U tepper Motors ugust 22, 2017 tepper Motors in Unipolar (5 lead) stepper motorr. $1.95 from www.mpja.com 100 steps per rotation. 24V / 160m / 600 gm cm holding torque @ 160m stepper motor is a digital motor with two phases and 4, 5, or 6 leads. These leads connect to two sets of electromagets. The main difference is the addition of a center tap for the two electromagnets: black black white 4-Lead (bipolar) 5-Lead (unipolar) 6-Lead (unipolar) 4-lead stepper motors are typically higher power (higher torque) and require an H-bridge to operate. 5-lead and 6-lead motors are easier to interface to a microprocessor but only use half of the winding, resulting in less torque. With a 5-lead stepper motor, the center taps are shorted together, resulting in essentailly four separate electromagnets: red 134 Ohms 134 Ohms white black 134 Ohms green 134 Ohms brown To make the motor spin, there are several options. page 1
U tepper Motors ugust 22, 2017 ase 1: 5V Operation The stepper motor in your kits is rated at +24V. It will operate at 5V as well, just without as much holding torque. Each phase has a resistance of 134 Ohms to the center tap (ground in this case), resulting in the stepper motor drawing 37m. This is a little more than the 25m rated for the PI, but there's always some engineering tolerance. Just don't run it too long. If you connect your PI to the stepper motor as follows: R7 R6 R5 R4 R3 R2 R1 R0 - - - - - - - - white brown green red with the center tap (black) tied to ground, you can make the motor spin by energizing each coil sequentially: 5V 5V 5V 5V 5V ote that when is energized, current flows the opposite direction as when is energized. This results in the electromagnet attracting the north or sourth poles of the rotor magnet respectively. To make the motor spin, output the following sequence to PORT (termed full stepping) : 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 repeat Each step causes the motor to rotate 3.6 degrees, giving the motor 100 steps per rotation. You can also do half-steps. This increases the resolution of a stepper motor by a factor of two or 200 steps per rotation for the motor in your lab kits 0 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 0 1 repeat page 2
U tepper Motors ugust 22, 2017 ase 2: 5V.. 24V Operation Unipolar tepper Motor (0 to 4) The stepper motor in your kit is rated at +24V. To get more voltage to your stepper motor, onnect the center tap (black) to your power supply. +12V is used in this example. onnect each phase to ground using a transistor. +12V a0 a1 a2 300 300 a0 a1 a2 +12V b1 b0 300 b0 b1 b2 300 b2 Each transistor acts as a switch. When the PI applies +5V to, transistor Qa saturates, allowing current to flow. The current you're allowing is I c = 12V 134Ω = 89.6m ssuming a 3906 P transistor with a gain of 100, to saturate the transistor you need at least 0.89m I b > I c β = 0.896m The base resistor can then be anything less than 4948 Ohms R b < 5V 0.7V = 4948Ω 0.869m. The lower limit on Rb is 25m: the maximum current a PI can output R b > 5V 0.7V 25m = 172Ω 300 Ohms is an overkill, but it works. The nice thing about this design is It works for any voltage: you can connect the center tap to +5V, +12V, +24V, or whatever the stepper motor needs. It works for currents up to 200m for 3904 transistors (4 cents each) or 4 for Zetex 1049 transistors (78 cents each). The problem is you lose some torque: by using the center tap you're only using half of each electromagnet. page 3
U tepper Motors ugust 22, 2017 ase 3: 5V to 12V Operation, <800m ($0.99 solution) third option is to use a stepper motor driver chip from ebay H-ridge river from ebay. ote that the limits are +12V, +800m. This is essentially a dual H-bridge and works best for 4 and 6 lead stepper motors. It sort of works for 5-lead stepper motors as well. 1-1- Motor 1 Motor 2 Motor 1-2 5V +Vcc +Vcc 5V +Vcc -Vcc 5V 5V +Vcc +Vcc If you connect the center tap (black) to ground, you can drive the stepper motor as before with R2 R0 +5V R4 R1 PI oard 1 1 Vcc g 1 1 L9110 oard Motor Motor re br gr wh tepper Motor bk onnections for the L9110 H-ridge tepper Motor river board with a 5-lead stepper motor. page 4
U tepper Motors ugust 22, 2017 Input Output 1-1- 1-1- Motor 1 Motor 2 Motor 1 Motor 2 R0 R2 R1 R3 (red) (br) (gr) (wh) enter Tap (black) tied to ground If you need more than 800m, you need a different (and more expensive) H-bridge. For example, $1.99 will get you a stepper motor driver capable of 2 and +35V. Hmmm. We might get these for next year. Regardless, the interface is the same. If you need more power, Jameco (and ebay and Marlin P Jones) has nice stepper motors. For example, one of their larger stepper motors has the following specs: EM 34 stepper motor from www.jameco.com. Part number 237631 6.3V, 1.5 operation 14,276 gm - cm holding torque (24 time the holding torque) 2.43 pounds $39.95 each (20 times more expensive) page 5
U tepper Motors ugust 22, 2017 ample ode: ase 1: Full-tepping Every 500ms ( tepper1. ) simple way to walk through the 1/0 pattern is to use a table. The following program cycles through the table with each step taking 100ms // tepper1. // rive a stepper motor at 100ms/step // Global Variables const unsigned char MG[16] = "tepper1. "; unsigned char TLE[4] = {1, 2, 4, 8; while(1) { TEP = TEP + 1; PORT = TLE[TEP % 4]; L_Move(1,0); L_Out(TEP,0); Wait_ms(100); On PORT, you should see the following bit pattern with it changing every 100ms. R3 R2 R1 R0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 (repeat) If you want to step the other way, simple decrement TEP every 100ms. If you want to step faster, change the wait() function. page 6
U tepper Motors ugust 22, 2017 ase 2: tep using Timer2 interrupts. (tepper2.) Problem: tep the motor every 100ms. If you want more precise timing with the stepping, you can step using interrupts. First, set up Timer2 for 1ms (10,000 clocks), = 10 = 250 = 4 ext, inside the interrupt routine, step the motor every 100th interrupt (100ms). // Global Variables unsigned char TLE[4] = {1, 2, 4, 8; int TEP, TIME, ; // High-priority service void interrupt Interve(void) { if (TMR2IF) { TIME = TIME + 1; = ( + 1) % 100; if ( == 0) { TEP = TEP + 1; PORT = TLE[TEP % 4]; TMR2IF = 0; Turn on Timer2 interrupts for 1ms // initialize Timer2 T2O = 0x4; PR2 = 249; TMR2O = 1; TMR2IE = 1; PEIE = 1; ince everything is done inside the interrupt, the main routine is free to do whatever you like - such as display the present angle of the motor: while(1) { L_Move(1,0); L_Move(1,8); L_Out(TIME,3); L_Out(TEP,0); page 7
U tepper Motors ugust 22, 2017 ase 3: djust the speed the stepper motor steps using push buttons: (tepper3.) R4: Forward, 30ms / step R3: Forward, 100ms / step R2: top R1: Reverse, 100ms / step R0: Reverse, 30ms / step hange the hard numbers in the previous code to variables, which are changed based upon the button you press: // Global Variables unsigned char TLE[4] = {1, 2, 4, 8; int TEP, TIME; int IR, PEE; // High-priority service void interrupt Interve(void) { if (TMR2IF) { TIME = TIME + 1; if (R4) { IR = 1; PEE = 30; if (R3) { IR = 1; PEE = 100; if (R2) { IR = 0; PEE = 100; if (R1) { IR =-1; PEE = 100; if (R0) { IR =-1; PEE = 30; = ( + 1) % PEE; if ( == 0) { TEP = TEP + IR; PORT = TLE[TEP % 4]; TMR2IF = 0; page 8
U tepper Motors ugust 22, 2017 ase 4: Position ontrol via push buttons (tepper4.) Have the stepper motor go to the following positions based upon which button is pressed: R4: 100 steps (360 degrees) R3: 75 steps (270 degrees) R2: 50 steps (180 degrees) R1: 25 steps (90 degrees) R0: 0 steps (0 degrees) Move the stepper motor at a speed of 10ms/step. To do this, define two new global variables: int TEP; int REF; // the present position of the stepper motor // the desired position hange the Timer2 interrupt as follows: // High-priority service void interrupt Interve(void) { if (TMR2IF) { if (R4) REF = 100; if (R3) REF = 75; if (R2) REF = 50; if (R1) REF = 25; if (R0) REF = 0; TIME = (TIME + 1) % 10; if (TIME == 0) { if (TEP < REF) TEP += 1; if (TEP > REF) TEP -= 1; PORT = TLE[TEP % 4]; TMR0IF = 0; The interrupts do all the work. In the main routine, you can watch what's happening with: while(1) { L_Move(0,0); L_Move(0,8); L_Move(1,8); L_Out(TIME,3); L_Out(REF,0); L_Out(TEP,0); page 9
U tepper Motors ugust 22, 2017 Microstepping: stepper motor is actually an synchronous machine: If you send a square wave to the motor, it jumps from one angle to another: it is operating as a stepper motor. For the motor above, it has 100 steps per rotation. If you send a sine wave to the motor, it smoothly moves from one angle to another: it is operating as an synchronous machine. For the motor above, it rotates once per 25 cycles: 100 steps revolution 1cycle 4steps = 25 cycles revolution If you apply a 60Hz sine wave to the above motor (sine on phase, cosine on phase ), it will spin at 60 cycle sec 1 revolution 25 cycles = 2.4 rps = 144 rpm For example, if you look at the voltage applied to phase, when using full stepping the voltage V looks like the blue line in the following figure (shown for two cycles): 1 0 0 0 V = 1 0 1 0 0 V = 0 0 0 1 0 V = -1 0 0 0 1 V = 0 repeat If you use a sine wave instead, you'll be able to position the motor inbetween steps. This is shown in the red line below: ignal sent to V when using full steps (blue line) or microstepping (red line). V would be 90 degrees out of phase (cosine vs. sine). page 10