Controlling a uni-polar stepping motor
|
The programs
|
| REM Bi-polar stepper driver REM For the Raspberry Pi computerle REM Jochen Lueg REM http://roevalley.com REM Limavady, November 2012 REM Version 1.0 ON ERROR PRINT ERL;" ";REPORT$:END PROCinit OSCLI"RMensure GPIO 0.40 ERROR Please inbstall the GPIO module" PROCsetupGPIO OFF PRINT " Motor controls" PRINT " Left . . . . . . Z" PRINT " Right . . . . . . C" PRINT " Stop . . . . . . X" PRINT " Full step . . . . . . F" PRINT " Half step . . . . . . H" PRINT " Fastest . . . . . . 1" PRINT " to" PRINT " Slowest . . . . . . 9" PRINT " Press 'Q' to leave the program" REPEAT Key$=INKEY$(0) : REPEAT UNTIL INKEY(0)=-1 IF Key$="c" OR Key$="C" Direction$="Right" IF Key$="z" OR Key$="Z" Direction$="Left" IF Key$="q" OR Key$="Q" Direction$="Finished" IF Key$="x" OR Key$="X" Direction$="Stop" IF Key$="h" OR Key$="H" Mode$="Half" IF Key$="f" OR Key$="F" Mode$="Full" IF Key$="1" T%=150*S% :Speed$="Fast" IF Key$="2" T%=200*S% :Speed$="Fast-1" IF Key$="3" T%=300*S% :Speed$="Fast-2" IF Key$="4" T%=625*S% :Speed$="Fast-3" IF Key$="5" T%=1250*S% :Speed$="Half" IF Key$="6" T%=2500*S% :Speed$="Slow+3" IF Key$="7" T%=5000*S% :Speed$="Slow+2" IF Key$="8" T%=10000*S% :Speed$="Slow+1" IF Key$="9" T%=20000*S% :Speed$="Slow" IF Direction$="Right" AND Mode$="Full" THEN PROCfull_step_right IF Direction$="Right" AND Mode$="Half" THEN PROChalf_step_right IF Direction$="Left" AND Mode$="Full" THEN PROCfull_step_left IF Direction$="Left" AND Mode$="Half" THEN PROChalf_step_left IF Direction$="Stop" PRINTTAB(1,18)"Motor stopped " IF Direction$="Stop" PROCall_off:Direction$="Wait" IF Direction$ <> "Wait" PRINTTAB(1,18);Mode$;" step. Turning ";Direction$;" with speed ";Speed$;" " UNTIL Direction$="Finished" END DEFPROCfull_step_right LOCAL J%, FOR J%=0 TO 3 SYS"GPIO_WriteData",Full%(J%),1 PROCall_off NEXT ENDPROC DEFPROCfull_step_left LOCAL J%, FOR J%=3 TO 0 STEP -1 SYS"GPIO_WriteData",Full%(J%),1 PROCall_off NEXT ENDPROC DEFPROCall_off LOCAL J%,Speed% FOR Speed%=1 TO T%:NEXT FOR J%=0 TO 3 SYS"GPIO_WriteData",Full%(J%),0 NEXT ENDPROC DEFPROChalf_step_right LOCAL J% FOR J%=0 TO 7 SYS"GPIO_WriteData",Half%(J%),1 SYS"GPIO_WriteData",Half%(J%+1),1 PROCall_off NEXT ENDPROC DEFPROChalf_step_left LOCAL J%,Speed% FOR J%=8 TO 1 STEP -1 SYS"GPIO_WriteData",Half%(J%),1 SYS"GPIO_WriteData",Half%(J%-1),1 PROCall_off NEXT ENDPROC DEFPROCsetupGPIO SYS"GPIO_EnableI2C",0 SYS"GPIO_ExpAsGPIO",2 ENDPROC DEFPROCinit W%=0 Direction$="Stop" S%=800 T%=S%*150 Speed$="Fast" Mode$="Full" DIM Full%(3) : Full%()=24,23,18,15 DIM Half%(8) : Half%()=24,24,23,23,18,18,15,15,24 ENDPROC DEFPROCerror PRINT REPORT$;" at line ";ERL : END ENDPROC |
Back to the start
|