Want to Drive Stepper Motor with PWM Duty Cycle

I’m considering using stepper motors for a balancing robot because the backlash is very low and torque is highest at low RPM. Specifically I’m interested in Stepper Motor #1474 (2.8A per coil, 180 oz-in torque).

Just not sure how to control them in Arduino under a fixed time step program loop. Typically I use standard DC motors driven by a VNH2SP30 Motor Driver and I simply change the PWM duty cycle to change RPM without upsetting the program loop timing. The PWM frequency is set before the loop. Changing duty cycle in the loop is really fast. This arrangement works really well.

Is there a way to just drive stepper motors with PWM duty cycle alone? I’m interested in just commanding stepper RPM like a motor. Appreciate your help on this.

[quote]Is there a way to just drive stepper motors with PWM duty cycle alone?[/quote]Not really, but the general approach is similar to how microstepping/chopper motor drivers like the A4988 work. I suggest to buy one (or the DRV8825 if appropriate) and learn how to work with it before continuing down the present avenue of thought.

Because of the current requirements, you need a motor driver in any case, so why reinvent the wheel?

Yes, I ordered the DRV8825 high current stepper driver. On the chip side, it seems simpler to operate than a VNH2SP30 motor driver. Not sure how to cool the DRV8825 driver.

On the Arduino side, the VNH2SP30 is easily driven by just changing the duty cycle of a hardware PWM signal running in the background. No need to change frequency in the loop. No addition of delays needed that would upset the program loop.

On the other hand, the DRV8825 wants a PWM wave with a fixed duty cycle (50%) and variable frequency to set the period and timing between steps. This wave can be easily produced by bit banging and adding delays, but this will upset my fixed time step associated with my program loop. In other words, long delays will be needed for slower step commands.

How does Pololu recommend using the DRV8825 driver in a loop? Thanks.

[quote]the DRV8825 wants a PWM wave with a fixed duty cycle (50%)[/quote]Not true, see the data sheet for the DRV8825 chip. The STEP input is activated by the rising edge of a pulse with a minimum duration of 1.9 us, so the duty cycle is essentially irrelevant.

The pulse train to control the step rate can be produced either directly by a hardware timer, by a timer driven interrupt routine running in the background, or by a simple foreground loop. Delays are not required or recommended in any case.

You will only need cooling if you set the winding current near the upper limit of about 2.2 amperes. You may not need the maximum torque the motor is capable of producing and a much lower winding current may be fine for your application.

That’s good news that Delays are not required. Any examples or tutorials on this? This seems like the perfect tutorial by Pololu for Pololu products.

Depending on the development system you are using, a millisecond interrupt-based clock can be used to avoid delays completely and to schedule several different tasks to execute concurrently.

The Arduino community has a number of tutorials on the topic, for example, a Blink Without Delay program is distributed with the IDE. Here is a more extensive example forum.arduino.cc/index.php?topic=223286.0

I’ve been experimenting with the DRV8825 driver on a bipolar stepper with a 12V power supply. I sent a repeating pulse to the STEP channel expecting the stepper to spin. Instead, it just hummed and clicked. It finally spun after adjusting the DRV8825 potentiometer. Then I changed the RPM, and it just hummed again. A new pot adjustment helped. This is a problem. I need to actively set the RPM without readjusting the pot on the fly. Can this be done with the DRV8825 driver or other driver?


The potentiometer on the DRV8825 is used to set the current limit for the board, and should not need to be adjusted to change step speeds. However, if the current limit is not set properly, it could cause the motor to not step.

You can find instructions for setting the current limit in the current limiting section of the DRV8825 product page. Since you are using a stepper motor with a larger rated current per phase (2.8A) than the DRV8825 can handle, you should set the current limit to 1.5A (the maximum for the DRV8825 without additional cooling).

What speed are you trying to step at?