STAMP II 3x STEPPER MOTOR RS-232 DRIVER

Abstract
This application note demonstrates simple hardware
and software techniques for driving and controlling 3 common four-coil
stepper motors by one Stamp II board. The below text / work is a modified
version of Parallax, Inc. single axis Stamp I driver. The program is adjusted
to run 3 motors simultaneously on a Stamp II board. The board as been tested
succesfully with stepper motors from RS (Serial no. 440-436).
Introduction - Background
Stepper motors translate digital switching sequences
into motion. They are used in printers, automated machine tools, disk
drives, and a variety of other applications requiring precise motions
under computer control. Unlike ordinary dc motors,
which spin freely when power is applied, steppers require that
their power source be continuously pulsed in
specific patterns. These patterns, or step sequences, determine the
speed and direction of a stepper’s motion. For each pulse or step input,
the stepper motor rotates a fixed angular increment; typically 1.8 or 7.5
degrees.
The fixed stepping angle gives steppers their precision. As long as the
motor’s maximum limits of speed or torque are not exceeded, the
controlling program knows a stepper’s precise position at any given
time.
Steppers are driven by the interaction (attraction and repulsion) of
magnetic fields. The driving magnetic field rotates as strategically
placed coils are switched on and off. This pushes and pulls at perma-nent
magnets arranged around the edge of a rotor that drives the output shaft.

Figure 2. Schematic for the serial 3x stepper motor controller.
When the on-off pattern of the magnetic fields is in the proper
sequence, the stepper turns (when it’s not, the stepper sits and quivers).
The most common stepper is the four-coil unipolar variety. These are
called unipolar because they require only that their coils be driven on
and off. Bipolar steppers require that the polarity of power to the coils
be reversed.
The normal stepping sequence for four-coil unipolar steppers appears
in figure 3. There are other, special-purpose stepping sequences, such
as half-step and wave drive, and ways to drive steppers with multi-phase
analog waveforms, but this application concentrates on the
normal sequence. After all, it’s the sequence for which all of the
manufacturer’s specifications for torque, step angle, and speed apply.

Many microprocessor stepper drivers use four output bits to generate the stepping sequence. Each bit drives a power transistor that switches on the appropriate stepper coil. The stepping sequence is stored in a lookup table and read out to the bits as required.
This design takes a slightly different approach. First, it uses only two output bits, exploiting the fact that the states of coils 1 and 4 are always the inverse of coils 2 and 3. Look at figure 3 again. Whenever coil 2 gets a 1, coil 1 gets a 0, and the same holds for coils 3 and 4. In Stamp designs, output bits are too precious to waste as simple inverters, so we give that job to two sections of the ULN2003 inverter/driver. The second difference between this and other stepper driver designs is that it calculates the stepping sequence, rather than reading it out of a table. While it’s very easy to create tables with the Stamp, the calcula-tions required to create the two-bit sequence required are very simple. And reversing the motor is easier, since it requires only a single additional program step. See the program listing in the APPENDIX below.
How it works.
The stepper controller accepts commands from a termi-nal or PC via a
38400-baud serial connection. (no parity, 8 databits and 1 stop bit).
When power is first applied
to the Stamp, it sends a prompt to be displayed on the terminal screen.
The user types a string representing the direction (+ for forward, - for
backward), number of steps, and at last step delay (in milliseconds), like this:
cmd>+500 +100 -100 20
As soon as the user presses enter, return, or any non-numerical charac-ter
at the end of the line, the Stamp starts the motor running. When the
stepping sequence is over, the Stamp sends a new cmd> prompt to the
terminal. The sample command above would take about 10 seconds
(500 x 20 milliseconds). Commands entered before the prompt reap-pears
are ignored.
On the hardware side, the application accepts any stepper that draws 500 mA or less per coil. In Figure 2, the schematic shows the color code for an Airpax-brand stepper, but there is no standardization among different brands. If you use another stepper, use Figure 2 and an ohmmeter to translate the color code. Connect the stepper and give it a try. If it vibrates instead of turning, you have one or more coils connected incorrectly. Patience and a little experimentation will prevail.
The Stamp II 3Mx PC program module

APPENDIX
Use the stamp2.exe to load this program into Stamp memory!
The programming RS-232 plug's pin connections are shown in Figure 2.
Stamp II 3Mx program listing
'Program to run 3 stepper motors
'By F. Sigernes and D. A. Lorentzen
Directn1 VAR BYTE
Directn2 VAR BYTE
Directn3 VAR BYTE
Steps1 VAR WORD
Steps2 VAR WORD
Steps3 VAR WORD
SLEP VAR WORD
I VAR WORD
C VAR WORD
M1 VAR WORD
M2 VAR WORD
M3 VAR WORD
Dircmd1 VAR BYTE
Dircmd2 VAR BYTE
Dircmd3 VAR BYTE
DIRS = %0000000000111111 : OUTS = %0000000000010101
M1 = %0000000000000001 : M2 = %0000000000000100
M3 = %0000000000010000
Directn1 = "+" : Directn2 = "+" : Directn3 = "+"
SLEP = 5
SEROUT 16,6+$4000,["Welcome Stamp II 3x Serial RS-232 Driver!",13]
SEROUT 16,6+$4000,["by Sigernes and Lorentzen UNIS 2003",13]
SEROUT 16,6+$4000,["Command input format:",13]
SEROUT 16,6+$4000,["Cmd>+/-STEPS1 +/-STEPS2 +/-STEPS3