1 Introduction
A stepper motor is a precision actuator that converts electrical pulse signals into angular or linear displacement. Due to its ease of control and small size, stepper motors are widely used in CNC systems, automated production lines, automated instruments, plotters, and computer peripherals. The rapid development of microelectronics and the widespread application of microcomputers have opened up broad prospects for stepper motor applications, enabling the implementation of previously large and complex controllers using hardware circuits in software. This reduces hardware costs while improving control flexibility, reliability, and multifunctionality. Many ready-made stepper motor control mechanisms are available on the market, but their prices are relatively high. Using the L297 and L298 chips from SGS, a stepper motor driver can be easily constructed. Combined with an AT89C52 microcontroller for control, a reasonably priced stepper motor drive circuit can be built.
2. Working principle
Because a stepper motor is an actuator that converts electrical pulse signals into linear or angular displacement, it cannot be directly connected to an AC or DC power supply. Instead, it requires a dedicated device – a stepper motor control driver. A typical stepper motor control system is shown in Figure 1. The controller can output pulse signals with continuously varying frequencies from a few hertz to tens of kilohertz, providing the pulse sequence to the ring distributor. The main function of the ring distributor is to distribute the pulse sequence from the control loop according to a certain rule, amplify it through a power amplifier, and then apply it to the various input terminals of the stepper motor drive power supply to drive the stepper motor's rotation. There are two main types of ring distributors: one type uses computer software to implement the required functions, usually called a soft ring distributor; the other type uses hardware to construct the ring distributor, usually called a hard ring distributor. The power amplifier mainly amplifies the smaller output signal of the ring distributor to drive the stepper motor.
Figure 1 Typical stepper motor control block diagram
3 Hardware Components
The stepper motor controlled in this paper is a four-phase single-pole 35BY48HJ120 geared stepper motor. The block diagram of the stepper motor control driver designed in this paper is shown in Figure 2. It consists of an AT89C52 microcontroller, an optocoupler, and integrated chips L297 and L298. The AT89C52 is a low-voltage, high-performance 8-bit CMOS microcontroller from Atmel, USA. It has 8KB of internally rewritable memory.
Flash memory. 256 bytes of RAM. Three 16-bit timers. Programmable serial UART channel. Sufficient for simple control of stepper motors.
Figure 2 Block diagram of the stepper motor control driver proposed in this paper
The L297 is a stepper motor controller (including a ring distributor). The L298 is a dual H-bridge driver. The interface between the microprocessor and the dual-bridge stepper motor, formed by these two components, is shown in Figure 3. The advantages of this combination are that it requires fewer components, resulting in lower assembly costs, higher reliability, and a smaller footprint. Furthermore, software development simplifies and reduces the burden on the microcomputer. In addition, both the L297 and L298 are independent chips, making their application highly flexible.
The L297 chip is a hardware ring splitter integrated circuit. It generates four-phase drive signals for computer-controlled two-phase bipolar or four-phase unipolar stepper motors. Its core is a decoder that generates various required phase sequences. This part is controlled by two input modes: direction control (CW/CCW) and HALF/FULL, as well as a step clock (CLOCK). It advances the decoder from one step to another. The decoder has four output points connected to the output logic section, providing the phase sequence required for suppression and chopping functions. Therefore, the L297 can generate three phase sequence signals, corresponding to three different operating modes: half-step mode (HALFSTEP); basic step (FULLSTEP, full step) one-phase excitation mode; and basic step two-phase excitation mode. The pulse distributor internally contains a 3-bit reversible counter, plus some combinational logic, generating an 8-step Gray code timing signal per cycle, which is the timing signal for the half-step operating mode. In this mode, the HALF/FULL signal is high. If HALF/FULL is low, the basic step operating mode is obtained. That is, a double four-beat full-step working mode.
Another important component of the L297 is the use of two PWM choppers to control the phase winding current, achieving constant current chopping control to obtain good torque-frequency characteristics. Each chopper consists of a comparator, an RS flip-flop, and an external sampling resistor, and is equipped with a common oscillator to provide trigger pulse signals to both choppers. In Figure 3, the frequency f is determined by the external 16-pin RC network; when R > 10kΩ, f = 1/0.69RC. When the clock oscillator pulse sets the flip-flop to 1, the motor winding phase current rises, and the voltage across the sampling resistor R rises to the reference voltage Uref. The comparator then flips, resetting the flip-flop, turning off the power transistor, and causing the current to decrease, awaiting the next oscillation pulse. Thus, the flip-flop outputs a constant-frequency PWM signal, modulating the L297's output signal. The peak value of the winding phase current is determined by Uref. The input to the L297's CONTROL pin determines whether the chopper operates on phase lines A, B, C, D or suppression lines INH1 and INH2. When CONTROL is high, it controls A, B, C, and D; when it is low, it controls INH1 and INH2, thereby controlling the motor's direction and torque.
The L298 chip is a high-voltage, high-current dual full-bridge driver designed to accept standard TTL logic level signals and drive inductive loads such as relays, cylindrical coils, DC motors, and stepper motors. It features two suppression inputs to prevent the device from being affected by input signals. The emitters of the transistors in each bridge are connected together, and corresponding external terminals can be used to connect external sensing resistors. An additional input power supply can be provided to allow the logic to operate at low voltages. The L298 chip is an integrated chip in a multi-wattage through-hole package with 15 pins.
In Figure 3, the AT89C52 is connected to the microcomputer via a serial port and level-shifted by a MAX232, receiving commands from the host computer. It sends clock signals, forward/reverse signals, reset signals, and enable control signals to the L297. In the circuit, resistors R13 and R15 are used to adjust the reference voltage of the chopper circuit. This voltage is compared with the potential fed back through pins 13 and 14 to determine whether chopping control is performed, thereby controlling the peak current of the motor windings and protecting the stepper motor.
Because the L297 has an internal chopper constant current circuit, the peak value of the winding phase current is determined by Uref. When two L297s are used to drive the two windings of the stepper motor respectively through an L298, and two D/A converters are used to change the Uref of each phase winding, a stepper motor microstepping drive circuit is formed. In addition, to effectively suppress electromagnetic interference and improve system reliability, two 16-pin optocouplers TLP521-4 are used in the microcontroller and stepper motor drive circuit to form an isolation circuit as shown in Figure 3. Its function is to cut off the direct electrical connection between the microcontroller and the stepper motor drive circuit, realizing separate ground connections between the microcontroller and the drive circuit system. This prevents interference signals generated by the drive circuit operating under high current inductive loads and interference signals generated by sudden changes in the power grid load from entering the microcontroller through the lines and affecting its normal operation.
4. Software Components
In this circuit, P1.0 is set as the motor start button, and P1.1, P1.2, and P1.3 are speed selection buttons, ranging from low to high speed. P1.4 is the motor stop button. The maximum speeds for the three speed settings are set to 500pps, 1000pps, and 2000pps respectively. RXD and TXD are output to the serial port via MAX232 level converter. Furthermore, stepper motors have relatively low start and stop frequencies, typically between 100-250Hz, while requiring a higher maximum operating frequency, usually 1-3kHz. To ensure that the stepper motor does not lose steps during start-up, operation, and stopping, and can quickly and accurately reach the target position, the operating speed must undergo an acceleration-constant deceleration process. Here, a common discrete method is used to approximate the ideal approximately trapezoidal acceleration/deceleration curve, as shown in Figure 5. This involves using a timer interrupt to continuously change the timer load value.
In this example, for ease of calculation, the required loading values for the speeds of each discrete point are converted into their respective required timing times and stored in the system's ROM using formulas. Here, TH0 = (65536 - time) / 256 and TL0 = (65536 - time) % 256 are used to calculate the loading values, where time represents the required timing time for each step. During system operation, a lookup table method is used to find the required time, thereby significantly reducing the CPU time occupied and improving the system's response speed. Therefore, this program mainly consists of a main control program and acceleration/deceleration subroutines, and the main program flowchart is shown in Figure 4.
5. Conclusion
The innovation of this paper lies in proposing the use of a microcontroller and L297/L298 integrated circuits to construct a stepper motor control driver. This gives it advantages such as fewer components, high reliability, small footprint, and low assembly cost. Software development simplifies and reduces the burden on the microcomputer. Furthermore, the calculation of the timer load value in the acceleration/deceleration program using formulas, as mentioned above, is inaccurate, and these two assignments take considerable time. In practice, the initial value can be calculated directly, or the division sign can be used for addition to achieve accuracy.