Design Ideas: February 17, 1994
| Listing 1Stepper motor drive subroutines |
|---|
![]() |
To understand the algorithm, first consider that stepper motors have two stator coils, A and B, each having a center tap. Phase notation (A,A,B, and B) shows the direction of the current flow. That is, AA=102 symbolizes that current flows through half-coil A and that half-coil A is off.
To get the maximum torque from a stepper motor, you must drive two phases at a time. Using the binary notation developed in the preceding paragraph, the 4-phase drive sequence for all four half coils is 01012, 01102, 10102, 10012 or 5HEX, 6HEX, AHEX, 9HEX.
The usual technique for generating this sequence with a µP is to look up the succeeding phase commands in a table (see the first subroutine in Listing 1). This operation requires a multibyte MOV instruction. The new algorithm obtains each phase by rotating the accumulator's contents (Fig 1). Thus, the algorithm saves processor cycles and the space needed for the table.
In Fig 1, the accumulator begins with A5HEX. The accumulator's least-significant four bits are the motor-drive output (5HEX). Two circular-rotate left instructions yield the next motor-drive output, 6HEX, and so on. To drive the motor in the opposite direction, reverse the sense of the rotation instructions.
Comparing the two subroutines in the listing, you can see that the accumulator-rotating algorithm saves 10 memory locations (six in the subroutine plus four in the table) and three µP cycles for each step.
You can use the same algorithm to generate wave-drive and half-step sequences. Rotate one of the bytes48HEX, 84HEX, 23HEX, or 12HEXto obtain wave drive. Obtain the sequence 01012, 01002, 01102, 00102, 10102, 10002, 10012, 00012 by alternately rotating both of the full-step sequences to achieve half-step drive, saving even more memory.EDN BBS /DI_SIG #1368