I have got a stepper motor working nicely on a basic stamp with the following code. But am unsure of what changes should I make for the same code to work on a PIC. I understand most of what is going on but am a bit unsure about what the Phase is about and the OUTB
Phase VAR OUTB ' phase control outputs
idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control
Steps DATA %0011, %0110, %1100, %1001
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 5 ' set step delay
Main:
FOR idx = 1 TO 200 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 500 ' wait 1/2 second
FOR idx = 1 TO 200 ' one revolution
GOSUB Step_Rev ' rotate counter-clockwise
NEXT
PAUSE 500 ' wait 1/2 second
GOTO Main
END
' -----[ Subroutines ]-----------------------------------------------------
Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step
Step_Rev:
stpIdx = stpIdx + 3 // 4 ' point to previous step
GOTO Do_Step
Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN
Bookmarks