EDN Access -- 02.17.94 Motor-drive algorithm saves space and cycle

-February 17, 1994

EDN logo

Design Ideas:February 17, 1994

Motor-drive algorithm saves space and cycles

Jose A P Machado da Silva,
University of Porto, Porto, Portugal

Listing 1—Stepper motor drive subroutines

The algorithm embodied in the second subroutine in Listing 1 generates the excitation sequence for most permanent-magnet and hybrid stepper motors. This subroutine is smaller than subroutines that spring from other algorithms.

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 bytes—48HEX, 84HEX, 23HEX, or 12HEX—to 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

| EDN Access | feedback | subscribe to EDN! |
| design features | design ideas |

Copyright c 1995 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.

Loading comments...

Write a Comment

To comment please Log In