Controlling a unipolar stepping motor 


The stepper adaptor This simple little project requires only a small adaptor to make it more convenient to connect the stepper motor to the Velleman board. As can be seen from the illustration on the left and the circuit diagram below, the motor is connected via 6 wires seen on the right of the picture. The two common wires of the motor coils are at the top and they connect to the positive supply seen on the bottom and the clamp input of the Velleman board. The four motor wires are then connected to outputs O5 to O8.

Be careful not to do this with a motor that draws too much current - half an amp per coil is the maximum I would risk, even though the Darlington driver fitted to the Velleman board is rated at 1A per line.Circuit diagram and PCB layout




There is a suggested PCB layout on the right, though the circuit is so simple a veroboard would do just as well.

The wires of the motor must obviously be connected in the right sequence. A simple way to do this is to test them with a 9V battery or something similar. Connect the two commons together. These are usually fitted in the centre of the coil, but they can be identified with an ohmmeter. The centre tap has the same resistance against both halves of the coil, as shown below.

Testing the coils To determine the correct sequence of wires simply connect the two commons to one side of the battery and any one of the other four wires to the other side. You have a three in four chance that the motor will move by a single step either left or right. If this doesn't happen, try another wire.

Repeat the process with a second wire. If the motor moves again in the same direction, the sequence is correct. If it turns in the other direction, you got it wrong and you have to start again from the beginning.

Generally a few tries will establish the correct sequence. Once established, I tend to fasten the wires in correct order to a small connector, as seen in the photograph above on the right of the picture.

A word about timing. To change the speed of the motor, a time wasting loop is needed. For various reason I picked a simple FOR -NEXT loop that does nothing. Depending on the motor in use, the fastest speed my be too much for your motor or, alternatively, your motor might be able to turn even faster.

 

The program

My program will turn the motor in both directions at different speed in three basic modes: Single step, half step and two-phase. Single step mode sends the pattern

0001, 0010, 0100, 1000

to the four output lines. This mode uses the least power. To reverse the motor, send the pattern

1000, 0100, 0010, 0001

Two-phase mode uses two coils at the same time. This increases the torque but doubles the current consumption. The pattern is

0011, 0110, 1100, 1001

and so on.

Half-step mode produces a half step by turning on two adjacent coils so that the rotor  moves half way between them. The pattern is

0001, 0011, 0010, 0110, 0100.1100, 1000, 1001

I have stored these values in three arrays (lines 990 to 1190 below). When you run the program, you may find that your motor turns left when the program says it should turn right. This simply means the wires of your motor are in a different sequence from the wires of my motor.

As usual, I supply both a program file and a self executing file should you not have BBC BASIC for Windows.


K8055_onestep_1_0.zip


Below are the same two files adapted for the K8061


