Get Your Motor Running - Embedded.com

Get Your Motor Running

Step motors are used in many devices and appliances that are part of our everyday lives. Learn some basics to start designing products with them.

Step motors are everywhere. As an embedded developer, you may have already designed a step motor into your projects. If not, you're likely to do so sometime in your career. This article summarizes some important terminology associated with step motors, presents enough information to give you a basic understanding of a step motor's elements, and shows you how to control a stepper using a microcontroller or digital signal processor.

The stepper
A step motor is a type of motor that converts electrical energy to mechanical energy via the principles of electromagnetism. Also known as steppers, such motors were used as early as the 1920s. Their use has skyrocketed with the popularity of embedded systems, including printers, disk drives, toys, windshield wipers, vibrating pagers, robotic arms, and video cameras.

Whenever something is required to move from one position to another (whether the application is industrial, military, medical, automotive, or entertainment), you can bet that a step motor is the driving force. Step motors come in many shapes and sizes, but most fall into one of two categories: the variable reluctance stepper or the permanent magnet stepper. This article focuses on the simpler and more popular permanent magnet stepper.


Figure 1: A stator with two teeth and one winding

Step motor construction
Step motor movement is made possible by wires that are wound around teeth on a stator, the stationary part of a motor, as shown in Figure 1. In general, a wire wound in a coil-like shape is called a solenoid. In a motor, the wire that is wound around the teeth is called a winding, coil, or phase. If current is flowing in the direction shown in Figure 1 and we view the motor from the top looking down at the top of the teeth, the current makes a counterclockwise motion around each of the two teeth. According to Ampere's Law and the right hand rule, this induces a magnetic field with the north pole of the field pointing up.

Now suppose we build a device with two windings on the stationary part. Inside we put a permanent magnet that is free to rotate about its center. The rotating piece is called the rotor.


Figure 2: A two-phase, two-pole motor

The simple motor shown in Figure 2a is called a two-phase, two-pole motor because the stator has two phases (windings), and the rotor has two magnetic poles. If we send current through winding 1 in the direction shown in Figure 2a, with no current through winding 2, the rotor will naturally align itself in the direction shown in Figure 2a, with its south pole pointing in the north direction of the stator's magnetic field.

Now suppose we remove current from winding 1 and instead apply current to winding 2 in the direction shown in Figure 2b. The stator's magnetic field will point to the left, and the rotor will rotate such that its south pole is aligned with the stator's magnetic field.

Next we remove current from winding 2 and apply current to winding 1 in the direction shown in Figure 2c. Note that the current in winding 1 is opposite the current shown in Figure 2a. This will result in a stator field pointing down, so the rotor will rotate to the position where its south pole is pointing down.

Next we remove current from winding 1 and apply current to winding 2 in the direction shown in Figure 2d. This will result in the stator field pointing to the right, so the rotor will rotate to the position where its south pole is pointing to the right.

Finally, we remove current from winding 2 and apply current to winding 1 in the direction shown in Figure 2a, returning the rotor to the original position.

At this point we have completed one cycle of electrical excitation of the motor windings, while the rotor has rotated one complete revolution. In other words, the electrical frequency of the motor is equal to the mechanical frequency of the motor.

If we take one second to sequence through the four steps shown in Figure 2, the electrical frequency is 1Hz. The rotor has rotated once, so the mechanical frequency is also 1Hz. In general, for a two-phase stepper, it can be shown that the relationship between electrical and mechanical frequency is given by the equation:

f e = f m P / 2 (1)

where fe is the electrical frequency, fm is the mechanical frequency, and P is the number of equally-spaced magnetic poles on the rotor.

We also can see from Figure 2 that one step of the motor results in a rotation of 90º . In general, for a two-phase stepper, it can be shown that one step results in a rotation given by the equation:

1 step = 180º / P (2)

This equation says that a two-pole motor will rotate 180º / 2 = 90º per step, which is consistent with what we observe in Figure 2. The equation also shows that a greater number of poles results in better stepping resolution. It is common to find two-phase steppers with anywhere between 12 and 200 poles, which results in a stepping resolution of anywhere between 15º and 0.9º .


Figure 3: A two-phase, six-pole motor

