Embedded World 2023 - STM32 CORDIC CO-PROCESSOR

ok I think I found something even better.
To generate those bumps, simpleFOC implements Space Vector pwm

But you can also just apply a midpoint clamp to the actual simpleFOC sinusoidal implementation after the Clarke transform.
Replacing this here:

center = driver->voltage_limit/2;
// Clarke transform
Ua = Ualpha + center;
Ub = -0.5f * Ualpha + _SQRT3_2 * Ubeta + center;
Uc = -0.5f * Ualpha - _SQRT3_2 * Ubeta + center;

By this:

center = driver->voltage_limit/2;
// Clarke transform
Ua = Ualpha;
Ub = -0.5f * Ualpha + _SQRT3_2 * Ubeta;
Uc = -0.5f * Ualpha - _SQRT3_2 * Ubeta;
if (svpwm){
float Umin = min(Ua, min(Ub, Uc));
float Umax = max(Ua, max(Ub, Uc));
center -= (Umax+Umin) / 2;
}
Ua += center;
Ub += center;
Uc += center;

Tada, it should be nearly as fast as sinePWM, no atan2 anymore.

3 Likes

I love it!

Your rate of innovation greatly exceeds my ability to test everything

We should run this by @Antun_Skuric

If it really produces the svm waveform that would simplify and speed up the code

1 Like

Here you guys already have a bottom clamp

This formula could help simplify even more and you get top-clamp for almost free, but I am not sure if top-clamp is really useful:

Very interesting!

I’ve tested it in matlab quickly and it seems to work well.
I’ll make sure to test it properly in the simplefoc as well. This could be a great addition

2 Likes

I was checking Qfplib again, I read here it can be made to replace the standard math functions.

According to this document (page 23-25) gfplib is already used on the Raspberry pico because of the poor floating math support on cortex M0+.

As Simplefoc supports the RP2040, I imagine there is no impact.

1 Like

Just an update. I am sharing this here because it’s related to the math functions but please move my previous post and this one if needed.

All the single precision calculation would probably benefit from this library. For things like precise angle calculation that use double it would be safer not to use it.
I am wondering how the RP2040 handles the double precision though.

I was looking for options to replace the gcc math functions like addition/substration/multiplicatio/division by the Qfplib ones without changing anything in SimpleFOC, but I wasn’t successful yet. But there are posts hinting at doing linker magic. Stay tuned.

Mary x mass