Driving a uni-polar stepper motor with theSAA 1027 stepper motor driver
|
|
![]() Suggested PCB layout. The Velleman side is on the left and motor and power connections on the right. |
The programBecause the SAA1027 does most of the work, programming the project
is simplicity itself. The motor is driven by lines 420 to 430 which are of course in a continous loop.
|
10 REM K8055_SAA1027 20 REM Control one stepper motor with the Velleman K8055 interface board and a SAA1027 IC 30 REM Jochen Lueg 40 REM http://roevalley.com 50 REM Limavady, June 2012 60 REM Version 1.0 70 80 ON ERROR PROCerror 90 PROCK8055_init 100 PROCinit 110 ON CLOSE PROCclose 120 PROCwindow(680,300,"SAA 1027 driver") 130 OFF 140 SYS K8055_CloseDevice%,0 150 SYS K8055_OpenDevice%,0 160 170 PRINT 180 PRINT 190 PRINT " Left - Stop - Right . . . . . . Z X C" 200 PRINT " Fast - - - Slow . . . . . . 1 - 9" 210 PRINT 220 PRINT " Quit the progran . . . . . . Q" 230 240 REM Main loop 250 REPEAT 260 Key$=INKEY$(0):REPEAT UNTIL INKEY(0)=-1 270 IF Key$ = "z" OR Key$ = "Z" Dir$="left" :PROCreport 280 IF Key$ = "c" OR Key$ = "C" Dir$="right" :PROCreport 290 IF Key$ = "x" OR Key$ = "X" Dir$="not at all" : SYS K8055_ClearAllDigital%:PROCreport 300 IF Dir$="left" SYS K8055_SetDigitalChannel%,7 310 IF Dir$="right" SYS K8055_ClearDigitalChannel%,7 320 IF Key$="1" Speed%=10:PROCreport 330 IF Key$="2" Speed%=20 :PROCreport 340 IF Key$="3" Speed%=50 :PROCreport 350 IF Key$="4" Speed%=75 :PROCreport 360 IF Key$="5" Speed%=150 :PROCreport 370 IF Key$="6" Speed%=300 :PROCreport 380 IF Key$="7" Speed%=600 :PROCreport 390 IF Key$="8" Speed%=1000 :PROCreport 400 IF Key$="9" Speed%=1400 :PROCreport 410 IF Dir$<>"not at all" THEN 420 SYS K8055_SetDigitalChannel%,8 430 FOR J%=1 TO Sp%*Speed%:NEXT 440 SYS K8055_ClearDigitalChannel%,8 450 ENDIF 460 UNTIL Key$ = "q" OR Key$ = "Q" 470 PROCclose 480 END 490 500 510 520 DEFPROCclose 530 SYS K8055_ClearAllDigital% 540 SYS K8055_CloseDevice% 550 SYS "FreeLibrary",K8055_Board% 560 QUIT 570 ENDPROC 580 590 600 DEFPROCreport 610 LOCAL S% 620 S%=Speed% 630 IF Dir$="not at all" S%=0 640 PRINTTAB(1,11)"The motor is"; 650 IF Dir$="not at all" PRINT;" not turnig. "; 660 IF Dir$<>"not at all" PRINT;" turnig ";Dir$;" at speed ";S%;" " 670 ENDPROC 680 690 700 DEFPROCinit 710 Dir$="not at all" 720 Sp%=15000 730 Speed%=10 740 SYS K8055_WriteAllDigital%,0 750 ENDPROC 760 770 780 DEFPROCwindow(WindowWidth%,WindowHeight%,W$) 790 MODE 30 800 SYS "SetWindowPos",@hwnd%,0,0,0,WindowWidth%,WindowHeight%,6 810 SYS "SetWindowText",@hwnd%,W$ 820 VDU 26 830 COLOUR 15 840 *FONT Lucida Console,14,2 850 ENDPROC 860 870 880 DEFPROCerror 890 PRINT REPORT$;" at line ";ERL 900 SYS K8055_ClearAllDigital% 910 SYS K8055_ClearAllAnalog% 920 SYS K8055_CloseDevice% 930 SYS "FreeLibrary",K8055_Board% 940 END 950 ENDPROC 960 970 980 DEFPROCK8055_init 990 SYS"LoadLibrary","K8055D.dll" TO K8055_Board% 1000 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice% 1010 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice% 1020 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel% 1030 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog% 1040 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel% 1050 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog% 1060 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel% 1070 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog% 1080 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel% 1090 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog" TO K8055_SetAllAnalog% 1100 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital% 1110 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel% 1120 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital% 1130 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel% 1140 SYS"GetProcAddress",K8055_Board%,"SetAllDigital" TO K8055_SetAllDigital% 1150 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel% 1160 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital" TO K8055_ReadAllDigital% 1170 SYS"GetProcAddress",K8055_Board%,"ResetCounter" TO K8055_ResetCounter% 1180 SYS"GetProcAddress",K8055_Board%,"ReadCounter" TO K8055_ReadCounter% 1190 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime" TO K8055_SetCounterDebounceTime% 1200 ENDPROC 1210 |
Back to the start
|