Driving a bi-polar stepper motor with the

SN754410NE double H-bridge


The bipolar setupBi-polar stepping motors use only two coils and are easily recognized because they only have four wires. Most unipolar steppers can be used in bipolar mode by ignoring the two centre taps. Because bi-polar stepping motors produce the rotating magnetic field by reversing the current in both coils, controlling them is much more complicated than controlling their unipolar cousins.            

My circuit makes use of a SN754419 dual h-bridge chip, which takes all the hard work out of designing an interfacing circuit. As can be seen in the circuit diagram below, my circuit merely connects the chip to the relevant terminals. In fact, the board is so bare that I added a power on LED out of pure embarrassment. I run my motor at 5V. If you use a motor with a higher voltage, you have to split the supply via the link and provide a 5V logic supply via a tap from the Velleman board. The motor supply will then be connected to pin 9 and the logic positive to pin 8.

Below is a suggested PCB layout at 2*magnification. Notice that the four centre earth pins also serve as a heat sink. This of course explains the large copper area.

 

The circuit diagram

the PCB layout
 

My program drives the motor in both directions at nine different speeds. It allows both half step and full step mode.


Below is a link to a zip archive with the BBC Basic file and also a self-executing file which allows you to try the program whether you have BBC BASIC for Windows or not.


K8055_bi-polar_stepper_1_0.zip


Here are the same two files for the K8061