In another example, Figure 3 shows four electrical steps of a two-phase, six-pole motor. As shown in the figure, the rotor consists of three permanent magnets and, therefore, six magnetic poles. In Figure 3a, we apply voltage to stator winding 1 so the stator field has a north pole at the top of the stator. This causes one of the rotor's south poles (the red “S” in Figure 3a) to rotate to the top of the figure. At the next step, in Figure 3b, we apply voltage to stator winding 2 so the stator field has a north pole at the left of the stator. This causes a rotation so that the nearest south pole of the rotor is at the left of the figure; in other words, the rotor moves 30º clockwise. In Figure 3c, we apply voltage to stator winding 1 so the stator field has a north pole at the bottom of the figure. This again causes a 30º clockwise rotation of the rotor to the position shown in Figure 3c. In Figure 3d, we apply voltage to stator winding 2 so the stator field has a north pole at the right of the stator. This results in another 30º clockwise rotation of the rotor to the position shown in Figure 3d. Finally, we again apply voltage to stator winding 1 so the stator field has a north pole at the top of the stator, as shown in Figure 3a. This again causes a 30º clockwise rotation of the rotor and completes one electrical cycle. It can be seen that four electrical steps result in a mechanical rotation of 120º . In other words, the electrical frequency is three times the mechanical frequency, which is consistent with Equation 1. We also observe from Figure 3 and Equation 2 that the rotor rotates 30º in one step.


Figure 4: Exciting both motor windings simultaneously

We can increase the motor torque by sending current through both windings simultaneously. Figure 4 shows this process. The stator's magnetic field is the vector sum of the two individual winding magnetic fields. The stator's magnetic field still rotates in 90º steps, just as it did in Figures 2 and 3, but now the magnetic field is stronger because we are exciting both motor windings simultaneously. Since the stator's magnetic field is the vector sum of two perpendicular fields, the magnetic field increases by a factor of 2 1.414. This results in a proportionally higher torque applied by the motor to its load.

Excitation sequences
Now that we have seen what sequence of excitations will cause a stepper to rotate, we need to put some hardware together to implement the desired stepping sequence. A piece of hardware (or a combination of hardware and software) that causes a motor to run is called a motor drive.

We can see from Figure 4 what sequence of excitations we need to apply to the windings of a two-phase motor in order to cause rotation. The motor leads are labeled 1A, 1B, 2A, and 2B in Figure 4. Leads 1A and 1B are the two leads of winding 1, and leads 2A and 2B are the two leads of winding 2.

For the first step, we need to apply a positive voltage to leads 1B and 2B and ground leads 1A and 2A. For the second step, we need to apply a positive voltage to leads 1B and 2A and ground leads 1A and 2B. (This actually depends on the direction that the leads are wound around the teeth. We will assume that they are wound in the direction that makes the previous statement correct.) Continuing through the other steps, we can summarize the excitation sequence as shown in Table 1, where a “1” means positive voltage and “0” means ground.


Figure 5: An H-bridge circuit can be used to drive each winding

Because current can flow in either direction in each winding lead, this is called a bipolar motor and a bipolar drive sequence. A bipolar motor drive is usually built with a circuit called an H- bridge. The schematic of an H-bridge connected to two leads of a stepper is shown in Figure 5. A constant DC voltage supply (whose magnitude depends on the motor specification) is connected to the H-bridge through a resistor. The circuit is connected through four switches (labeled S1, S2, S3, and S4) to the two leads of a winding. The arrangement of the schematic looks something like a capital letter H, hence the denotation H-bridge.

From Table 1, we see that the first step requires a logic 0 at lead 2A and a logic 1 at lead 2B. We can achieve this by closing switches S1 and S4 and opening S2 and S3. The second step requires a logic 1 at lead 2A and a logic 0 at lead 2B. We can achieve this by closing S2 and S3 and opening S1 and S4. Similarly, the third step is achieved by keeping S2 and S3 closed and S1 and S4 open. The fourth step is achieved by closing S1 and S4 and opening S2 and S3.

A similar line of reasoning can be followed for winding 1. We see that a pair of H-bridges can be used to generate the excitation sequence. This results in a table listing the switch positions for each step as shown in Table 2.

Note that if R = 0 and switches S1 and S3 are inadvertently closed at the same time, the current through the switches will approach infinity. This will burn up the switches and maybe also the power supply, which is why there's a nonzero resistor in the circuit. Although it dissipates power and makes the motor drive less efficient, the resistor provides protection against a short circuit.


Figure 6: A unipolar motor winding

Unipolar motors and drives
So far we've discussed bipolar step motors and drives. A unipolar motor is similar to a bipolar motor except that each winding has a center lead that is accessible from outside the motor, as depicted in Figure 6. We label the lead that comes out the top of the winding lead B, the one that comes out of the bottom of winding is A, and the one that comes from the center of the winding is C.

