A Simple Approach to Driving The Ubiquitous Stepper Motor

Stepper motors are a favorite of designers, engineers, and makers alike, and so can be found almost everywhere there is an electronically controlled system. They’re so popular and useful, in fact, that it’s often easy to forget how they work and to ensure that they are being driven correctly.

The motors themselves are brushless, synchronous DC motors where each 360˚ rotation is divided into a number of equal, discrete steps. The angular rotation of step is determined by the number of “toothed” electromagnets arranged around a central, gear-shaped piece of iron (Figure 1). It is the energization of the magnets, and the ensuing magnetic attraction of the gear-shaped shaft’s teeth, that pulls the shaft around its axis of rotation by.

Figure 1: The permanent-magnet rotor is rotated according to the sequencing of the pulses applied to energize the electromagnetic “teeth”. (Image source: NXP)

It’s important to note that when the shaft’s teeth are aligned with the first electromagnet, they are slightly offset from the next electromagnet. This makes sure that when the next electromagnet is energized, the teeth are pulled in the direction of the next electromagnet.

The number of steps required to complete a single 360˚ revolution defines its resolution, or how finely the motor can be controlled. Typical motors have 200 steps per revolution, but it’s not unusual to see 1600 steps per revolution for very fine control of movement, such as the arm of a hard disk drive.

Control is accomplished using a sequence of square digital pulses, typically from a microcontroller, which are used to intelligently drive the coils. The word “intelligently” is deliberate here: as how the coils are arranged, constructed and driven determines key parameters such as efficiency, accuracy, precision, repeatability, and torque. Each pulse is a discrete step and so the number of pulses and their rate determine the rotation distance and speed.

Depending on how the coils are connected and driven, steppers can be either unipolar or bipolar. In unipolar designs, the current flow is always in the same direction to achieve rotation. In bipolar, an alternating reversal of current flow in the windings is used to achieve rotation.

Some of the interesting, useful and fun characteristics of stepper motors include that fact that once energized, it stays rock steady with full torque until the next pulse; the precision with which they can be controlled, particularly if gearing is used; the fact that they can be reversed quickly by changing pulse polarity, manually or electronically; their fast-stop capability; robustness and reliability; and low cost.

Adding to the cost and simplicity factor is the fact that they are open loop. This means that there is no need for extra sensors or feedback mechanisms to determine the shaft position.

The stepper motor’s characteristics have made it a favorite of designers of systems from toys and gaming to automotive and spacecraft (Figure 2).

Figure 2: Stepper motors come in various forms for applications ranging from toys to medical, industrial control, and spacecraft. (Image source: NXP)

In medical applications, they are used to control insulin and blood oxygenation pumps, storage retrieval systems, and CT scanners. In automobiles, they are used for everything from windshield wipers to lumbar support devices to headlight adjustment motors. Robots, both industrial and toys, are also popular applications, also due to their precise position control capabilities.

Designers beware: simplicity belies drive complexity

Of course, with motors in general being a combination of magnetism, electricity, analog, and digital, it is a science that is replete with variations and nuances about which many books have been written. Stepper motors are a specific type of motor, but are no less varied in design and drive complexity and options.

For example, they come in three main varieties: permanent magnet, hybrid synchronous, and variable reluctance. The choice depends on parameter requirements with respect to speed and torque.

The drive circuits are also a large area of exploration. The drive circuit design can influence torque curves to switch stator poles more quickly, so there are drive-circuit variations that include L/R (inductance/resistance), chopper drive, wave drive, full-step drive, microstepping, and half-stepping, but to mention a few.

The goal in is to achieve the optimum sequencing of pulses while also ensuring that the output drivers of a stepper motor controller can supply sufficient current. Motor coils are inductive loads, so high instantaneous current is required.

For sure, application-specific stepper motor drivers are available, but these can be costly. Instead, it may be better to opt for an inexpensive general-purpose I/O (GPIO) expander, such as NXP’s PCA9537.

Driving a unipolar stepper motor with the NXP PCA9537

The NXP PCA9537 is a 10-pin CMOS totem pole GPIO with an SMBus and I2C two-wire bus so it can interface to most microcontrollers (Figure 3).

Figure 3: The NXP PCA9537 is a totem pole GPIO that takes the I2C byte sequences from the host controller and provides the requisite waveforms to the gate inputs G1 through G4. (Image source: NXP)

In the diagram, the motor is a 12-V unipolar stepper motor with a current rating of 1.25 A. For users that want to modify the diagram and tweak it to their own application, there is a fully interactive schematic of the unipolar driver available on

The PCA9537 has a 4-bit configuration register, 4-bit input port register, and a 4-bit output port register, and a 4-bit polarity inversion register for “active high” or “active low” operation. The GPIO has a fixed I2C-bus slave address of 92H and it takes the I2C byte sequences from the host controller and provides the requisite waveforms to the gate inputs G1 through G4.

The diagram also shows the NXP PCA9665, an IC that serves as an interface between most standard parallel-bus microcontrollers/microprocessors and the serial I2C-bus allowing the parallel bus system to communicate bidirectional with the I2C-bus. The type of waveform will be one corresponding to wave, two-phase or half-step drive, as chosen by the user. The duration of the pulses is controlled by time delay implemented in the host controller firmware. It is shown as a reference for the various waveforms. The maximum I2C-bus speed supported by PCA9537 is 400 kHz.

To drive the stepper motor at approximately 18 RPM, use the following byte sequence, where ‘S’ stands for I2C-bus START condition, and ‘P’ stands for STOP condition. Also, DLY1 and DLY2 are time delays implemented by the microcontroller firmware. Numbers are represented in hexadecimal notation:

S, 0x92, 0x03, 0x00, P // Set all 4 IO pins of PCA9537 as OUTPUT pins;
// IO Configuration Register = 0x00
Set DLY1 = 300 ms // Time delay between steps; 18 RPM for a 7.5˚ motor

//Start of waveform loop
S, 0x92, 0x01, 0x08, P // Start the half-step sequence waveform
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x0C, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x04, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x06, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x02, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x03, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x01, P // outputs for the next step
Execute time delay between steps = DLY1
S, 0x92, 0x01, 0x09, P // outputs for the next step
Execute time delay between steps = DLY1
// Loop through waveform sequence to keep running motor
// OR execute next two steps if desired
Execute time delay = DLY2 // Hold in current position for time = DLY2
S, 0x92, 0x01, 0x00, P // Turn off motor

(Byte sequence source: NXP)

Of course, some users may want to drive multiple motors. For this, many single-chip options are also available. In the meantime, it’s good to practice on the PCA9537 and the unipolar, single-motor, interactive schematic shown here.