Abstract: This paper describes the design of a DC motor PWM control system based on 80C196KC and L298N, presents the working principle of the PWM speed control system, introduces the implementation method and anti-interference measures of L298N driving DC motor with specific hardware circuits, and provides a software implementation method for introducing segmented PI control. Practice has proven that the system operates stably and reliably, achieving the set effect.
1. Introduction
DC motors are widely used in various fields due to their excellent speed regulation performance, large starting torque, and strong overload capacity. In recent years, the structure and control methods of DC motors have undergone significant changes. With the entry of computers into the control field and the continuous emergence of new power electronic components, PWM (pulse width modulation) speed regulation has become a new method for DC motor speed regulation. It is widely used in DC motor speed regulation due to its advantages such as high switching frequency, stable low-speed operation, excellent dynamic performance, and high efficiency.
2. Working principle of PWM speed control system
PWM, or Pulse Width Modulation, refers to using the switching characteristics of high-power transistors to modulate a fixed-voltage DC power supply, switching it on and off at a fixed frequency. The duration of these on/off cycles can be varied as needed, thereby changing the duty cycle of the voltage on the armature of a DC servo motor to alter the average voltage and thus control the motor's speed. Therefore, it is often referred to as a switching drive device. A schematic diagram of PWM control is shown in Figure 1.
Figure 1 Schematic diagram of PWM control
There are generally two ways to change the duty cycle: PWM and PFM (pulse frequency modulation). PWM changes the width of the conduction pulse, which is commonly referred to as fixed-frequency pulse width modulation. PFM changes the duty cycle by changing the switching frequency while keeping the conduction pulse width constant. Since mechanical resonance at a certain frequency often leads to vibration and howling noise in the system, PWM control is mainly used in the control of DC motors.
3. Hardware design of the control system based on 80C196KC and L298N
The DC motor speed control system based on the 80C196KC and L298N consists of a microcontroller minimum system, an R/D converter, a PWM power amplifier circuit, A/D and D/A conversion circuits, and a command receiving interface circuit. The microcontroller minimum system uses a 16-bit 80C196KC microcontroller with an external interface circuit, mainly used for data acquisition and PWM signal generation. The block diagram of the speed control system is shown in Figure 2.
Figure 2 Block diagram of PWM speed control system
3.1 Introduction to the L298N Power Integrated Circuit
To improve system efficiency and reduce power consumption, the power amplifier driver circuit uses the L298N integrated circuit based on bipolar H-bridge pulse width modulation. The L298N is a high-performance pulse width modulation power amplifier manufactured by SGS, characterized by its small size and strong driving capability. Internally, it contains two H-bridge high-voltage, high-current bridge drivers, enabling single-chip full-bridge driving of motors up to 46V and 2A. The internal structure of the L298N is shown in Figure 3.
Figure 3. Internal structural block diagram of L298N
3.2 Hardware Circuit of DC Motor Control System
The L298N can drive two DC motors. Since this speed control system is a single-axis structure, to fully utilize the load-carrying capacity of the power amplifier circuit and enable the system to start and brake at maximum acceleration, the inputs and outputs are connected in parallel in pairs to control the DC motors. As shown in Figure 4, input terminals IN1 and IN3 are connected in parallel, IN2 and IN4 are connected in parallel, and output terminals OUT1 and OUT3 are connected in parallel, while OUT2 and OUT4 are connected in parallel and connected to both ends of the motor. The enable terminal is controlled by the microcontroller's high-speed output port HSO1.
The 80C196KC microcontroller generates a PWM signal based on the position and speed loop calculations. One PWM signal is directly output to IN1 (IN3), and the other is inverted by a 7406 and output to IN2 (IN4). When the PWM analog signal duty cycle is 50%, the forward and reverse voltages at the motor terminals are applied for the same duration, and the motor is in a slight tremor state, i.e., in a "power lubrication" state. When the duty cycle is greater than 50%, the signal voltage OUTA is greater than OUTB, and the motor rotates forward; conversely, it rotates backward. Therefore, the output polarity of each stage must be aligned to form negative feedback and complete closed-loop control. By changing the PWM duty cycle, the motor speed can be controlled, and the motor direction can also be changed. The control method is simple and reliable. In addition, because the motor is a coil type, a back electromotive force is generated when the motor stops suddenly or reverses abruptly. To ensure the normal operation of the L298N driver chip, two pairs of freewheeling diodes are added between the output terminals OUTA and OUTB and the DC motor to shunt the current to the positive terminal of the power supply or ground, so as to prevent the back electromotive force from damaging the L298N.
3.3 Anti-interference and electromagnetic compatibility design
During motor operation, the rapid switching of the main power switching elements results in significant changes in power current and voltage, affecting not only the drive circuit but also the control circuit via the power supply and ground. Furthermore, transient voltages are generated at load abrupt changes during motor start-up and braking. These transient voltages have amplitudes higher than the power supply voltage, with steep leading edges and wide bandwidths, and enter the control circuit via the DC power supply. Therefore, interference suppression and electromagnetic compatibility design are crucial. The system incorporates measures such as current smoothing, glitching, and shielding.
Current smoothing: Due to the large instantaneous energy of PWM switching, an RC filter is used at the output of the PWM power amplifier. By selecting appropriate resistor and capacitor values, high-frequency harmonics are effectively suppressed, PWM power amplifier voltage spikes are absorbed, and interference is reduced.
De-glitching: The system increases the filter capacitor at the power supply end, using two capacitors, one large and one small, connected in parallel. The large capacitor is responsible for decoupling, filtering, and smoothing low-frequency alternating signals, while the small capacitor eliminates mid- and high-frequency parasitic couplings in the circuit network, effectively reducing spikes and glitches;
Shielding: The motor drive cable is a double-shielded cable, and the wiring is kept as separate as possible from other cables.
Figure 4 Driver hardware circuit diagram
4. Control system software implementation
The control system employs a combination of speed and position closed-loop control. Taking position control as an example, the software implementation method is introduced. Based on the classic PI control algorithm, the proportional and integral parameters are simplified, and piecewise PI control is introduced. This involves dividing the calculated error into segments, with different proportional and integral parameters used for adjustment within each segment. This ensures smoother and more stable system operation. The derivation and simplification process of the PI formula is as follows:
The specific software implementation flowchart is shown in Figure 5. After receiving the given angle command, the difference between the sampled position information and the given angle is first calculated. Then, the difference is divided into n equal parts. Each segment corresponds to a set of parameters kp1 and ki1 for adjustment and control. The output quantity of PI control is calculated and then converted into the corresponding PWM value output.
Figure 5 Software Flowchart
5. Conclusion
This DC motor PWM control system, based on the 80C196KC and L298N microcontrollers, uses a microcontroller to generate PWM signals for the L298N power integrated circuit. It employs classic PI segmented control to achieve motor control, featuring simple circuitry and convenient control. Operational test results show that the system operates stably and reliably, meeting the speed regulation requirements, and has been successfully applied in multiple airborne products.