Stepper Motor Interface

Driving coils sequence.

Darshan N
Updated: 19 March 2026
10 min read

A stepper motor is a brushless DC motor that divides a full rotation into a fixed number of equal steps, making it ideal for precision position control without requiring position feedback sensors. When interfaced with a microprocessor via an output port, the CPU drives the motor coils in a programmed sequence, and each step advances the rotor by a precise angular increment. This topic is standard in peripheral interfacing courses and appears in GATE questions on I/O control.

8255 PPIPort A OutputPA0-PA3 = Coil A B C DControl RegMode 0, Port A out = 80hPA0-PA3ULN2803Darlington Driver(Current amplifier)Coil driveRotorABCDStep angle = 360 / (number of rotor poles x phases)Stator coils A, B, C, D
Figure 1: Stepper motor interfacing using 8255 Port A and ULN2803 Darlington driver to energize stator coils A, B, C, D

Core Concept Explanation

A stepper motor has a toothed rotor and multiple stator coils (also called phases or windings). When a coil is energized with current, it creates a magnetic field that attracts the nearest rotor tooth, pulling the rotor into alignment. By energizing coils in a specific rotating sequence, the magnetic field rotates around the stator, and the rotor follows it one step at a time.

In microprocessor interfacing, the CPU does not directly energize motor coils because output port pins (8255 Port A) can supply only a few milliamps, far less than the hundreds of milliamps required by motor coils. A Darlington transistor array such as the ULN2803 is placed between the 8255 output and the motor coils. Each Darlington pair has a current gain of around 1000, allowing the logic-level output of Port A to switch coil currents of up to 500 mA per channel.

The software must output the coil energization pattern to Port A in the correct sequence and with controlled timing between steps. The step rate (steps per second) determines motor speed, and the direction of rotation depends on whether the sequence progresses forward or backward.

Driving Modes

There are three standard driving modes for a 4-phase stepper motor, each representing a different coil energization strategy with trade-offs in torque, resolution, and power consumption.

  • Wave Drive (Single-Phase Excitation): Only one coil is energized at a time. Sequence: A, B, C, D. Port A codes: 01h, 02h, 04h, 08h. Produces minimum torque and lowest power consumption. Step angle is the full step angle of the motor.
  • Full Step Drive (Two-Phase Excitation): Two adjacent coils are energized simultaneously. Sequence: AB, BC, CD, DA. Port A codes: 03h, 06h, 0Ch, 09h. Produces higher torque than wave drive. Still one full step per sequence transition.
  • Half Step Drive (One-Phase then Two-Phase alternating): Alternates between single coil and two-coil energization. Sequence: A, AB, B, BC, C, CD, D, DA. Port A codes: 01h, 03h, 02h, 06h, 04h, 0Ch, 08h, 09h. This doubles the number of steps per revolution, giving half-step resolution and smoother motion at the cost of varying torque per step.

Mathematical Expression

The step angle of a stepper motor determines the angular displacement per step. For a motor with N_r rotor teeth and N_ph phases in full step mode, the step angle is:

Step Angle = 360 / (N_r x N_ph) degrees

More commonly, stepper motors are specified directly by their step angle (e.g., 1.8 degrees per step, meaning 200 steps per revolution). Motor speed in RPM is related to step rate by: RPM = (step_rate x 60) / steps_per_revolution. The software delay between steps controls the step rate.

Example
Given:
Step angle = 1.8 degrees per step (200 steps/revolution)
Desired speed = 60 RPM
Driving mode = Full Step (2-phase excitation)

Why this formula applies:
Speed in RPM depends on how many steps are issued per second.

Formula:
Step rate = (RPM x steps_per_revolution) / 60
Delay per step = 1 / step_rate

Substitution:
Step rate = (60 x 200) / 60
Delay per step = 1 / 200

Calculation:
Step rate = 200 steps/second
Delay per step = 5 ms

Final Answer:
CPU must output next coil pattern every 5 ms to rotate motor at 60 RPM.
Full step sequence Port A values: 03h, 06h, 0Ch, 09h (repeat).
Exam Tip: In GATE and university problems, always verify the driving mode when counting steps or calculating step angle. Half-step mode gives double the steps per revolution (half the step angle). Reversing the coil sequence direction reverses motor rotation. The ULN2803 has built-in flyback diodes to protect against inductive kickback from motor coils.

Practical Understanding

Stepper motors are used in applications requiring controlled position without position sensors: printers (paper feed and print head), CNC machines, disk drive head positioning, and camera auto-focus mechanisms. The open-loop nature of stepper control (no encoder feedback) is acceptable when step losses due to overloading or excessive acceleration are prevented by proper torque selection and ramp-up profiles.

When the motor is suddenly started at high speed, it may miss steps because the rotor cannot accelerate fast enough. A ramp acceleration profile is used in practice: the step delay is initially long (slow start) and progressively reduced to the target rate. Similarly, deceleration ramps are applied before stopping to prevent overshoot.

Loading lab...

Quick Revision

  • Stepper motor rotates in discrete steps. Step angle = 360 / (rotor teeth x phases). Common: 1.8 deg/step = 200 steps/rev.
  • Wave drive: 1 coil at a time (01h, 02h, 04h, 08h). Minimum torque.
  • Full step drive: 2 coils at a time (03h, 06h, 0Ch, 09h). Higher torque.
  • Half step drive: 8-step sequence alternating 1 and 2 coils. Doubles resolution, halves step angle.
  • RPM = (step_rate x 60) / steps_per_rev. Step delay = 1 / step_rate.
  • 8255 Port A output drives ULN2803 Darlington array which switches motor coil currents. Control word = 80h for Mode 0, Port A output.
  • Exam trap: Reversing the look-up table traversal direction reverses rotation. ULN2803 flyback diodes protect against motor inductive kickback.

Stepper Motor Quiz

Test your knowledge of stepper motor coil excitation sequences and interfacing with microprocessors.

Question 1 of 3

Q1.A 4-phase stepper motor is driven in full-step single-phase excitation (wave drive) mode. The coil sequence for clockwise rotation is A, B, C, D. Which byte sequence (for coils D3=D, D2=C, D1=B, D0=A) correctly represents the first four steps?