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.

TMS320F280049: How to accelerate motor control algorythm without compiler Option

Part Number: TMS320F280049

Hello all,

We implement a Permanent Magnet motor sensorless FOC control  on a TMS320F280049.

We'd like and have a 25kHz sampling frequency.

So far we developped using inline functions the FOC (wihtout sensorless) and reached so far a 60% CPU load without any "- O" optimisation, which needs to be accelerated.

In the DMC libray provided in the "control suite" for this type of control, all functions are developped as MACROs based on a "SPRAAK2" document.

unfortunately, this document is not available easily onthe website. Is it possible to get it?

Can you indicate me if "inline" functions or Macros have a big difference in execution time?

I dont like to use too much "-O" options as i like to debug my code as easily as possible... Any advice for a -O option that speed up the code but leave it understandable?

Thanks a lot for any advice,

PA Nicoletti.

        

  • Inline functions are when we ask the compiler to compile the code as is without branches in the context in which it is called, where as a normal function call requires a call or long call branch. Be aware, just because we use the inline compiler intrinsic does not mean that the compiler has to actually inline the function. It can sometimes still perform a branch. A macro is a simple replacement of a keyword in your C code with a block of code defined elsewhere. There is no branch here. Inline functions can, in theory, save cycles as there is no context (i.e. register) pushing onto the stack, or manipulation of the program counter. The long call branch can sometimes be as low as 7 cycles though, so while non-zero, it can sometimes be a negligible amount of time

    In the CCS settings, under C2000 Compiler -> Optimization, you'll see the 'rule of thumb' given for optimizations. -O0 will fully optimize for size, meaning your inline functions are more than likely not actually inlined. -O5 is optimized for speed, meaning your code size will be larger, but all of the functions you've asked the compiler to inline should be actually inlined

    In reality, the best way to test this is to take some code and compile it, then look at the disassembly. You can use the CCS features to do cycle counting as you step through the code. The C2000 C compiler User's Guide can be found here: www.ti.com/.../spru514p.pdf

    It will help to technically verse you about the compiler, but you may find it easier to just play around with the settings yourself and check the code size/cycle count in the debug window

    Sean
  • Nicoletti,

    I didn't use TMS320F280049 before, so I will speak more general. Please consider followings.

    1) Benchmark your code: Use gpio's or count event in order to find which functions are consuming more time. Then try to find the root cause of this consumption.

    2) Your has single precision floating point. Make sure that you use single precision functions (ie: sinf, cosf)

    3) Your DSP has TMU (trigonometric math unit), which significantly decreases computation time of trigonometric operations (like sin/cos in FOC). Make sure that your code uses TMU. Don't ask me how, because I don't know :)

    4) By the way I usually use optimisation level 0 (register optimisation) and full symbolic debug. And I didn't have any debug problem so far. Morever, level 0 optimisation has significant improvement on execution time of your code.

    Regards,
    Hakan
  • Hi Nicoletti

    If there are no more questions, I will close the thread for now

    Sean