10 REM Single stepper motor driver
20 REM Version 1
30 REM For The Velleman K8055 USB interface #
40 REM Jochen Lueg
50 REM http://roevalley.com/newsbrowser/v-projects/v-index.htm
60 REM Limavady, January 2012
70
80 ON ERROR PRINT ERL;" ";REPORT$:END
90 PROCK8055_init
100 PROCinit
110 SYS K8055_CloseDevice%
120 SYS K8055_OpenDevice%,0
130 PRINT
140 PRINT " Motor controls"
150 PRINT
160 PRINT " Left . . . . . . Z"
170 PRINT " Right . . . . . . C"
180 PRINT " Stop . . . . . . X"
190 PRINT " Full step . . . . . . F"
200 PRINT " Half step . . . . . . H"
210 PRINT
220 PRINT
230 PRINT " Number keys above QWERTY Press for 1 second"
240 PRINT
250 PRINT " Fastest . . . . . . 1"
260 PRINT " Slowest . . . . . . 9"
270 PRINT
280 PRINT " Press 'S' to leave the program"
290
300 REPEAT
310 Key$=INKEY$(0) : REPEAT UNTIL INKEY(0)=-1
320 IF Key$="c" OR Key$="C" Direction$="Right"
330 IF Key$="z" OR Key$="Z" Direction$="Left"
340 IF Key$="s" OR Key$="S" Direction$="Finished"
350 IF Key$="x" OR Key$="X" Direction$="Stop"
360 IF Key$="h" OR Key$="H" Mode$="Half"
370 IF Key$="f" OR Key$="F" Mode$="Full"
380 IF Key$="1" T%=35*S% :Speed$="Fast"
390 IF Key$="2" T%=70*S% :Speed$="Fast-1"
400 IF Key$="3" T%=140*S% :Speed$="Fast-2"
410 IF Key$="4" T%=280*S% :Speed$="Fast-3"
420 IF Key$="5" T%=560*S% :Speed$="Half"
430 IF Key$="6" T%=1120*S% :Speed$="Slow+3"
440 IF Key$="7" T%=2240*S% :Speed$="Slow+2"
450 IF Key$="8" T%=4480*S% :Speed$="Slow+1"
460 IF Key$="9" T%=8960*S% :Speed$="Slow"
470 IF Direction$="Right" AND Mode$="Full" THEN PROCfull_step_right
480 IF Direction$="Right" AND Mode$="Half" THEN PROChalf_step_right
490 IF Direction$="Left" AND Mode$="Full" THEN PROCfull_step_left
500 IF Direction$="Left" AND Mode$="Half" THEN PROChalf_step_left
510 IF Direction$ <> "Wait"
PRINTTAB(1,16);Mode$;" step. Turning ";Direction$;" with speed
";Speed$;" "
520 IF Direction$="Stop" PRINTTAB(1,16)"Motor
stopped
"
530 IF Direction$="Stop" SYS K8055_ClearAllDigital%:Direction$="Wait"
540 UNTIL Direction$="Finished"
550
560 PRINTTAB(1,16)"All good things come to an
end.
"
570 SYS K8055_ClearAllDigital%
580 SYS K8055_CloseDevice%
590 *QUIT
600 END
610
620
630
640 DEFPROChalf_step_right
650 FOR J%=1 TO 8
660 SYS K8055_WriteAllDigital%,HalfStep%(J%): FOR I%=1 TO T%:NEXT
670 NEXT
680 ENDPROC
690
700
710 DEFPROChalf_step_left
720 FOR J%=8 TO 1 STEP -1
730 SYS K8055_WriteAllDigital%,HalfStep%(J%): FOR I%=1 TO T%:NEXT
740 NEXT
750 ENDPROC
760
770
780 DEFPROCfull_step_right
790 FOR J%=1 TO 4
800 SYS K8055_WriteAllDigital%,FullStep%(J%): FOR I%=1 TO T%:NEXT
810 NEXT
820 ENDPRO
|
830
840
850 DEFPROCfull_step_left
860 FOR J%=4 TO 1 STEP -1
870 SYS K8055_WriteAllDigital%,FullStep%(J%): FOR I%=1 TO T%:NEXT
880 NEXT
890 ENDPROC
900
910
920 DEFPROCinit
930 COLOUR 128
940 CLS
950 COLOUR 15
960 W%=0
970 Direction$="Stop"
980 S%=5000
990 T%=S%*35
1000 Speed$="Fast"
1010 Mode$="Full"
1020
1030 DIM HalfStep%(8)
1040 HalfStep%(1)=&11
1050 HalfStep%(2)=&33
1060 HalfStep%(3)=&22
1070 HalfStep%(4)=&66
1080 HalfStep%(5)=&44
1090 HalfStep%(6)=&CC
1100 HalfStep%(7)=&88
1110 HalfStep%(8)=&99
1120
1130 DIM FullStep%(4)
1140 FullStep%(1)=%00010001
1150 FullStep%(2)=%00100010
1160 FullStep%(3)=%01000100
1170 FullStep%(4)=%10001000
1180
1190 ENDPROC
1200
1210
1220 DEFPROCK8055_init
1230 REM Typing errors in routine name do not generate an error message - they just hang up the program.
1240 REM These are all the system calls in the order found in the manual
1250 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
1260 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
1270 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
1280 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
1290 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
1300 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
1310 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
1320 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
1330 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
1340 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
1350 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog" TO K8055_SetAllAnalog%
1360 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
1370 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
1380 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
1390 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
1400 SYS"GetProcAddress",K8055_Board%,"SetAllDigital" TO K8055_SetAllDigital%
1410 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
1420 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital" TO K8055_ReadAllDigital%
1430 SYS"GetProcAddress",K8055_Board%,"ResetCounter" TO K8055_ResetCounter%
1440 SYS"GetProcAddress",K8055_Board%,"ReadCounter" TO K8055_ReadCounter%
1450 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime" TO K8055_SetCounterDebounceTime%
1460 ENDPROC
|