Stepper Motor Driver
This is a more detailed piece of PBASIC code that shows how to drive a
unipolar 4 coil stepper motor. It also includes two switches to
increase and decrease the speed of the motor, and an LCD output to
display the motor speed.
I wanted this to be a quick-n-dirty test of some surplus stepper
motors I had picked up. I found some Epson stepper motors at Halted Speciality Supply in
Sunnyvale, CA. The only markings on them were MCM-1 and
4608. The only way to determine what wire drove what coil was
to use a ohmmeter and some simple deduction.
Features
- Drives 4 coil unipolar stepper motor
- Speed control via push buttons
- Speed dispalyed on LCD screen
- PBASIC code is self-documenting (good use of symbols)
Possible improvements
- Uses 4 output lines of a BS2. Should use a stepper motor driver
- No direction control of the motor
Stamp2 code for 4 coil stepper motor
The LCD is connected to Pin 11 on the Stamp. It is used to display the
current delay setting between pulsing each coil. NOTE: the LCD
is set to display at 9600 baud. If you are using a LCD display from Scott Edwards Electronics be sure to
set the toggle on the back to 9600 baud.
There are two buttons: one on Pin 12 to speed up the motor (by
reducing the delay) and one on Pin 11 to slow down the motor (by
increasing the delay). These buttons are active high.
Click here to download the source code.
'
' stepper.bs2
'
' Drive a 4 coil unipolar stepper motor using 4 Stamp pins
' Inefficient, but works if you have no L293 or ULN2003
'
' Mark Crosbie 1/14/98 mark@mastincrosbie.com
' v1.0: Drives motor forwards
' v1.1: Added speedup/slowdown buttons
'
' Assumes:
'
' pin 5 pin 8
' +-----| |-----+
' % %
' 1 % % 3
' % %
' +-----| |-----+ common - connected to 12V
' % %
' 2 % % 4
' % %
' +-----| |-----+
' pin 7 pin 10
'
' These are defined as COIL1, COIL2, COIL3 and COIL4
'
' Speedup: pin 12
' Slowdown: pin 13
'
' LCD: pin 11
' symbolic constants for coil pins.
COIL1 con 5
COIL2 con 7
COIL3 con 8
COIL4 con 10
SPEEDUP con 12
SLOWDOWN con 13
LCD con 11
N96N con 16468
LCDCLS con 1
LCDPREFIX con 254
' These define which outputs get turned on to drive that coil.
DRIV1 var word
DRIV2 var word
DRIV3 var word
DRIV4 var word
delay var word
wrk1 var word
wrk2 var word
DRIV1 = dcd COIL1
DRIV2 = dcd COIL2
DRIV3 = dcd COIL3
DRIV4 = dcd COIL4
' set output bits on all the driver lines
dirs = (DRIV1 | DRIV2 | DRIV3 | DRIV4 | (ncd LCD))
delay = 20
wrk1 = 0
wrk2 = 0
' set the LCD to the current delay
serout LCD, N96N, [LCDPREFIX, LCDCLS]
serout LCD, N96N, ["Delay = ", dec delay]
top:
button SPEEDUP, 1, 0, 20, wrk1, 0, checkslow
if delay = 0 then checkslow
delay = delay - 1
serout LCD, N96N, [LCDPREFIX, LCDCLS]
serout LCD, N96N, ["Delay = ", dec delay]
goto spin
checkslow:
button SLOWDOWN, 1, 0, 20, wrk2, 0, spin
if delay = 200 then spin
delay = delay + 1
serout LCD, N96N, [LCDPREFIX, LCDCLS]
serout LCD, N96N, ["Delay = ", dec delay]
spin: outs = DRIV1 | DRIV3
pause delay
outs = DRIV1 | DRIV4
pause delay
outs = DRIV2 | DRIV4
pause delay
outs = DRIV2 | DRIV3
pause delay
goto top
|