' STEP_2.Bas - PICAXE 18X
'
' Illustrates control of two uni-polar stepper motors.
'
' Motor A on low four bits of outputs, Motor B on upper four bits.
'
' Note that a ULN2803 or similar is required to interface with the steppers.
'
' Pullup resistors (10K typ) to +5 VDC required on Inputs 0, 1, 6 and 7.
'
' A GRD on Pin0 casues Motor A to turn. Similarly, a ground on Pin1 causes Motor B to turn.
' the direction is determined by the state of Input 6 for Motor A and Input 7 for Motor B.
'
' Note that both motors travel at the same speed.
'
' Uses nominally 135 of 2048 bytes. It appears that this would run on a PICAXE-18A
'
' copyright, Jesus Hernandez, Peter H Anderson, Baltimore, MD, May, '04
Symbol StepPatt = B0
Symbol OutPatt = B1
Symbol StepIndexA = B2
Symbol StepIndexB = B3
Symbol StepOnA = Pin0
Symbol StepOnB = Pin1
Symbol StepDirA = Pin6
Symbol StepDirB = Pin7
StepIndexA = 0
StepIndexA = 0
OutPatt = $11 ' output something to hold motors in place
Pins = OutPatt
MotorA:
If StepOnA = 1 Then MotorB ' skip to control motor B
' Control Motor A
If StepDirA = 0 Then CWA
Goto CCWA
CWA:
If StepIndexA = 0 Then CWA_1
StepIndexA = StepIndexA - 1
GoTo CWA_2
CWA_1:
StepIndexA = 7
CWA_2:
Goto OutPattA
CCWA:
If StepIndexA = 7 Then CCWA_1
StepIndexA = StepIndexA + 1
GoTo CCWA_2
CCWA_1:
StepIndexA = 0
CCWA_2:
OutPattA:
Lookup StepIndexA, ($01, $03, $02, $06, $04, $0c, $08, $09), StepPatt
OutPatt = OutPatt & $f0 | StepPatt
Pins = OutPatt
MotorB:
If StepOnB = 1 Then TimeDelay ' skip to delay
' otherwise, control MotorB
If StepDirB = 0 Then CWB
Goto CCWB
CWB:
If StepIndexB = 0 Then CWB_1
StepIndexB = StepIndexB - 1
GoTo CWB_2
CWB_1:
StepIndexB = 7
CWB_2:
Goto OutPattB
CCWB:
If StepIndexB = 7 Then CCWB_1
StepIndexB = StepIndexB + 1
GoTo CCWB_2
CCWB_1:
StepIndexB = 0
CCWB_2:
OutPattB:
Lookup StepIndexB, ($01, $03, $02, $06, $04, $0c, $08, $09), StepPatt
StepPatt = StepPatt * 16 ' move to high nibble
OutPatt = OutPatt & $0f | StepPatt
Pins = OutPatt
TimeDelay:
Pause 50 ' adjust as necessary to control the speed of a motor.
Goto MotorA