Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

DRV8834 Micropython and PWM

Hello Forum,

This might be a newbie question… We are building and application for an autonomous vehicle using the DRV8834 stepper motor driver. We are trying to use Micropython PWM on an ESP32 MCU and are having some trouble attempting to get consistent performance from the motors.

According to this equation…

RPM / ( (a/360) * 60) = Hz

I should be able to set a Micropython PWM frequency of 1000Hz with a duty of 512 on the DRV8834 STEP pin and achieve 300 RPM. However, we’re seeing significantly lower RPM’s at this frequency and the motors stutter and vibrate quite a lot. If we use a 2000Hz frequency the motors work as expected. We are supplying the driver with 5v

Can you provide any guidance on how to use Micropython PWM with the DRV8834?

Hello.

I am not sure where you are getting that equation from, but if you are not adjusting the microstepping mode on the DRV8834 from its default (quarter-stepping) and using a motor with 200 steps/revolution (like all of our stepper motors), then I would expect sending a 1000Hz signal to result in a speed of about 75 rpm:

(1000Hz × 60s/min) / (200 steps/rev × 4 quarter-steps/step) = 75rpm

Is that the speed you are seeing? If not can you post some more information about your setup (such as specs for your motor and power supply) along with pictures of your setup?

- Patrick

Hi Patrick,

Thanks for the info. I didn’t realize quarter-stepping is the default on the DRV8834. So if I set M0 and M1 low I should get a full step with each Hz, correct? So that would be (1000 * 60)/(200 * 4) = 300 RPM?

I’m setting M0 high, so I think that’s half-stepping, I’m getting pretty good results. However, when I set M1 and M0 low I’m still not getting the expected RPM and the motors stutter a lot. I’m trying to get the optimal settings for quiet performance and decent torque from about 150-500 RPM.

Here’s some info on my setup:
Motor: SL42STH34-1334A Bipolar Stepper Motor
Power: D24V22F5 5V, 2.5A Step-Down Voltage Regulator
MCU: ESP32-WROOM-32D

Based on your schematic, it looks like you are probably not using our DRV8834 carrier, but perhaps your own PCB. Is that correct?

It looks like you left the “×4” in the equation by accident, but 300rpm is the right result of with that frequency if you are in full-stepping mode.

(1000Hz × 60s/min) / (200 steps/rev ) = 300rpm

Setting M0 high and leaving M1 disconnected (M1 is pulled low by default) would put the driver in half-stepping mode according to the “Stepping Format” table in the “Indexer mode” section of the DRV8834 datasheet.

Finding a good balance for operating your stepper motor quietly while still getting sufficient power from it can be a tricky endeavor. I would not expect operating in full-step mode to provide optimal performance for the criteria you mentioned. Instead, I suspect you will be better off if you use as high a microstepping mode as possible and set up your code so that your motor accelerates and decelerates as gradually as possible.

By the way, unless you have a specific reason to power your stepper motor from a regulator, you might get better results if you can power your motor directly from a higher voltage supply (although you may need to get a different driver that can handle the higher voltage).

- Patrick

Hi Patrick,

Thank you for the information. It is very helpful. I only have one more question on my stepper motors. The data sheet says rated voltage is 2.8v. This seems low to me as I’m already giving them 5v on my breadboard.

As long as you are using a stepper motor driver with active current limiting (like any of our stepper motor drivers), then it is fine to power your driver from a source greater than the rated voltage voltage of your specific motor. You can find more information about that under the FAQs tab of our stepper motor driver product pages.

However, based on your schematic, I am concerned that your circuit might not allow you to set an appropriate current limit for your motors. If that is the case, using a supply voltage above their rated could damage your motors since they will draw more than their rated current.

- Patrick