spacer DIY: A Better Bipolar Stepper Motor Driver

Designing things inside my computer is lots of fun but making physical things move under computer control is extra fun. I remember my first experiments with controlling stepper motors via my PC's parallel port some 20 years ago. At that time I never got beyond the basics but it was still a hoot. This project represents the culmination of several years of learning about stepper motors and the different ways in which they can be driven.

You can buy some very good stepper motor drivers but some people just like to build things. There are lot's of designs to be found floating around the web and in application notes from various semiconductor houses. But the designs of the most advanced stepper drivers are closely guarded. Their secrets are hidden within custom chips or code. I struggled through a lot of frustrating designs that could never drive any of my stepper motors at more than 3 or 4 revolutions per second. I wondered how the pros could extract so much better performance out of the same motors. Then I stumbled across a reference design developed by MicroChip. MicroChip, being a microcontroller company, is interested in selling their PIC chips and not at all hesitant to show how you can get superb performance out of a stepper motor.

Stepper Board
My bipolar stepper driver that utilizes a dsPIC33 and a L298N

After studying their design I rolled my own. I use a different driver stage, and my code is quite different but the core method is the same. Thank you Microchip. As proof of the pudding, here are links to some videos showing what the driver can do. In the videos, the driver board is connected to my next project, a motion control board. This board can drive a mix of stepper drivers and servo motors. It's being prepared in support of yet another project that I hope to unveil later.


Stepper Driver Board Specifications and Requirements

  • designed to drive bipolar motors
  • utilizes a dsPIC33 to monitor currents and perform PWM
  • utilizes an L298N for power delivery
  • PWM at 40KHz and can step at the same frequency
  • motor supply can be up to 40V
  • supplies up to 1.7A per motor phase
  • 1, 2, 4, 8 or 16 microsteps per full step
  • accepts TTL level direction and step signals
  • board requires a 5V regulated supply

Background on Stepper Motor

As I've said before, I'm not an electrical engineer. Rather than try to explain the background materials myself (and probably make a mess of it) I'll refer you to some very well written papers on the Internet.

Stepper Motor Basics - Google search at GeckoDrive

Stepper Motor Basics - Microchip

Stepper Motor Control with dsPIC® DSCs - Microchip: background and reference design

Achieving High Performance

Below a certain speed, stepper motors are fairly simple to drive. The driver's main concern, beyond energizing the motor coils in the correct sequence, is to limit the current so the motor doesn't overheat. This is done with either load resistors, or pulse width modulation (PWM).

At higher speeds it becomes more and more difficult to push current through the motor coils. Simple drivers pursue a dead-reckoning strategy. Apply as high a voltage as you can for as long as you can without burning out the motor. This approach doesn't actually work all that well because pulse timing and shaping becomes much more critical at higher speeds.

The Microchip reference design allows the motor currents to be actively monitored by the driving microcontroller. This allows the driving voltages to be dynamically adjusted to best attain the target currents. A proportional-integral (PI) controller scheme is used. The PI controller is a piece of software that takes as inputs the target current, the actual current, and the previous current and calculates the best voltage to apply in order to reach the target current.

At low speeds a stepper motor comes to rest between steps. When a step is commanded, the rotor will swing to the next stable location and with a bit of wobbling will come to a rest. As the step speed increases, the time between steps becomes too short for the rotor to come to a rest. Instead, the rotor will be commanded mid-wobble to move to the next location. In this situation, the motor is very susceptible to what are called resonance effects. The motor can behave very erratically and even stall. The PI controller minimizes this effect by eliminating much of the wobbling. It does so by easing off the driving voltage as the rotor approaches the target position.

At higher stepping speeds, the rotor no longer halts between steps. It proceeds relatively smoothly, just reaching it's target position before getting another kick to go to the next. This behaviour is like a synchronous motor found in hard drives. It's very difficult to drive such a motor if you have no feedback as to what it's doing.

If you've ever pushed someone on a swing, you know that a small, well timed push can cause that person to swing higher and higher. Miss a push or two by even a small amount and the 'power transfer' is significantly less. This is the situation in stepper motors at high speeds. If you don't match the pushes or steps to the actual state of the motor it will run poorly. Again, the PI controller monitors the actual current in the motor and dynamically adjusts the driving voltage in response. The result is a smooth running motor at speeds far exceeding those achievable by dead reckoning.

Next Section: Hall of Disillusion