Issues with going above a certain speed

STM MCWB can do field weakening, question is what Id current was commanded.
But what’s the KV of this motor ?

If loop rate is the problem, they are still areas of improvement for Simplefoc:

  • sin/cos runs twice now
  • 6PWM implementation is slow (being discussed here)
1 Like

@mizzi_labs is getting 24kHz loop speed with 20kHz PWM so this is enough speed, I think.

Assuming you set the PWM back to 24 or 25kHz and the performance remains roughly the same, 24kHz is enough to have 15 iterations for each electrical rotation at 94500eRPM - not great but should be enough to get more than the 250rad/s (=50100eRPM) you’re currently getting.

Is the STM studio speed based on the AS5047 sensor also, or is that sensorless or using another sensor?

I just managed to improve my motor driver speed significantly, from 125000 ERPM to 160000 ERPM. The way I improved the speed was by changing the current sense sampling point location. I probably miscalculated the previous sampling point location, and it seems like some switching noise got into the current readings. This must have messed up the FOC loop when the full DC voltage was requested, and limited the max speed.

Maybe you could try tuning the sampling point location to see if it makes a difference. It will probably help, but I think you are mainly still limited by the loopFOC speed.

Another way to speed up the loop would be to use the CCM SRAM of the STM32. It should speed up the code execution by quite a bit. I’m not sure if it’s easy to set up in Arduino, but for STM32CubeIDE you can find a guide online that tells you how to mess with the linker and add attributes to the function to put it into the CCM SRAM.

STM MCWB can also sample only the 2 best phase currents and avoids sampling when mosfets are switching.

1 Like

@Antun_Skuric, I haven’t tried torque control yet. Will give it a shot and see later today.

Yes @runger , in ABZ mode (however, not using the Z index)

I checked my work-bench and Motor-Pilot setup and it doesn’t seem to have Flux Weakening or MTPA enabled.
This is interesting. Will poke around the ST Motor control a little more today. It’s somehow giving twice the speed we are getting from SimpleFOC, using the same hardware.

That’s awesome, 125K to 150K is simply great. How to go about tuning the sampling point?

I wouldn’t look at sampling point or running from the interrupt now, as this is not supported by SimpleFOC anyway. And this will not impact that much.
There must be something else.

1 Like

This is wrong by the way.
You should use CC4 to trigger the ADC, and run loopfoc in the ADC interrupt.
Unless you are ok running foc on previous phase currents.

1 Like

I use custom firmware, and to tune the sampling point I use channel 6 of the timer to trigger the ADC conversions. Changing when the timer compare happens lets me tune the sampling point. You can also sync 2 timers and use the second timer to trigger the ADC for the same effect.

To do this in SimpleFOC probably requires modifying the source code, as I think currently it is hardcoded to trigger the ADC reading in the middle of the low side MOSFET on time.

I believe that the synchronization between the PWM and the FOC loop is the most important, because with an unsynchronized loop there will be a lot of timing jitter which likely messes up your FOC, similar to how the switching noise in the current sense messed up my FOC. So I think you should give this method a try first.

You could also try increasing the switching frequency to 50KHz, but from my experience with the B-G431B-ESC1 the MOSFET switching speeds are quite slow so it might not give you any net gain.

Also I’ve only been running my motor at 21V due to that being the maximum voltage of my adjustable power supply. I tried powering the motor driver with a high power boost converter set to 24V and was able to get the motor spinning even faster at 180000 ERPM.

I use the TIM1 TRGO2 which is linked to CC6 and it works just fine, I don’t get stale phase currents or lag when dynamically choosing which two phases to measure the current in each cycle. I use CC4 to trigger the FOC interrupt. But I guess it also works the other way around. You can also sync up another timer to trigger the ADC or the FOC interrupt if you want, it should all work the same.

1 Like

Changing the sampling point means you shift when ADC is starting to sample. FOC should run when ADC has finished the sampling.

I’ve put together a diagram showing the approximate timings in my motor driver firmware. The time when FOC finishes depends on whether the torque, velocity or position control is used, the slowest is the position mode which finishes in roughly 7us after start of the PWM cycle. Also the ADC reads the sin/cos encoder just after it finishes with the phase currents.

1 Like

Looks complicated. Are you starting ADC withing the interrupt ?

TIM-CC4 triggers injected ADC (ADC_EXTERNALTRIGINJECCONV_T1_CC4) → ADC sampling → ADC JEOC Interrupt → FOC

1 Like

Thanks for the suggestion, using the ADC JEOC interrupt is probably easier than using CC4 to trigger the FOC interrupt.
The ADC injected conversions are currently started by hardware on the falling edge of TIM1 TRGO2 (ADC_EXTERNALTRIGINJEC_T1_TRGO2) which is linked to TIM1 CC6.

1 Like

With this setup, it’s a single chain of events.

Hey @mizzi_labs,
I was thinking about this a bit more and I was wondering if you have tried to reduce the Low pass filter time constant for the d and q current control loops?
By default their time constants are set to 5ms which might be too much for your application and it might be responsible for some lag.

motor.LPF_current_q.Tf = 0.001; // sec (to set it to 1ms)
motor.LPF_current_d.Tf = 0.001; // sec (to set it to 1ms)