PH-315 MICROCONTROLLERS Stepper motor control with Sequential Logic Circuits Portland State University Summary Four sequential digital waveforms are used to control a stepper motor. The main objective of this laboratory session is to illustrate how pulse width modulation helps to implement the sequential logic effectively. 1. Introduction In sequential logic, the outputs of the block depend on both i) the input and ii) the memory of the block. The sequential logic has some kind of memory or feedback capability. In the previous labs we have attained familiarity implementing combinational logic using arrays. In this lab, you will see how sequential logic can be implemented with a sequence of pulses. When operating a stepper motor, the control signals are the input and the stepper motor s positions are the output. The motor always turns from the current position to the next position, so the motor has some kind of memory of its position in the previous step. Figure 1. General platform to implement a sequential-logic circuit. 2. Stepper motor A stepper motor is an electromechanical device that converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses: The sequence of the applied pulses is directly related to the direction of motor shafts rotation; the speed of the motor shafts rotation is directly related to the frequency of the input pulses; and the length of rotation is directly related to the number of input pulses applied. Advantages of stepper motors 1. The rotation angle of the motor is proportional to the number of input pulses. 2. The motor is able to apply a large torque at the beginning of the pulse, which provides excellent response to starting/stopping/reversing.
3. Because the rotor moves towards already fixed poles, it provides precise positioning and repeatability of movement (error is not accumulative!). One can find stepper motors with 1% position accuracy (even at low price). 4. Very reliable since there are no contact brushes in the motor. 5. A stepper motor has the ability to be accurately controlled with open loop strategies. The latter implies that no feedback information (from precedent rotor position) is needed; that is, each step is implemented independent of what happened in the past. This type of control eliminates the need for expensive sensing and feedback-control devices such as optical encoders. The position is known simply by keeping track of the input step pulses. Disadvantages of stepper motors 1. Resonances can occur if not properly controlled. 2. Not easy to operate at extremely high speeds. Types of Stepper Motors There are three basic types of stepper motors: Variable-reluctance Permanent-magnet Hybrid Variable-reluctance (VR). This type of stepper motor has been around for a long time. It is probably the easiest to understand from a structural point of view. Figure 2 shows a cross section, consisting of a soft iron multi-toothed rotor and a wound stator. When the stator windings are energized with DC current the poles become magnetized. Rotation occurs when the rotor teeth are attracted to the energized stator poles. Figure 2. Cross-section of a variable reluctance (VR) motor.
Permanent Magnet (PM). See in fig 3. The permanent magnet step motor is a low cost and low resolution type motor with typical step angles in the range of 7.5 to 15. (48 24 steps/revolution). PM motors have permanent magnets added to the motor structure. The rotor no longer has teeth as with the VR motor. Instead the rotor is magnetized with alternating north and south poles situated in a straight line parallel to the rotor shaft. These magnetized rotor poles provide an increased magnetic flux intensity and because of this the PM motor exhibits improved torque characteristics when compared with the VR type. N S N S S N S Figure 3. Principle of a PM stepper motor. Hybrid (HB). The hybrid stepper motor is more expensive than the PM stepper motor but provides better performance with respect to step resolution, torque and speed. Typical step angles for the HB stepper motor range from 3.6 to 0.9 (100 400 steps per revolution). The hybrid stepper motor combines the best features of both the PM and VR type stepper motors. The rotor is multi-toothed like the VR motor and contains an axially magnetized concentric magnet around its shaft. The teeth on the rotor provide an even better path which helps guide the magnetic flux to preferred locations in the airgap. This further increases the detent, holding and dynamic torque characteristics of the motor when compared with both the VR and PM types. Figure 4. Cross-section of a hybrid stepper motor.
When to Use a Stepper Motor A stepper motor can be a good choice whenever controlled movement is required. They can be used to advantage in applications where controlled rotation angle, speed, position and synchronism is needed. Some applications include printers, plotters, high end office equipment, hard disk drives, medical equipment, fax machines, automotive and many more. Drive the motor with a rotating magnetic field When a phase winding of a stepper motor is energized with current, a magnetic flux is developed in the stator. Figure 5 shows the motor rotating clockwise as its pole aligns with the sequentially activated stator poles. To get the motor to rotate we can now see that we must provide a sequence of energizing the stator windings in such a fashion that provides a rotating magnetic flux field which the rotor follows due to magnetic attraction. Figure 5. Bipolar wound stepper motors. The figure shows the individual stators that are sequentially turned ON, while keeping the others OFF. 3. Experimental procedure 3.A LEDs lighted up in sequence. First, we are going to generate sequences of pulses to light up four LEDs. Connect four LEDs to the digital ports D4 D7, like the one shown in the circuit below. TASK: Make a program to light up the four LEDS sequentially; i.e. put LED j in HIGH while keeping all the others in LOW, repeating the process from j=1 to j=4. Take good care of the timing.
Figure 6. Bipolar wound stepper motors. The waveform of the output should look similar to the pattern shown in Fig. 7. Figure 7. Waveform of the outputs (for the circuit of Fig. 6). To help us elaborate the code for implementing the waveform digitally and in a sequential way, we have highlighted in green color one period of the waveform. 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 In the program we will take this matrix information row by row to write the pins. Run the program suggested in Fig. 8 void setup() { for(int i=4; i<=7; i++) pinmode(i, OUTPUT); void loop()
{for (char i=4; i<=7; i++) digitalwrite( i, HIGH), delay(300), digitalwrite( i, LOW); // Notice the i-th waveform is implemented // row by row, according to the matrix below // Fig. 7, and in a PWM format // to increase the sequence speed, decrease the delay time Figure 8. Implementation of sequential logic via PWM. Notice, PWM is implemented in all the four pins, which helps to implement sequential logic effectively. The program in Fig. 8 is short because it capitalizes on using positive and negative logic in the same line (highlighted in light orange color). Otherwise the program may result in being much longer. TASK: Write your own program (alternative to the one in Fig. 8) to generate the same waveform of figure 7. (Some former students used up to 20 lines; hence no worries if your program is too long). Reverse the process implemented above; i. e. in sequence light up LED4 to LED1. Repeat this process and draw the wave form of the outputs. 3.B Connecting the terminals to the stepper motor Upon finishing 3A and 3B successfully, you will have learned the essentials in digitally controlling a stepper motor. In next steps you will see why. 3.B.1 Remove the LEDs and hook up D4 D7 with the ABCD phases of the stepper motor driver board. Connect the 5V power supply and GND to the board. You will see that the stepper motor is running! Figure 9. Connection between the Arduino board and stepper motor.
3.B.2 Change the speed and direction of the stepper motor, by changing the delay time. 3.C Alternative method to drive the stepper motor The objective is to output the control sequence shown below to the stepper motor. Figure 10. Alternative wave form (compared to Fig. 7) for full step driving. TASK: Using an analytical analysis, indicate whether or not the waveforms in Fig. 7 and Fig. 10 have a different net effect in driving the stepper motor. If the answer were no, a follow up question would be: why to bother then in designing the new waveforms in Fig. 10. If the answer were yes, indicate the main difference(s). 3D. Advanced driving of a 4 phase stepper motor. Half Step Drive. In Half Step Drive, the stator is energized according to the sequence AB B AB A AB B AB A and the rotor steps from position 1 2 3 4 5 6 7 8. This results in angular movements that are half of those in 1- or 2-phases-on drive modes. Half stepping can reduce a phenomena referred to as resonance which can be experienced in 1- or 2 phases-on drive modes. By half step driving, even though the stepper motor we are using has four fixed positions, we can make it run at 8 positions. Fig 11 shows the sequences of the half step driving.
Figure 11. Half step drive waveforms. Similar to what we did with the waveforms in Fig. 9, we have highlighted in green color one period of the waveform in Fig. 11. This allows to elaborate the matrix needed to make the code implementing the waveform digitally and in a sequential way. 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 1 The program below (Fig. 12) will output the control sequence as shown above to the stepper motor. The difference with the program in Fig. 7 is that the matrix is read in columns (instead of rows). TASK: Make your own alternative program to do the same job. // const byte o4=b11100000; const byte o5=b00111000; const byte o6=b00001110; const byte o7=b10000011; word delayus=19533; // Here we implement the information // from the matrix. void setup() { for( int k=4; k <=7; k++)
pinmode( k, OUTPUT); void loop() { int i, j; { for( j=0; j<510; j++) { // This is the sequential clock for( i=7; i>=0; i--) // Notice we read the bytes from // left to right. { bitread(o4, i)? digitalwrite(4,high):digitalwrite(4,low); Figure 12. bitread(o5, i)? digitalwrite(5,high):digitalwrite(5,low); bitread(o6, i)? digitalwrite(6,high):digitalwrite(6,low); bitread(o7, i)? digitalwrite(7,high):digitalwrite(7,low); delaymicroseconds(delayus);