Low-speed stepper smoothness and load response with FOC current control

I’m using SimpleFOC to control a NEMA17 stepper with StepperDriver4PWM, an SPI encoder and inline current sensing. It works quite well overall, but I’m struggling with smoothness and response to load at low speeds.

In closed-loop velocity mode, around 1–2 rad/s and below, rotation isn’t particularly smooth. When I apply mechanical resistance, it also takes longer than I’d like to recover the requested speed. I’m not sure whether this comes from detent torque, velocity measurement noise or my tuning. Above roughly 5 rad/s, the motion is noticeably smoother.

My hardware is:

  • STM32 Nucleo-F446RE

  • LDO-42STH48-2004AC NEMA17 stepper, 1.8°, 2A/phase, 1.6 ohms and 3mH per phase

  • Pololu Dual MC33926 carrier, using both H-bridges for one stepper

  • AS5047P SPI encoder with a magnet on the motor shaft

  • Two INA240A2 current-sensing modules, one per phase, with 0.01-ohm shunts and 1:2 voltage dividers on their outputs

I’m using foc_current torque control underneath the velocity loop, with 50 pole pairs configured.

My velocity PI settings are P=0.4, I=1, D=0, with a 20ms velocity filter. Both current loops use P=10, I=600, D=0 and 1ms filters. Motion downsampling is set to 4. The current-request limit is normally 1.5A, and the voltage ceiling is adjustable up to 11V.

Has anyone had good results running a similar stepper setup smoothly at these speeds while maintaining a reasonably quick response to load? Would you start with the velocity PI/filter settings, current-loop tuning, or checking ADC sampling relative to PWM?

I’d like to keep closed-loop control across the speed range without having to stop and reinitialize when switching between slow and fast operation. Happy to share the sketch or collect specific measurements.

Thanks!

2 Answers

2

Hi @S.J,

From my experience I’d say that one of the most important things for smoothness is a fast loop time, the higher the better. If you can have a fast loop it can compensate for a lot of nonlinear effects that happen due to backlash, cogging, sensor noise, …

Here are some ideas:

  • From my experience you need much more I in your velocity PID. I’d expect it to be closer to 100.
  • Use low-side current sensing class. In your case it will not actually matter which one you use but it will give you a faster loop, 5-10x faster I’d expect.
  • Use more higher clock speed for the spi sensor, play with the clock speeds, the higher the better. I think the inital is 1M, but try more, up to 10M. It can also reduce the loop speed a lot.
  • Try downsampling the velocity calculation to 1-5ms (sensor.min_elapsed_time)
  • autotune the current PIDs with the library functions,try different bandwith values to give you the best performance

EDIT: I just looked into the slew rate of the driver as suggested by @dekutree64 .
The slew rate is pretty bad
image

make sure to enable the fast slew rate. But even with the fast slew rate smooth rotation at low speeds will be a challenge.
Basically, at 1us raise time at 25khz pwm (40us per cycle) and with the power supply of 11V you have the dead-zone of

11\cdot1/40 = 0.28V

This can be a lot for low velocities and small perturbations.
At 0.28V of dead zone (it is not exactly a dead zone, but you can see it that way a bit), you will have the current dead-zone of

11\cdot1/40/1.6 = 0.28V/1.6 = 0.17 A

Which is a lot for small motors.
So your best bet with the current hardware is to increase the bandwidth as much as you can and see if it will be better.

If not you’ll have to change the driver I’m afraid. :slight_smile:

Great thanks for response! I'll definitely go through every step u listed. My setup is just a prototype for now so I'm quite happy to change the hardware tbh. is there any hardware u would recommend for: low side current sensing and fast loop - preferably some IC's if possible.

–

From a quick look at the datasheet, make sure the SLEW pin is set to fast (I think high? The wording is not clear). But even then the rise/fall time is pretty slow so there will be some coggy motion. And max PWM frequency is 20KHz, so make sure you’re not giving it 25 which is probably the default.