Sometimes we run across a motor whose leads are not labeled. By knowing how steppers are constructed, we can easily determine which wires are associated with which windings by simply measuring the resistance between the leads. The resistance between leads that belong to different windings will always be infinite. If we measure the resistance between leads A and C as 100 W, then the resistance between B and C will also be 100 W, and the resistance between A and B will be 200 W. In this case, the 200 W resistance of the winding is called the winding resistance.


Figure 7: Circuitry for unipolar motor control

The drive circuitry for a single phase of a unipolar motor is shown in Figure 7. We can see that with S1 closed and S2 open, current will flow from right to left through the motor winding. With S1 open and S2 closed, current will flow from left to right. We can, therefore, change the direction of current flow using only two switches (instead of the four switches needed for the bipolar motor). The sequence of switch positions for a unipolar drive is the sequence shown in Table 3.

Unipolar motor drives are simpler to control. However, unipolar motors are more complicated than bipolar motors because they have center-tapped leads. Unipolar motors are generally more expensive than bipolar motors. Because electrical current is only flowing through half of the motor winding, they also produce only half the magnetic field.

Knowing how unipolar and bipolar motors are constructed enables us to make some inferences when we run across a motor that is not labeled and does not have a data sheet. A motor with four leads is a two-phase bipolar motor. We measure the resistances between pairs of wires to determine which wires belong to the same winding. A motor with six leads is either a two-phase unipolar motor or a three-phase bipolar motor. We can determine the specific type by measuring the resistances between pairs of wires.


Figure 8: Step motor controller schematic

Controlling your motor
The motor control theory discussed earlier in this article can be implemented with a hardware-only solution, a microcontroller, or a DSP. Figure 8 shows how a two-phase unipolar motor can be controlled, using transistors as switches. Each transistor needs to have its base connected to one of the microcontroller's digital outputs. These four connections are made through resistors (in the 1 to 10 MW range) to limit the current to the bases of the transistors. The emitter of each transistor is connected to ground, and the four collectors are connected to the four end leads of the motor windings. The center-tapped motor leads are connected to the positive terminal of the voltage supply.

Each collector is also connected to the voltage supply through a diode, to protect the transistor from the voltage induced in the motor windings during rotation. (Suffice it to say that as the rotor rotates, a voltage is induced in the motor windings. This voltage will pump current into the collectors of the transistors unless we connect the collectors through a diode to the voltage supply.)

Now suppose, for example, that digital output do1 is high and do2 is low. Then the do1 transistor will be on and current will flow from +V through the center-tapped lead, through the base of transistor T1, and out the emitter of T1. However, do2 will be off, so current will not be allowed to flow through T2. Continuing this reasoning, we can rewrite Table 3 to see the desired sequence of microcontroller digital outputs to drive the motor. See Table 4

Now that we know the required hardware and the desired sequence of digital outputs to drive the motor, we can write the software for our favorite microcontroller/DSP to implement the sequence shown.

Firmware control
I implemented the motor controller I just described on a Microchip PIC16F877. I used 1N4003 diodes and 2SD1276A Darlington transistors. I used the PIC's PortA bits 0 to 3 as my digital outputs. I purchased a 5V two-phase unipolar motor from Jameco (manufactured by Airpax [Thomson], part number M82101-P1). I also used the same 5V power supply for both the PIC and the motor. However, for serious applications, I recommend you use separate power supplies for the microcontroller and motor to avoid noise on the microcontroller's power signal.

The assembly source code is shown in Listing 1. This program rotates the motor one step every 50ms. It works by initializing the digital outputs to Step #1 as shown in Table 4. Then, every 50ms (as specified by the WaitTime constant), the program cycles through the digital outputs shown in the correct order. To reverse the direction of the motor rotation, simply cycle through the digital outputs in the opposite order.

Listing 1: PIC16F877 assembly code for two-phase unipolar motor control

Listing 1 PIC16F877 assembly code for two-phase unipolar motor control

