This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Faulty output from sin/cos function, using C6678

Other Parts Discussed in Thread: MATHLIB

When we use the functions sin(x) or cos(x) we sometimes get faulty results. It usually works when we only use one sin(x) and one cos(x) function, but if we also add e.g. a tan(x) and a acos(x) function to the program, the sin(x) and cos(x) returns faulty values. With input 0.5235988, the sin(x) function returns 0.5235988 and the cos(x) function returns 1.0, which obviously is faulty.

We are using c6000_7.4.1 version of CCS to produce the executable code.

The relevant code simply looks like this:

#include "C:\TI\ccsv5\tools\compiler\c6000_7.4.1\include\math.h"

float ARG_IN, SIN_OUT, COS_OUT, TAN_OUT, ACOS_OUT; 

TAN_OUT = tan( ARG_IN );

ACOS_OUT = acos( ARG_IN );

SIN_OUT = sin( ARG_IN );

COS_OUT = cos( ARG_IN );

These are the libraries we link in. I don't know which of them contains the math functions:

INCLUDE_LIB_PATHS = \
 -i"C:/TI/ccsv5/tools/compiler/c6000_7.4.1/lib" \
 -i"C:/TI/ccsv5/tools/compiler/c6000_7.4.1/include" \
 -i"C:/TI/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug" \
 -i"C:/TI/pdk_C6678_1_1_2_5/packages/ti/csl/lib"

 -l"ti.platform.evm6678l.ae66" \
 -l"ti.csl.ae66" \
 -l"ti.csl.intc.ae66" \
 -l"libc.a" \

Compiler switches are:

GENERAL_OPTIONS = -mv6600 --symdebug:none -O3 -ms0 -mf5 --asm_listing --src_interlist --optimizer_interlist --display_error_number --diag_suppress=552 --diag_warning=225 --abi=eabi

Compilation command:

 $(COMPILER) $(GENERAL_OPTIONS) -z -m"DSP3.map" --warn_sections $(INCLUDE_LIB_PATHS) --reread_libs --rom_model -o"DSP3.out" $(ORDERED_OBJS)

Has anyone experienced similar problems?

  • Hi Gunnar,

    this could be because of optimization level -O3. Either try the volatile keyword:

    volatile float ARG_IN, SIN_OUT, COS_OUT, TAN_OUT, ACOS_OUT;

    or try lowering optimization level.

    Please see also the Compiler User's Guide on this topic. Chapter 3.1 Invoking Optimization

    Kind regards,

    one and zero

  • We tried using optimization level -O0 and declared both inputs and outputs for the trigonometric functions as volatile, but the errors still remain. The only difference was that the processor load increased from 42% to 77% with 250 us cycle time.

    We will try linking the mathlib library and check if that works better, but all other ideas are welcome.

  • Hi Gunnar,

    I have tried your code with a loop around it and it works fine for me. See results copied from console:

    ARG IN: 0.000000, tan: 0.000000 acos: 1.570796 sin: 0.000000 cos: 1.000000
    ARG IN: 0.050000, tan: 0.050042 acos: 1.520775 sin: 0.049979 cos: 0.998750
    ARG IN: 0.100000, tan: 0.100335 acos: 1.470629 sin: 0.099833 cos: 0.995004
    ARG IN: 0.150000, tan: 0.151135 acos: 1.420228 sin: 0.149438 cos: 0.988771
    ARG IN: 0.200000, tan: 0.202710 acos: 1.369438 sin: 0.198669 cos: 0.980067
    ARG IN: 0.250000, tan: 0.255342 acos: 1.318116 sin: 0.247404 cos: 0.968912
    ARG IN: 0.300000, tan: 0.309336 acos: 1.266104 sin: 0.295520 cos: 0.955337
    ARG IN: 0.350000, tan: 0.365029 acos: 1.213225 sin: 0.342898 cos: 0.939373
    ARG IN: 0.400000, tan: 0.422793 acos: 1.159279 sin: 0.389418 cos: 0.921061
    ARG IN: 0.450000, tan: 0.483055 acos: 1.104031 sin: 0.434966 cos: 0.900447
    ARG IN: 0.500000, tan: 0.546303 acos: 1.047197 sin: 0.479426 cos: 0.877583
    ARG IN: 0.550000, tan: 0.613105 acos: 0.988432 sin: 0.522687 cos: 0.852524
    ARG IN: 0.600000, tan: 0.684137 acos: 0.927295 sin: 0.564643 cos: 0.825336
    ARG IN: 0.650000, tan: 0.760205 acos: 0.863212 sin: 0.605186 cos: 0.796084
    ARG IN: 0.700000, tan: 0.842289 acos: 0.795399 sin: 0.644218 cos: 0.764842
    ARG IN: 0.750000, tan: 0.931597 acos: 0.722734 sin: 0.681639 cos: 0.731689
    ARG IN: 0.800000, tan: 1.029639 acos: 0.643501 sin: 0.717356 cos: 0.696707
    ARG IN: 0.850000, tan: 1.138333 acos: 0.554811 sin: 0.751280 cos: 0.659983
    ARG IN: 0.900000, tan: 1.260159 acos: 0.451026 sin: 0.783327 cos: 0.621610
    ARG IN: 0.950000, tan: 1.398383 acos: 0.317560 sin: 0.813416 cos: 0.581683
    ARG IN: 1.000000, tan: 1.557408 acos: 0.000000 sin: 0.841471 cos: 0.540302

    I have a couple of comments:

    1. I have used compiler version 7.4.4 (default with CCS5.5), is there a reason why you use 7.4.1? BTW, the latest version is 7.4.11

    2. Using MATHLIB is a good idea anyway since it'll give better performance.

    Kind regards,

    one and zero

  • Now we have tested using MATHLIB and it looks fine, so we will probably go with that solution. Why we get faulty results when we use the builtin runtime library still remains a mystery, but unfortunately we don't have time to dig deeper into that issue right now.

    Thanks for your help

    Gunnar