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.

TMS570 motor control cpu utilization



Hi,

I'm looking at the the LS12 motor control kit examples and the FOC example (TMS570_sensored_speed_smo) uses 40% plus of the cpu.

Has anyone tried to optimize the calculations for FOC?  Is it possible to get the cpu usage under 10% for the control of one motor?

I need to spin two motors (sensorless using FOC) and still have 50% plus time left over (plus head room) for higher level, application code.

Thanks,

Mike

PS - I should mention that I want to use C or C++, not assembly.

  • Hi Mike,

    I will forward your question to our motor control expert. He will response soon. Thanks

    Regards,

    QJ

  • Go to http://processors.wiki.ti.com/index.php/TMS570LS12x_CNCD

    Search for Hercules_Motorware_Dec2012.zip

    It realize the same functionality and code structure of the one in TI website. However, I optimize the code in C level and reduced the CPU usage to 40% of before. Here is the benchmark 4300.Motor Control Benchmark.pdf A couple points:

    1. The benchmark is done with CPU Freqency 80MHz, so, the percentage of CPU usage @ 180MHz or higher is only about half of the one listed in the table.

    2. I thought I changed the software frequency to 160MHz and Flash waitstate to 2. However, there are so many project in the zip file, please double check it in system.c. And please check the Flash waitstate against the datasheet .

    3. Optimization in CCS settings is very very important for the fixed point project, it shrink the CPU usage to 1/3. For the floating point project, optimizaiton in CCS settings  shrink the CPU usage to 2/3 to 1/2.

    Regards,

    Haixiao

  • Use the FOC I attached, you can get to about 15% CPU untilizaiton of one motor when you running at 180MHz or higher. Please note that:

    1. In this algrithm, we calculate the motor angle twice - one from the encoder, another one from sensorless. If you use only encoder feedback, it can go down to 10%.

    2. The PWM_Wrtite code can be optimize further since all three channels repeat the same calculation.

    3. If you use 10k pwm, which I think is good enough for most motors, you can drop the CPU untilization to another half.

    Regards,

    Haixiao

  • Hi Haixiao,

    Thanks the new version really helps a lot.  Can I ask what you did to get the speed improvements?

    The only thing I found so far was the removing the redundant calculation of sin/cos theta for the inverse Park transform.

    Thanks,

    Mike

  • Mike,

    Most of the difference can be tracked in the benchmark result with green fonts.

    1. PID functions. In the old version, "min and max" are called the generic cmsis functions. In the new version, I replaced with a simple if (x>y) x=y; function. The new one only takes about 2 asm instructions after compiling.

    2. SPEED_FR, SPEED_EST, similar saturation as 1.

    3. VOLT_CALC, SVGEN - I rewrite the C function - generating the same result, but take less cycles.

    4. QEP. Replace the function fmod with shift, sub, and multiply. fmod takes more calcuation then a div

    5. SMOPOS rewrite the atan2 function in asm.

    Regards,

    Haixiao