How do Stepper Motors Work?
This mysterious type of motor is found in all kinds of CNC machines and 3D printers, plus tons of other applications that require precision.
Anyone who has ever installed these motors or designed a control system using them can tell you one thing: They aren't as simple as just hooking up power and ground to the wires.
In fact, they require complicated stepper motor driver boards which can sometimes be quite expensive.
As you can see from the image below, each of these stepper driver boards contains 12 separate connections to get a single motor to run properly. Surely it can't be simple right?
It's not simple.
But that shouldn't stop us from trying to understand the operation of such a common device.
The first question to ask is 'why would we use a complicated motor when simpler ones exist?'
It's a good question, but the answer is actually in the name - it operates in steps.
All other motors - Brushed DC, AC, 3-phase, etc - they simply run when electricity is applied, and then stop when the electricity does.
However, steppers are different in that when electricity is applied, a magnetic field will move the motor only a tiny fraction of a rotation (a 'step') and then lock tightly in place until a different voltage is very intentionally applied.
If we need a motor to move a specific amount then pause, then move another specific amount, we need to somehow be able to determine how far we are moving - this is exactly the purpose of these motors.
Since you can predict motion down to tiny fractions of rotations, steppers are the ideal solution for the coordinated motion of 3-axis CNC machines. Even normal paper printers are loaded with stepper motors, feeding paper and moving ink cartridges in increments of thousandths of inches at a time.
Although they are predictable, you still cannot absolutely guarantee that a stepper has moved properly. If the load is too heavy, the motor will not move even though the electricity has been applied.
Open-loop control is where we apply a voltage and hope everything is working properly. In most CNC machines, we can assume that it moved correctly, but we can't be sure...
If absolute precision is critical and we can't afford even a tiny error, we might choose to use a stepper motor WITH an encoder to read the position. In the picture above, the stepper in the upper-left side has the normal motor wires, but a second black cable harness from the built-in encoder on the back.
This addition of feedback to guarantee operation gives us a Closed-loop control system. Most steppers will not have an encoder, but it may be used for medical or precision testing machines.
How Do the Drivers Work?
From that first image, we can read the names of each of the wire terminals on that Gecko G203V motor driver.
+18 to 80 VDC
Current Set 1
Current Set 2
The first two names refer to Power Ground and +18 to 80 VDC. This is the power supply for the motors themselves. Big motors will require more current, and we cannot supply this current direction from the driver chips. They are simply the switches.
This voltage may come from a battery or DC supply - and remember, magnetic fields are generated from current, NOT voltage. So the exact voltage level is not important, in fact most stepper motors accept a range of voltage, not an exact level.
We simply need to provide sufficient current, but not an excessive amount - this is the job of those Current Set pins later on.
These two sets of terminals are for the two coils that internally create the bipolar stepper arrangement.
Here is a sample motor datasheet for a NEMA 23 motor. In the lower right corner, you can see the wire color and terminal names for all four wires coming out of the motor.
NOT ALL WIRE CODES ARE THE SAME. Make sure you can find information about your motor.
The idea of these two coils is that inside, the two coils are arranged around the outside of the shaft in many separate coils, not just one large coil for A and another for B.
In order to take a step, the current passed through each coil can be positive, negative or off. This allows each coil to attract or repel the shaft a tiny bit at a time, then held in position. The whole job of the control board is to alternate the polarity of each of the two coils to achieve a smooth motion.
Because of this two-coil polarity switching, these are called Bipolar stepper motors.
Some stepper have 6 wires which consist of exactly what we have here, plus a center tap in each coil. That way, half of each coil can be positive or negative, creating a more precise motion.
These signals all come from an external computer. It may be a tiny microcontroller or an entire PC.
The common would be a 'ground' wire, and each of the other signals is a small 3.3 or 5 volt, very low current signal. Disable must be OFF for the motor to run. The direction may be ON or OFF to make the motor advance Clockwise or Counterclockwise. Finally, each time the Step terminal is turned On and Off, the motor will advance one step in whichever direction is determined by the Dir pin.
This driver board states 'optoisolated' which means the control signals actually just each run a little LED inside, which runs a little phototransistor. The isolation means that if something bad happens to the motor and voltage is thrown back into the control board, it can't be sent back to your computer.
Losing a driver board would be bad. But losing a driver board AND your computer would be really bad...
Optoisolation is a seriously good thing to have inside any control system.
Current Set 1
Current Set 2
These pins establish the max current for each coil - this is really important!
Refer back to that motor datasheet, and it says '2.8 Amps per phase'. So we need to determine the correct resistor to use on this board. There is a small table of R values printed right on the driver case.
For 2.8 Amps, we can choose an appropriate value between the 18k and 36k resistor for 2 and 3 amps, respectively. The datasheets will usually have a table or formula to make this resistor selection pretty easy.
One final note about steppers is that you don't always need to turn the coils on and off completely. If you can turn them slightly on and slightly off, and vary the polarity, you can advance in steps that are in between the absolute on/off.
A typical number of steps per revolution is 200. This means each step is 1.8* around the circle. Microstepping can double that number of steps (or x4 or x8, or even more!).
This is NOT a function of the motor itself, but rather the stepper driver board.
Not every drive is capable of microstepping, but it can give better precision for some machines.
This is just a quick description of the theory of stepper motors. It's true, they are quite complicated, but they can be used to create machines with some pretty incredible capabilities!