; Declare variablescblock  0x20	Count1	; Delay counter	Count2	; Delay counterendc; Declare constantsWaitTime	equ	d'50'	; Wait 50 msec between stepsPosition1	equ	b'1010'	; digital output values for 1st stepPosition2	equ	b'1001'	; digital output values for 2nd stepPosition3	equ	b'0101'	; digital output values for 3rd stepPosition4	equ	b'0110'	; digital output values for 4th step;****************  Program Start  ***********************	org 	0	; Reset Vector	nop		; nop for Microchip's In-Circuit Debugger (ICD);****************  Initialization  *********************	banksel	TRISA	movlw	0xC0	movwf	TRISA	; Set Port A bits 0-3 to be all outputs	movlw	b'00000110'	; Configure the Port A bits as digital	movwf	ADCON1	banksel	PORTA	; Back to bank 0	clrf	Count1	; Clear counter	clrf	Count2	; Clear counter	movlw	Position1	; Start the motor in Position 1	movwf	PORTA;********************  Motor drive  *********************Drive	movlw	WaitTime	; Initialize WaitTime to Count1	movwf	Count1Loop	call	Timer	; Wait 1 msec	decfsz	Count1, f	; Decrement Count1. Count1 = 0 ?	goto	Loop	; No - keep waiting	movf	PORTA, w	; Read the present position	sublw	Position1	bnz 	Drive1	movlw	Position2	; Presently in Position1 - step to Position2	movwf	PORTA 	goto	Drive	; Step againDrive1	movf	PORTA, w	; Read the present position	sublw	Position4	bnz 	Drive2	movlw	Position1	; Presently in Position4 - step to Position1	movwf	PORTA	goto	Drive	; Step againDrive2	movf	PORTA, w	; Read the present position	sublw	Position3	bnz	Drive3	movlw	Position4	; Presently in Position3 - step to Position4	movwf	PORTA	goto	Drive	; Step againDrive3	movf	PORTA, w	; Read the present position	sublw	Position2	bnz	Drive4	movlw	Position3	; Presently in Position2 - step to Position3	movwf	PORTA	goto	Drive	; Step againDrive4	movlw	Position1	; Presently in unknown position - step to Position1	movwf	PORTA	; Write PORTA	goto	Drive	; Step again;*************  1 msec Delay Subroutine  *****************; This routine takes 1 msec to execute (at clock speed is 4 MHz)Timer	movlw	d'200'	; Set loop count	movwf	Count2	; Save loop countTime1	nop	nop	decfsz	Count2, f	; Count2 - 1 = 0 ?	goto	Time1	; No - Continue	return		; Yes - Return

end

The motor I used was a 24-pole motor. That means that one step moves the motor 180º / 24 = 7.5º . The motor rotates 7.5º every 50ms, which works out to 1 rotation every 2.4 seconds. If we decrease the WaitTime constant by a factor of two, the motor will rotate twice as fast. However, there is a limit to the rotational velocity of the motor. If the stator field rotates too fast, the rotor will not be able to keep up (due to its inertia, friction, and other mechanical limitations). At that point the motor will start skipping —and will not rotate synchronously with the stator field. If the WaitTime constant is decreased further, the motor may actually stop rotating altogether.

Other motor typesStep motors can come with three or four phases, in addition to the two-phase variety that we have focused on in this article. Some two-phase steppers have a single center-tapped lead that is connected to the center of both windings. These types of steppers have five leads coming out of the motor.

There are also types of motors other than steppers. The oldest and simplest motor is the direct current (DC) motor. However, it uses brushes and, therefore, is not as prevalent as it used to be. Brushless DC motors are DC motors that use electronic circuitry instead of brushes for commutation. Since there are no brushes to wear out, brushless DC motors have much longer life spans than brush DC motors.

An induction motor works on a completely different principle than steppers or DC motors. The supply voltage of an induction motor is AC rather than DC, and the speed of the rotor lags the speed of the stator's magnetic field. Steppers and DC motors are synchronous because the rotor rotates synchronously with the stator's magnetic field, but induction motors are not synchronous because of the rotor speed lag relative to the rotating magnetic field.

Happy motoring
This article has presented an overview of stepper motors. Many more details and subtleties than those covered here await your discovery. However, if you understand the principles discussed here, you're well positioned to begin designing, maintaining, and debugging stepper drive hardware and software. esp

Dan Simon is a professor in the electrical and computer engineering department at Cleveland State University and an industry consultant. He teaches an embedded systems class using the Microchip PIC and is researching new motor control techniques using an Analog Devices DSP. Contact him at .

For further reading
Seiichi Inoue's website: Microchip PIC information and projects, including a step motor controller and a dc motor controller.
http://hobby_elec.piclist.com/e_menu.htm

Douglas Jones's website: Information about step motors, including animations, tutorials, and links.
www.cs.uiowa.edu/~jones/step/

Innovatia Laboratory's website: a four-part motor control tutorial in addition to more advanced material.
www.innovatia.com/Design_Center/Power_Electronics.htm

Benson, David. Easy Step'n. Kelseyville, California: Square 1 Electronics, 2001.
A website devoted to the book and related material can be found at www.stepperstuff.com/.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.