K8061_onestep_1_0.zip

 
   10 REM One-Step
   20 REM Control one stepper motor  with the Velleman K8055 interface board
   30 REM Jochen Lueg
   40 REM http://roevalley.com
   50 REM Limavady, May 2012
   60 REM Version 1.0
   70
   80 ON ERROR PROCerror
   90 PROCK8055_init
  100 PROCinit
  110 ON CLOSE PROCclose
  120 PROCwindow(680,300,"Two-step")
  130 OFF
  140 SYS K8055_CloseDevice%,0
  150 SYS K8055_OpenDevice%,0
  160
  170 PRINT
  180 PRINT " Left - Stop - Right  . . . . . .  Z  X  C"
  190 PRINT " Full step mode       . . . . . .     F"
  200 PRINT " Two-phase full step  . . . . . .     T"
  210 PRINT " Half step mode       . . . . . .     H"
  220 PRINT " Fast - - - Slow      . . . . . .  1  -  9"
  230 PRINT
  240 PRINT " Quit the progran     . . . . . .  Q"
  250
  260 REM Main loop
  270 REPEAT
  280   Key$=INKEY$(0):REPEAT UNTIL INKEY(0)=-1
  290   IF Key$ = "z" OR Key$ = "Z" Dir$="left" :PROCreport
  300   IF Key$ = "c" OR Key$ = "C" Dir$="right" :PROCreport
  310   IF Key$ = "x" OR Key$ = "X" Dir$="not at all" : SYS K8055_ClearAllDigital%:PROCreport
  320   IF Key$ = "f" OR Key$ = "F" Mode$="FullStep" :PROCreport
  330   IF Key$ = "h" OR Key$ = "H" Mode$="HalfStep" :PROCreport
  340   IF Key$ = "t" OR Key$ = "T" Mode$="TwoPhase" :PROCreport
  350   IF Key$="1" Speed%=10 :PROCreport
  360   IF Key$="2" Speed%=20 :PROCreport
  370   IF Key$="3" Speed%=40 :PROCreport
  380   IF Key$="4" Speed%=75 :PROCreport
  390   IF Key$="5" Speed%=150 :PROCreport
  400   IF Key$="6" Speed%=300 :PROCreport
  410   IF Key$="7" Speed%=600  :PROCreport
  420   IF Key$="8" Speed%=1000 :PROCreport
  430   IF Key$="9" Speed%=1400 :PROCreport
  440   SYS "Sleep",Speed%
  450   IF Dir$<>"not at all" PROCturn
  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 in ";Mode$;" mode      "
  650 PRINT " and turnig ";Dir$;
  660 IF Dir$<>"not at all" PRINT;" at speed ";S%;"         "
  670 IF Dir$="not at all" PRINT;".                        "
  680 ENDPROC
  690
  700
  710 DEFPROCturn
  720 IF Mode$="FullStep" THEN
  730   IF Dir$="right" Coil%+=1:IF Coil% > 4 Coil% = 1
  740   IF Dir$="left" Coil%-=1:IF Coil% < 1 Coil% = 4
  750   SYS K8055_WriteAllDigital%,Fullstep%(Coil%)
  760 ENDIF
  770
  780 IF Mode$="TwoPhase" THEN
  790   IF Dir$="right" Coil%+=1:IF Coil% > 4 Coil% = 1
  800   IF Dir$="left" Coil%-=1:IF Coil% < 1 Coil% = 4
  810   SYS K8055_WriteAllDigital%,Twophase%(Coil%)
  820 ENDIF
  830
  840 IF Mode$="HalfStep" THEN
  850   IF Dir$="right" Coil%+=1:IF Coil% > 8 Coil% = 1
  860   IF Dir$="left" Coil%-=1:IF Coil% < 1 Coil% = 8
  870   SYS K8055_WriteAllDigital%,Halfstep%(Coil%)
  880 ENDIF
  890
  900 ENDPROC
  910
  920
  930 DEFPROCinit
  940 Dir$="not at all"
  950 Mode$="FullStep"
  960 Speed%=2
  970 Coil%=1
  980
  990 DIM Fullstep%(4)
 1000 Fullstep%(1) = %0001 <<4
 1010 Fullstep%(2) = %0010 <<4
 1020 Fullstep%(3) = %0100 <<4
 1030 Fullstep%(4) = %1000 <<4
 1040
 1050 DIM Twophase%(4)
 1060 Twophase%(1) = %0011 <<4
 1070 Twophase%(2) = %0110 <<4
 1080 Twophase%(3) = %1100 <<4
 1090 Twophase%(4) = %1001 <<4
 1100
 1110 DIM Halfstep%(8)
 1120 Halfstep%(1) = %0001 <<4
 1130 Halfstep%(2) = %0011 <<4
 1140 Halfstep%(3) = %0010 <<4
 1150 Halfstep%(4) = %0110 <<4
 1160 Halfstep%(5) = %0100 <<4
 1170 Halfstep%(6) = %1100 <<4
 1180 Halfstep%(7) = %1000 <<4
 1190 Halfstep%(8) = %1001 <<4
 1200
 1210 SYS K8055_WriteAllDigital%,0
 1220 ENDPROC
 1230
 1240
 1250 DEFPROCwindow(WindowWidth%,WindowHeight%,W$)
 1260 MODE 30
 1270 SYS "SetWindowPos",@hwnd%,0,0,0,WindowWidth%,WindowHeight%,6
 1280 SYS "SetWindowText",@hwnd%,W$
 1290 VDU 26
 1300 COLOUR 15
 1310 *FONT Lucida Console,14,2
 1320 ENDPROC
 1330
 1340
 1350 DEFPROCerror
 1360 PRINT REPORT$;" at line ";ERL
 1370 SYS K8055_ClearAllDigital%
 1380 SYS K8055_ClearAllAnalog%
 1390 SYS K8055_CloseDevice%
 1400 SYS "FreeLibrary",K8055_Board%
 1410 END
 1420 ENDPROC
 1430
 1440
 1450 DEFPROCK8055_init
 1460 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
 1470 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
 1480 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
 1490 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
 1500 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
 1510 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
 1520 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
 1530 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
 1540 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
 1550 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
 1560 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog"  TO K8055_SetAllAnalog%
 1570 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
 1580 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
 1590 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
 1600 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
 1610 SYS"GetProcAddress",K8055_Board%,"SetAllDigital"  TO K8055_SetAllDigital%
 1620 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
 1630 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital"  TO K8055_ReadAllDigital%
 1640 SYS"GetProcAddress",K8055_Board%,"ResetCounter"  TO K8055_ResetCounter%
 1650 SYS"GetProcAddress",K8055_Board%,"ReadCounter"  TO K8055_ReadCounter%
 1660 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime"  TO K8055_SetCounterDebounceTime%
 1670
 1680
 1690 ENDPROC
 1700


Return to interfacing index

Back to the start
Tudor with sign