Design of stepper motor drive circuit based on single chip microcomputer
Stepper motors have a wide range of applications in control systems . It can convert pulse signal into angular displacement, and can be used as electromagnetic brake wheel, electromagnetic differential device, or angular displacement generator, etc.
Sometimes the stepper motor removed from some old equipment (this kind of motor is generally not damaged) needs to be used for other purposes, and it is generally necessary to design the driver by yourself. This article describes a driver designed for a stepper motor removed from an old Japanese printer. This article first introduces the working principle of the stepping motor, and then introduces the software and hardware design of its driver .
1. Working principle of stepper motor
The stepping motor is a four-phase stepping motor powered by a unipolar DC power supply. As long as the phase windings of the stepping motor are energized according to the appropriate timing, the stepping motor can be rotated step by step. Figure 1 is a schematic diagram of the working principle of the four-phase reactive stepper motor.
Figure 1 Schematic diagram of four-phase stepping motor stepping
At the beginning, the switch SB is powered on, SA, SC, and SD are disconnected, and the B-phase magnetic pole is aligned with the No. 0 and No. 3 teeth of the rotor. At the same time, the No. 1 and No. 4 teeth of the rotor have misaligned teeth with the C and D-phase winding magnetic poles. No. 2 and No. 5 teeth produce wrong teeth with the magnetic poles of the D and A phase windings.
When the switch SC is powered on and SB, SA, and SD are disconnected, due to the action of the magnetic force lines of the C-phase winding and the magnetic force lines between the 1st and 4th teeth, the rotor rotates, and the 1st and 4th teeth align with the magnetic poles of the C-phase winding . The 0, 3 teeth and the A, B phase windings produce wrong teeth, and the 2, 5 teeth and the A, D phase winding magnetic poles
wrong teeth. By analogy, the A, B, C, and D four-phase windings supply power in turn, and the rotor will rotate in the directions of A, B, C, and D.
Four-phase stepper motors can be divided into three working modes: single four-shot, double four-shot, and eight-shot according to the different power-on sequences. The step angles of the single four-beat and the double four-beat are equal, but the rotational moment of the single four-beat is small. The step angle of the eight-beat working method is half of that of the single four-beat and double four-beat. Therefore, the eight-beat working method can not only maintain a higher rotational torque but also improve control accuracy.
The power-on timing and waveforms of single-four-beat, double-four-beat and eight-beat working modes are shown in Figure 2.a, b, and c, respectively:
Figure 2. Stepping motor working timing waveform diagram
Figure 3 Schematic diagram of the stepper motor driver system circuit
AT89C2051 outputs the control pulse from P1.4~P1.7 of P1 port, and enters 9014 after being inverted by 74LS14 . After being amplified by 9014, it controls the photoelectric switch. After photoelectric isolation, the pulse signal is amplified by the power tube TI P122 for voltage and current , to drive the windings of each phase of the stepper motor. Make the stepper motor perform actions such as forward rotation, reverse rotation, acceleration, deceleration and stop according to different pulse signals. L1 in the figure is a phase winding of the stepper motor. AT89C2051 chooses a crystal oscillator with a frequency of 22MHz. The purpose of choosing a higher crystal oscillator is to minimize the impact of AT89C2051 on the pulse signal period of the host computer in mode 2 .
RL1-RL4 in Figure 3 are the internal resistance of the winding, and the 50Ω resistor is an external resistor that acts as a current limiter and is also a component that improves the loop time constant. D1~D4 are freewheeling diodes , so that the counter electromotive force generated by the motor winding is attenuated through the freewheeling diodes (D1~D4), thus protecting the power tube TIP122 from damage.
Connecting a 200μF capacitor in parallel with the 50Ω external resistor can improve the front edge of the current pulse injected into the winding of the stepping motor and improve the high frequency performance of the stepping motor. The 200Ω resistor in series with the freewheeling diode can reduce the discharge time constant of the circuit, make the trailing edge of the current pulse in the winding steeper, and the current fall time become smaller, which also plays a role in improving the high-frequency working performance.
3. Software design
The driver has three working modes for selection according to the different combinations of the dial switches KX and KY:
Mode 1 is the interrupt mode: P3.5 (INT1) is the step pulse input terminal, and P3.7 is the forward and reverse pulse input terminal. The upper computer (PC or single-chip microcomputer) is only connected with the driver by 2 lines.
Mode 2 is the serial communication mode: the upper computer (PC or single-chip microcomputer) sends the control command to the driver, and the driver completes the relevant control process by itself according to the control command.
Mode 3 is the dial switch control mode: directly control the stepper motor through different combinations of K1 ~ K5.
When the power is turned on or the reset key KR is pressed, the AT89C2051 first detects the status of the DIP switches KX and KY, and enters into different working modes according to different combinations of KX and KY. The program flow diagram and source program of mode 1 are given below.
In the compilation of the program, special attention should be paid to the handling of the stepping motor when commutating. In order to make the stepper motor transition smoothly during commutation and avoid wrong steps, the flag bit should be set in each step. Among them, each bit of unit 20H is the forward rotation flag of the stepping motor; each bit of unit 21H is the reverse flag bit. In the forward rotation, not only the forward rotation flag bit is assigned, but also the reverse rotation flag bit is assigned; the same is true in the reverse rotation. In this way, when the stepper motor changes direction, it can move backwards from the last position as the starting point, avoiding wrong steps when the motor changes direction.
Figure 4 Block diagram of method 1
Mode 1 source program:
MOV 20H, #00H ; Unit 20H sets the initial value, the motor rotates forward and the position pointer
MOV 21H, #00H ; Unit 21H sets the initial value, the motor reverses the position pointer
MOV P1,#0C0H ;P1 port is set to the initial value to prevent short circuit when the motor is powered on
MOV TMOD,#60H ;T1 counter set initial value, open interrupt
MOV TL1,#0FFH
MOV TH1,#0FFH
SETB ET1
SETB OF
SETB TR1
SJMP $
;********** Counter 1 interrupt program *************
IT1P: JB P3.7, FAN ; motor forward and reverse pointer
;**************motor forward******************
JB 00H,LOOP0
JB 01H,LOOP1
JB 02H,LOOP2
JB 03H,LOOP3
JB 04H,LOOP4
JB 05H,LOOP5
JB 06H,LOOP6
JB 07H,LOOP7
LOOP0: MOV P1,#0D0H
MOV 20H,#02H
MOV 21H,#40H
AJMP QUIT
LOOP1: MOV P1,#090H
MOV 20H,#04H
MOV 21H,#20H
AJMP QUIT
LOOP2: MOV P1,#0B0H
MOV 20H,#08H
MOV 21H,#10H
AJMP QUIT
LOOP3: MOV P1,#030H
MOV 20H,#10H
MOV 21H,#08H
AJMP QUIT
LOOP4: MOV P1
,#070H
MOV 20H,#20H
MOV 21H,#04H
AJMP QUIT
LOOP5: MOV P1,#060H
MOV 20H,#40H
MOV 21H,#02H
AJMP QUIT
LOOP6: MOV P1,#0E0H
MOV 20H,#80H
MOV 21H,#01H
AJMP QUIT
LOOP7: MOV P1,#0C0H
MOV 20H,#01H
MOV 21H,#80H
AJMP QUIT
;**************** Motor Reverse******************
FAN: JB 08H,LOOQ0
JB 09H,LOOQ1
JB 0AH,LOOQ2
JB 0BH, LOOQ3
JB 0CH,LOOQ4
JB 0DH,LOOQ5
JB 0EH,LOOQ6
JB 0FH,LOOQ7
LOOQ0: MOV P1,#0A0H
MOV 21H,#02H
MOV 20H,#40H
AJMP QUIT
LOOQ1: MOV P1,#0E0H
MOV 21H,#04H
MOV 20H,#20H
AJMP QUIT
LOOQ2: MOV P1,#0C0H
MOV 21H,#08H
MOV 20H,#10H
AJMP QUIT
LOOQ3: MOV P1,#0D0H
MOV 21H,#10H
MOV 20H,#08H
AJMP QUIT
LOOQ4: MOV P1,#050H
MOV 21H,#20H
MOV 20H,#04H
AJMP QUIT
LOOQ5: MOV P1,#070H
MOV 21H,#40H
MOV 20H,#02H
AJMP QUIT
LOOQ6: MOV P1,#030H
MOV 21H,#80H
MOV 20H,#01H
AJMP QUIT
LOOQ7: MOV P1,#0B0H
MOV 21H,#01H
MOV 20H,#80H
QUIT: NET
END
4 Conclusion
The driver has been experimentally verified to drive a 0.5Nm stepper motor. Adjust the relevant parameters of the resistance, capacitance and freewheeling diode of the driving part to drive a 1.2Nm stepping motor. The driver circuit is simple and reliable, and has a compact structure, and is especially suitable for systems with tight resources of I/O port lines and single-chip microcomputers.
[The above information is compiled and released by Aibo Testing. If there is any discrepancy, please correct it in time. If there is any quotation, please indicate the source. Welcome to discuss together. We have been paying attention to its development! Focus: CCC/SRRC/CTA/operator warehousing]