Classic Computer Magazine Archive COMPUTE II ISSUE 3 / AUGUST/SEPTEMBER 1980 / PAGE 18

A Simple Interface For A Stepper Motor

Marvin L. De Jong
Department of Mathematics-Physics
The School of the Ozarks

The circuit shown in Figure 1 and the programs given in Listing 1 allow you to drive a stepper motor with your 6502 based microcomputer. Why run a stepper motor? Perhaps to drive a solar panel to follow the sun, homebrew your own x-y plotter, run a pump at a preselected rate, or turn your robot's head. Whatever your application may be, here is some information to get you started working with stepper motors. You will want to get additional information from the following companies:

North American Philips Controls Corp.
Chesire Industrial Park
Cheshire, CONN 06410
(203) 272-0301

Dana Industrial
11901 Burke St.
Santa Fe Springs, CA 90670
(213) 698-2595

You can get a nice Stepper Motor Handbook from AIRPAX, and the specification sheet for the Stepper Motor IC Driver SAA1027 also is available from AIRPAX. The circuit we used made use of this integrated circuit driver and an AIRPAX 82701 stepper motor. The circuit was breadboarded on a FIRST MATE/SECOND MATE system from MicroMate.

The circuit of Figure 1 consists of a 7406 inverter with high voltage open-collector outputs. Two pins of the Port B application port on the computer drive the 7406 which in turn controls the trigger (T) input and the rotation direction (R) input on the stepper motor IC driver. The driver chip controls the stepper motor.

Listing 1 gives several subroutines that may be used to control the motor. The instructions in the INITIALIZE routine should be used near the beginning of any program to drive the stepper motor. These instructions place the proper logic levels on the T and R pins. In Listing 1 the initialization instructions are part of a short program from $0300 to $0328 that will run the stepper motor at a constant rate. The rate used in this program is about 200 steps/second, near the maximum rate for this particular motor. Since each step for the 82701 is a 7.5° step, the rotation rate is 250 rpm.

The INITIALIZE and MOTOR RUN routines call two subroutines, TRIGGER and either CW or CCW. Calling subroutine TRIGGER produces one step on the stepper motor. If the TRIGGER call is preceded by a subroutine call for CW, then the motor will turn clockwise (CW). If CCW (for counterclockwise) is called, then the motor will turn counterclockwise. The MOTOR RUN routine is an infinite loop, and is listed here to show how to make the motor run. Note that we have used the T1 timer on the 6522 VIA to control the time between steps.

Subroutine MOVE can be used to turn the stepper motor a prescribed number of steps, either CW or CCW depending on which subroutine is called. The number of steps is stored in location STEPS at address $0000. Again, the T1 timer on the 6522 VIA is used to produce the necessary delay between steps. The stepper motor is not capable of turning as fast as the computer can toggle the T input, hence either a timer delay or a delay loop must be used to wait.

Be sure to get all the information about various motors and drivers before you get started with your project. Quite obviously, different projects will demand different motors; larger, smaller, geared, linear actuators, etc. Then build something spectacular and let us hear about it.

Figure 1. Stepper motor interface. The SAA1027 is a special driver integrated circuit. The 7406 will also require five volts for its own power.

Listing 1. Driver Routines for the Stepper Motor Interface.

0300 A9 03     INITIALIZE  LDA $03     Set up Port B to make pins PB0 and PB1
0302 8D 02 A0              STA PBDD    output pins.
0305 A9 00                 LDA $00     Pull driver pins T and R to logic one 
0307 8D 00 A0              STA PBD     through the 7406 inverter.
030A A9 40     MOTOR RUN   LDA $40     Put the T1 timer in its free-running
030C 8D 0B A0              STA ACR     mode by setting bit six to logic one.
030F A9 86                 LDA $86     Set up the T1 timer to time out every
0311 8D 04 A0              STA T1LL    5 milliseconds giving 200 steps/sec.
0314 A9 13     MORE        LDA $13     ($1386 + 2 = 5000)
0316 8D 05 A0              STA T1LH    Now the timer is loaded and running.
0319 2C 0D A0  LOAF        BIT IFR     Has the timer out?
031C 50 FB                 BVC LOAF    No. Then loaf here.
031E 20 07 04              JSR CW      Subroutine CW will result in motor
0321 20 00 04              JSR TRIGGER running clockwise, CCW turns it counter-
0324 AD 04 A0              LDA T1CL    clockwise. Subroutine TRIGGER produces
0327 18                    CLC         one step of the motor.
0328 90 EA                 BCC MORE    clear the interrupt flag, then return 
                                       to make another step
0400 EE 00 A0  TRIGGER     INC PBD     Pulse the T input of the stepper motor
0403 CE 00 A0              DEC PBD     driver.
0406 60                    RTS
0407 A9 02     CW          LDA $02     Bring the R input to logic zero for
0409 0D 00 A0              ORA PBD     clockwise (CW) rotation, by making
040C 8D 00 A0              STA PBD     PB1 logic one.
040F 60                    RTS
0410 A9 FD     CCW         LDA $FD     Bring the R input to logic one for
0412 2D 00 A0              AND PBD     counterclockwise (CCW) rotation, by
0415 8D 00 A0              STA PBD     making PB1 logic zero.
0418 60                    RTS
0500 A9 00     MOVE        LDA $00     Set up T1 for the one-shot mode
0502 8D 0B A0              STA ACR     by clearing the 6522 ACR.
0505 20 10 04              JSR CCW     Motor will turn counterclockwise.
0508 A9 87                 LDA $87     Timer will wait 5 milliseconds between
050A 8D 04 A0              STA T1LL    steps.	
050D A9 13     AGAIN       LDA $13
050F 8D 05 A0              STA T1LH    Timer is now loaded and running.
0512 2C 0D A0  WAIT        BIT IFR     Has it timed out?
0515 50 FB                 BVC WAIT    No. Then wait here.
0517 20 00 04              JSR TRIGGER Here the motor turns one step.
051A C6 00                 DEC STEPS   Decrement the step counter.
051C D0 EF                 BNE AGAIN   Has it reached zero?
051E 60                    RTS         Yes. Then turn is complete.