bs2 code help - controlling stepper motors independently
Archiver
Posts: 46,084
hi everyone,
i'm using a bs2 to drive 2 stepper motors. i'm having trouble with
the code. i'm very new at this. i'm trying to control the motors
independently but i can't figure out how to have the motors do
different actions from each other at the same time. i'm trying to
figure out how to do it with the sample code from parallax below.
'{$STAMP BS2}
'{$PBASIC 2.5}
Phase VAR OUTB
Phase2 VAR OUTC
idx VAR Byte
stpIdx VAR Nib
stpDelay VAR Byte
Steps DATA %0011, %0110, %1100, %1001
Setup:
DIRB = %1111
DIRC = %1111
stpDelay = 30
Main:
FOR idx = 1 TO 48
GOSUB Step_Fwd
NEXT
PAUSE 500
FOR idx = 1 TO 48
GOSUB Step_Rev
NEXT
PAUSE 500
GOTO Main
END
Step_Fwd:
stpIdx = stpIdx + 1 // 4
GOTO Do_Step
STEP_Rev:
stpIdx = stpIdx + 3 // 4
GOTO Do_Step
Do_Step:
READ (Steps + stpIdx), Phase
READ (Steps + stpIdx), Phase2
PAUSE stpDelay
RETURN
If anyone has any advice on how to modify the code to do this i would
greatly appreciate
it.
Adam
i'm using a bs2 to drive 2 stepper motors. i'm having trouble with
the code. i'm very new at this. i'm trying to control the motors
independently but i can't figure out how to have the motors do
different actions from each other at the same time. i'm trying to
figure out how to do it with the sample code from parallax below.
'{$STAMP BS2}
'{$PBASIC 2.5}
Phase VAR OUTB
Phase2 VAR OUTC
idx VAR Byte
stpIdx VAR Nib
stpDelay VAR Byte
Steps DATA %0011, %0110, %1100, %1001
Setup:
DIRB = %1111
DIRC = %1111
stpDelay = 30
Main:
FOR idx = 1 TO 48
GOSUB Step_Fwd
NEXT
PAUSE 500
FOR idx = 1 TO 48
GOSUB Step_Rev
NEXT
PAUSE 500
GOTO Main
END
Step_Fwd:
stpIdx = stpIdx + 1 // 4
GOTO Do_Step
STEP_Rev:
stpIdx = stpIdx + 3 // 4
GOTO Do_Step
Do_Step:
READ (Steps + stpIdx), Phase
READ (Steps + stpIdx), Phase2
PAUSE stpDelay
RETURN
If anyone has any advice on how to modify the code to do this i would
greatly appreciate
it.
Adam