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.

CCS/UCD3138: What is ABS means in TI UCD3138 PFC Code?

Part Number: UCD3138

Tool/software: Code Composer Studio

Hello ;

In UCD3138 PFC Code witch i Download form Power Factor Correction (PFC) Application Development kit . 

I frond a function, abs. I use CCS6.0 couldn't  find the  function define.

Could  someone answer me , Does it work?  How it work? Why i can't find the define?

Hear are some of the Code:

if(abs(iv.vin_squared_average -(iv.vin_squared_slow_average >> VRECT_SQUARED_SLOW_AVERAGE_SHIFT)) >(iv.vin_squared_slow_average >> (VRECT_SQUARED_SLOW_AVERAGE_SHIFT + 4)))

  • Hello Dudu
    "abs" is a C library function, it returns the absolute value of an integer.

    See fresh2refresh.com/.../ for more details.

    Kind Regards
    Cormac
  • abs does an absolute value of an int.  It's part of the C language definition, so it's in a library.  It's part of the stdlib, so you may want to put this at the front of whatever file you are calling it in:

    #include <stdlib.h>

    That should fix it. 

  • why In TI PFC code  didn't include <stdlib.h>  but the ABS function still work. 

  • Hello Dudu

    stdlib.h is included by default via the project properties.

    Right click on the project in the explorer window in CCS, then left click "Properties"

    On the pop up menu, go to CCS Build -> ARM Compiler -> Include Options

    See that "${CG_TOOL_ROOT}/include" is included.

    If you go to back to Properties, then go to Resource -> Linked Resources, you will see that $CG_TOOL_ROOT is set to your tool installation directory

    For me, this is C:\ti\ccsv8\tools\compiler\ti-cgt-arm_5.2.5

    If I go to this directory via windows explorer, and then descend into the "include" directory, I find stdlib.h. 

    So all of the files in this directory are included for this project, via this mechanism.

    Best Regards

    Cormac

  • Thank you for  resolving my confusion.