|
Using a Unipolar Stepper Motor with a Microcontrollerby Lewis Loflin Here we will examine the basic operation of a unipolar stepper motor. I'll cover a bipolar stepper motor on a different page. A unipolar stepper motor has two windings per phase, one for each direction of magnetic field. Since in this arrangement a magnetic pole can be reversed without switching the direction of current, the commutation circuit can be made very simple (eg. a single transistor) for each winding. Typically, given a phase, one end of each winding is made common: giving three leads per phase and six leads for a typical two phase motor. Often, these two phase commons are internally joined, so the motor has only five leads. Others can have six leads. A microcontroller or stepper motor controller can be used to activate the drive transistors in the right order, and this ease of operation makes unipolar motors popular with hobbyists. They are probably the cheapest way to get precise angular movements. Bipolar motor: Bipolar motors have a single winding per phase. The current in a winding needs to be reversed in order to reverse a magnetic pole, so the driving circuit must be more complicated, typically with an H-bridge arrangement. There are two leads per phase, none are common. Stepper motors consist of a permanent magnet rotating shaft, called the rotor, and electromagnets on the stationary portion that surrounds the motor, called the stator. Controlling the sequence will cause the rotor to move. The electromagnets are energized by an external control circuit, such as a microcontroller.
/* Program 1 Stepper motor demo for pf35t-48 and 55mod48 and Airpax This particular stepper motor is 7.5 degrees per step so it requires 48 steps for 360 degrees. Another motor this circuit/program was tested on was a Teac motor removed from a 5.25 inch floppy drive. At 1.8 degrees per step it required 200 steps for 360 degrees. All wire colors were brown. Depending on the type motor swap the four numbers below (8 - 11) until motor works. The sequence below was derived at by experimentation. Speed is controlled by a delay between each step. The longer the delay the slower the rotation. That delay value is obtained by reading and analog-to-digital cover (AD0 in this case) which gives a value from 0 to 1023. See diagram below. The value is divided by 4 and add 10 for a delay in milliseconds: delay(analogRead(0)/4 +10) For faster speeds change 10 to say 2. This is calculated between every step to vary speed while stepping. The commands below will be compiled into machine code and uploaded to the microcontroller. Compiled size 1896 bytes. */ #define yellow 8 //Q1 #define orange 9 //Q2 #define brown 10 // Q3 #define black 11 // Q4 #define CW 3 // SW0 in schematic #define CCW 4 //SW1 in schematic void setup() { pinMode(CW, INPUT); pinMode(CCW, INPUT); digitalWrite(CW, 1); // pull up on digitalWrite(CCW,1); // pull up on pinMode(black, OUTPUT); pinMode(brown, OUTPUT); pinMode(orange, OUTPUT); pinMode(yellow, OUTPUT); // all coils off digitalWrite(black, 0); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 0); } void loop() { if (!digitalRead(CW)) { forward(200); all_coils_off(); } if (!digitalRead(CCW)) { reverse(200); all_coils_off(); } } // end loop void all_coils_off(void) { digitalWrite(black, 0); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 0); } void reverse(int i) { while (1) { digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(analogRead(0)/4 + 10); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(analogRead(0)/4 + 10); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(analogRead(0)/4 + 10); i--; if (i < 1) break; digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(analogRead(0)/4 +10); i--; if (i < 1) break; } } void forward(int i) { while (1) { digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(analogRead(0)/4 +10); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(analogRead(0)/4 +10); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(analogRead(0)/4 +10); i--; if (i < 1) break; digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(analogRead(0)/4 +10); i--; if (i < 1) break; } }
/* Program 2 This program works much the way program 1 does. In this case we send the delay time between steps to the subroutine and not read the analog in every time. Thus we can program an unlimited combinations for speed, steps, and direction. Stepper motor demo for pf35t-48 and 55mod48 and Airpax This particular stepper motor is 7.5 degrees per step so it requires 48 steps for 360 degrees. Another motor this circuit/program was tested on was a Teac motor removed from a 5.25 inch floppy drive. At 1.8 degrees per step it required 200 steps for 360 degrees. All wire colors were brown. Compiled size 1756 bytes. */ #define black 8 // Q1 #define brown 9 // Q2 #define orange 10 //Q3 #define yellow 11 //Q4 #define CW 3 // SW0 in schematic #define CCW 4 // SW2 in schematic void setup() { pinMode(black, OUTPUT); pinMode(brown, OUTPUT); pinMode(orange, OUTPUT); pinMode(yellow, OUTPUT); pinMode(CW, INPUT); pinMode(CCW, INPUT); digitalWrite(CW, 1); // pull up on digitalWrite(CCW,1); // pull up on digitalWrite(black, 0); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 0); } void loop() { if (!digitalRead(CW)) { // this will speed up forward(200, 50); reverse(200, 40); forward(200, 30); reverse(200, 20); forward(200, 10); reverse(200, 5); all_coils_off(); } if (!digitalRead(CCW)) { // random reverse(28, 100); forward(100, 50); reverse(200, 5); reverse(75, 150); forward(50, 50); reverse(125, 20); all_coils_off(); } } // end loop void all_coils_off(void) { digitalWrite(black, 0); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 0); } void reverse(int i, int j) { while (1) { digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(j); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(j); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(j); i--; if (i < 1) break; digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(j); i--; if (i < 1) break; } } void forward(int i, int j) { while (1) { digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(j); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 0); digitalWrite(yellow, 1); delay(j); i--; if (i < 1) break; digitalWrite(black, 0); digitalWrite(brown, 1); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(j); i--; if (i < 1) break; digitalWrite(black, 1); digitalWrite(brown, 0); digitalWrite(orange, 1); digitalWrite(yellow, 0); delay(j); i--; if (i < 1) break; } } You Tube Arduino Microcontroller Video Series March 2012:
Arduino demos:
» About me » Bristol VA/TN » E-Mail » Hobby Electronics » Arduino Microcontroller
General Electronics
Added January 2012: PICAXE Micro-controller Projects!The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.
|