K8061_bi-polar_stepper_1_0.zip



   10 REM Bi-polar stepper driver
   20 REM For The Velleman K8055N USB interface
   30 REM Jochen Lueg
   40 REM http://roevalley.com/newsbrowser/v-projects/v-index.htm
   50 REM Limavady, May 2012
   60 REM Version 1.0
   70
   80 ON ERROR PRINT ERL;"  ";REPORT$:END
   90 PROCK8055_init
  100 PROCinit
  110 PROCwindow(600,400,"Bi-polar stepper driver")
  120 OFF
  130 ON ERROR PROCerror
  140 SYS K8055_CloseDevice%
  150 SYS K8055_OpenDevice%,0
  160 SYS K8055_WriteAllDigital%,%11110000
  170 ON CLOSE PROCclose
  180 PRINT
  190 PRINT " Motor controls"
  200 PRINT
  210 PRINT " Left       . . . . . .  Z"
  220 PRINT " Right      . . . . . .  C"
  230 PRINT " Stop       . . . . . .  X"
  240 PRINT " Full step  . . . . . .  F"
  250 PRINT " Half step  . . . . . .  H"
  260 PRINT
  270 PRINT " Fastest    . . . . . .  1"
  280 PRINT " to"
  290 PRINT " Slowest    . . . . . .  9"
  300 PRINT
  310 PRINT " Press 'Q' to leave the program"
  320
  330 REPEAT
  340   Key$=INKEY$(0) : REPEAT UNTIL INKEY(0)=-1
  350   IF Key$="c" OR Key$="C" Direction$="Right"
  360   IF Key$="z" OR Key$="Z" Direction$="Left"
  370   IF Key$="q" OR Key$="Q" Direction$="Finished"
  380   IF Key$="x" OR Key$="X" Direction$="Stop"
  390   IF Key$="h" OR Key$="H" Mode$="Half"
  400   IF Key$="f" OR Key$="F" Mode$="Full"
  410   IF Key$="1" T%=150*S%    :Speed$="Fast"
  420   IF Key$="2" T%=200*S%    :Speed$="Fast-1"
  430   IF Key$="3" T%=300*S%   :Speed$="Fast-2"
  440   IF Key$="4" T%=625*S%   :Speed$="Fast-3"
  450   IF Key$="5" T%=1250*S%   :Speed$="Half"
  460   IF Key$="6" T%=2500*S%  :Speed$="Slow+3"
  470   IF Key$="7" T%=5000*S%  :Speed$="Slow+2"
  480   IF Key$="8" T%=10000*S%  :Speed$="Slow+1"
  490   IF Key$="9" T%=20000*S%  :Speed$="Slow"
  500   IF Direction$="Right" AND Mode$="Full" THEN PROCfull_step_right
  510   IF Direction$="Right" AND Mode$="Half" THEN PROChalf_step_right
  520   IF Direction$="Left" AND Mode$="Full"  THEN PROCfull_step_left
  530   IF Direction$="Left" AND Mode$="Half"  THEN PROChalf_step_left
  540   IF Direction$="Stop" PRINTTAB(1,18)"Motor stopped                                 "
  550   IF Direction$="Stop" SYS K8055_ClearAllDigital%:Direction$="Wait"
  560   IF Direction$ <> "Wait" PRINTTAB(1,18);Mode$;" step. Turning ";Direction$;" with speed ";Speed$;"   "
  570 UNTIL Direction$="Finished"
  580 PROCclose
  590 END
  600
  610
  620
  630 DEFPROCfull_step_right
  640 FOR J%=1 TO 4
  650   SYS K8055_WriteAllDigital%,FullStep%(J%): FOR I%=1 TO T%:NEXT
  660 NEXT
  670 ENDPROC
  680
  690
  700 DEFPROCfull_step_left
  710 FOR J%=4 TO 1 STEP -1
  720   SYS K8055_WriteAllDigital%,FullStep%(J%): FOR I%=1 TO T%:NEXT
  730 NEXT
  740 ENDPROC
  750
  760
  770 DEFPROChalf_step_right
  780 FOR J%=1 TO 8
  790   SYS K8055_WriteAllDigital%,HalfStep%(J%): FOR I%=1 TO T%:NEXT
  800 NEXT
  810 ENDPROC
  820
  830
  840 DEFPROChalf_step_left
  850 FOR J%=8 TO 1 STEP -1
  860   SYS K8055_WriteAllDigital%,HalfStep%(J%): FOR I%=1 TO T%:NEXT
  870 NEXT
  880 ENDPROC
  890
  900
  910 DEFPROCinit
  920 W%=0
  930 Direction$="Stop"
  940 S%=800
  950 T%=S%*35
  960 Speed$="Fast"
  970 Mode$="Full"
  980
  990
 1000 DIM FullStep%(4)
 1010 FullStep%(1)=%1000 <<4
 1020 FullStep%(2)=%0010 <<4
 1030 FullStep%(3)=%0100 <<4
 1040 FullStep%(4)=%0001 <<4
 1050
 1060 DIM HalfStep%(8)
 1070 HalfStep%(8)= %1010 <<4
 1080 HalfStep%(7)= %1000 <<4
 1090 HalfStep%(6)= %1001 <<4
 1100 HalfStep%(5)= %0001 <<4
 1110 HalfStep%(4)= %0101 <<4
 1120 HalfStep%(3)= %0100 <<4
 1130 HalfStep%(2)= %0110 <<4
 1140 HalfStep%(1)= %0010 <<4
 1150
 1160 ENDPROC
 1170
 1180
 1190 DEFPROCerror
 1200 PRINT REPORT$;" at line ";ERL  :
 1210 SYS K8055_ClearAllDigital%
 1220 SYS K8055_CloseDevice%
 1230 SYS "FreeLibrary",K8055_Board%
 1240 END
 1250 ENDPROC
 1260
 1270
 1280 DEFPROCclose
 1290 SYS K8055_ClearAllDigital%
 1300 SYS K8055_CloseDevice%
 1310 SYS "FreeLibrary",K8055_Board%
 1320 QUIT
 1330 ENDPROC
 1340
 1350
 1360 DEFPROCwindow(WindowWidth%,WindowHeight%,Wt$)
 1370 MODE 30
 1380 SYS "SetWindowPos",@hwnd%,0,0,0,WindowWidth%,WindowHeight%,6
 1390 COLOUR 128
 1400 CLS
 1410 COLOUR 15
 1420 VDU 26
 1430 SYS "SetWindowText",@hwnd%,Wt$
 1440 *FONT Lucida Console,14,2
 1450 ENDPROC
 1460
 1470
 1480
 1490 DEFPROCK8055_init
 1500 REM  Typing errors in routine name do not generate an error message - they just hang up the program.
 1510 REM These are all the system calls in the order found in the manual
 1520 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
 1530 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
 1540 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
 1550 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
 1560 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
 1570 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
 1580 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
 1590 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
 1600 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
 1610 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
 1620 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog"  TO K8055_SetAllAnalog%
 1630 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
 1640 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
 1650 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
 1660 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
 1670 SYS"GetProcAddress",K8055_Board%,"SetAllDigital"  TO K8055_SetAllDigital%
 1680 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
 1690 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital"  TO K8055_ReadAllDigital%
 1700 SYS"GetProcAddress",K8055_Board%,"ResetCounter"  TO K8055_ResetCounter%
 1710 SYS"GetProcAddress",K8055_Board%,"ReadCounter"  TO K8055_ReadCounter%
 1720 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime"  TO K8055_SetCounterDebounceTime%
 1730 ENDPROC



Return to interfacing index

Back to the start
Tudor with sign