STAMP II 3x STEPPER MOTOR RS-232 DRIVER

Compiled by F. Sigernes (1), K. Sandaker (2), and S. Olsen (2).


Figure 1. The 3x StampII S. Nr. 487 UNIS Stepper motor controller.

(1) The University Courses on Svalbard, N-9171 Longyearbyen, Norway.
(2) The Auroral Observatory, University of TromsÝ, Norway.

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.


Figure 3. Normal stepping sequence.

If you run the stepping sequence in figure 3 forward, the stepper rotates clockwise; run it backward, and the stepper rotates counterclockwise. The motorís speed depends on how fast the controller runs through the step sequence. At any time the controller can stop in mid sequence. If it leaves power to any pair of energized coils on, the motor is locked in place by their magnetic fields. This points out another stepper motor benefit: built-in brakes.

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


Figure 4. The main module of the PC program: StampII3Mx.exe

(1) is a RS-232 Terminal Emulator. The (2) button open / close communication for the terminal. (3) is RS-232 settings. (4) is this page. In panel (5) you can enter motor settings, such as steps per revolution and speed per step. Also incremetal steps can be entered. Note that these values are entered for each motor #. All of the settings are stored when terminating the module. The buttons in panel (6) enables you to move incremental steps according to panel (5) for each motor. (7) is statusbar for runtime messages.

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

Cmd:SEROUT 16,6+$4000,["Cmd>"]
SERIN 16, 6+$4000,[Dircmd1, DEC Steps1]
SERIN 16, 6+$4000,[Dircmd2, DEC Steps2]
SERIN 16, 6+$4000,[Dircmd3, DEC Steps3]
SERIN 16, 6+$4000,2000,nodata,[DEC SLEP]

noData:

if Dircmd1 = Directn1 then DL1
M1 = M1^%0000000000000011
DL1:

if Dircmd2 = Directn2 then DL2
M2 = M2^%0000000000001100
DL2:

if Dircmd3 = Directn3 then DL3
M3 = M3^%0000000000110000
DL3:

C = Steps1

if C > Steps2 then IFL1
C = Steps2
IFL1:

if C > Steps3 then IFL2
C = Steps3
IFL2:

FOR I = 1 to C

if Steps3 = 0 then skip3
if I > Steps3 then skip3
OUTS = OUTS^M3
M3 = M3^%0000000000110000
skip3:

if Steps2 = 0 then skip2
if I > Steps2 then skip2
OUTS = OUTS^M2
M2 = M2^%0000000000001100
skip2:

if Steps1 = 0 then skip1
if I > Steps1 then skip1
OUTS = OUTS^M1
M1 = M1^%0000000000000011
skip1:

pause SLEP
NEXT

Directn3 = Dircmd3
Directn2 = Dircmd2
Directn1 = Dircmd1

goto Cmd

SOURCE: Modified stamp program from the: BASIC Stamp Programming Manual 1.8 Parallax, Inc.