Share this

Design of a DC motor servo system based on PWM and CWG modules

2026-04-06 05:58:46 · · #1

DC motors have a simple structure, stable and reliable operation, and are relatively easy to implement servo control. This paper uses a PIC16F1508 microcontroller as the controller, and utilizes its PWM module and CWG module to generate complementary PWM waveforms with dead time, which are input to the upper and lower bridge arms of the H-bridge drive, effectively solving the shoot-through problem of the upper and lower bridge arms of the DC motor H-bridge drive.

introduction

The DC motor was the first electric motor invented and the first to achieve speed control. In most speed-controlled applications, the DC motor is still the preferred choice because it is inexpensive, easy to adjust, and provides relatively smooth speed control. Currently, DC motors are still widely used in smart toys and push-button adjustable car seats.

1. Composition of DC motor servo system

The DC motor servo system mainly includes a controller PIC16F1508, an opto-isolation circuit, a drive circuit, and a speed detection and level conversion circuit, as shown in Figure 1.

Figure 1 Block diagram of DC motor servo system

2. Hardware Design of the Servo System

2.1PIC16F1508

The PIC16F1508 is an 8-bit flash memory microcontroller from Microchip Technology. Compared to other Microchip microcontrollers, it adds several unique feature modules, such as a Complementary Waveform Generator (CWG) module, a Configurable Logic Unit (CLC) module, and a Numerically Controlled Oscillator (NCO) module. The CWG module is primarily used in DC motor servo systems .

The Complementary Waveform Generator (CWG) module has the function of generating complementary waveforms with dead time delay for the selected input source [2]. In short, the CWG module can generate complementary waveforms with dual outputs for the selected input source, and also has a certain dead time delay. In this servo system , the CWG module selects a specific PWM input source to generate a complementary PWM waveform with dead time delay, which is output to the upper and lower bridge arms of the H bridge, effectively avoiding the shoot-through problem of the upper and lower switching transistors, which is a major advantage of this servo system. In addition, the microcontroller itself generates a PWM waveform with dead time, which not only makes the system adjustable and stable, but also makes the entire system structure more compact and greatly reduces the cost.

2.2 Opto-isolation circuit

To protect the PIC controller and effectively suppress signal interference, an opto-isolator chip HCPL4504 was added between the controller and the H-bridge. It provides opto-isolation for the four PWM pulses output from the PIC16F1508. The opto-isolation circuit for one of the PWM signal outputs is shown in Figure 2; the other three are similar.

Figure 2. Optocoupler isolation circuit for PWM signal output

2.3 Drive Circuit

The driving of a reversible DC motor system mainly includes bipolar driving and unipolar driving. Bipolar driving means that the voltage polarity of the motor armature changes between positive and negative in one PWM cycle; while unipolar driving means that the motor armature only bears a unipolar voltage in one PWM cycle [3]. This system adopts unipolar driving, and unipolar driving is further divided into T-type and H-type, with H-type being more commonly used, as shown in Figure 3.

Figure 3H type unipolar reversible PWM drive system

As shown in Figure 3, the H-type unipolar reversible PWM drive system mainly consists of four MOSFETs. In this system, the upper arm of the H-bridge is composed of PMOS transistors, and the lower arm is composed of NMOS transistors. This effectively avoids the boost or buck circuits required when using all NMOS transistors or all PMOS transistors, reducing the complexity of the circuit and relatively improving the stability of the system.

Furthermore, MOSFETs are voltage-driven devices. The gate drive circuits for both PMOS and NMOS transistors utilize low-cost, simple-to-fabricate bipolar transistors, as shown in Figures 4 and 5. The overall H-bridge drive circuit is shown in Figure 6.

Figure 4 PMOS drive circuit

Figure 5 NMOS drive circuit

Figure 6 H-bridge drive circuit

2.4 Speed ​​Detection and Level Conversion Circuit

Methods for detecting the speed of DC motors include Hall effect sensors, photoelectric encoders, and DC tachogenerators. This system uses a DC tachogenerator to detect the speed. The DC tachogenerator is mounted on the shaft of the DC motor under test and rotates at the same speed as the motor. The selected DC tachogenerator model is ZCF221A. The speed of the DC motor is obtained by detecting the feedback voltage of the DC tachogenerator. Considering that the DC generator output voltage is -50~50V, which is far beyond the range of the A/D conversion input signal, level conversion is required.

This system first uses a precision voltage regulator TL431 to reduce the voltage to 2.5~7.5V, and then employs a high-precision differential amplifier INA132. The INA132 can form a subtraction circuit to ensure the voltage meets the input requirements of the A/D sampling circuit; in addition, it features a module with medium input impedance, closed-loop control, and fixed gain, allowing signal acquisition even in the presence of ground loops and noise. The INA132 has a fixed differential gain of 1/2 or 1, and exhibits a high common-mode rejection ratio. The specific level conversion circuit is shown in Figure 7.

Figure 7 Level conversion circuit

3. Software Design of Servo System

The software for DC motor servo control mainly consists of three parts: the main program, the PWM cycle interrupt subroutine, and the A/D conversion interrupt subroutine.

3.1 Main Program

The main program primarily includes setting the states of each I/O input/output, configuring the PWM module, setting the CWG module, and then waiting for interrupt responses, as shown in Figure 8. The module configuration of the main program is relatively simple, resulting in low program resource consumption and good portability.

Figure 8 Main Program Flowchart

3.2 PWM Period Interrupt Subroutine

After the PWM period interrupt subroutine samples the data upon reaching the sampling period, it compares the actual speed value with the base value of the tachogenerator and then multiplies it by the corresponding conversion coefficient to obtain the actual speed value. The speed is then adjusted using PI. The specific flowchart is shown in Figure 9.

Figure 9 Flowchart of PWM Period Interrupt Subroutine

3.3 A/D Conversion Interrupt Subroutine

The main function of the A/D conversion interrupt subroutine is to request an A/D interrupt after continuous automatic sampling and A/D conversion, that is, to convert the feedback input analog signal into a digital signal and read the speed conversion result in the A/D conversion interrupt subroutine.

4. Experimental Phenomena and Conclusions

After the system is powered on, the complementary PWM waveform with dead-time delay is detected by an oscilloscope through the operation of the PWM module and CWG module programs, as shown in Figure 11. This effectively avoids shoot-through in the upper and lower arms of the H-bridge driving circuit, laying the foundation for the stable operation of the entire system.

After testing, the DC motor speed regulation at a PWM frequency of 4kHz is shown in Figure 12. As can be seen from the figure, the DC motor speed is proportional to the PWM duty cycle. The difference between the theoretical and actual speeds, compared to the theoretical value, represents the relative error. The average of the 18 sets of relative errors is 0.15%, which meets the application requirements.

1—PWM waveform, 2—PWM waveform with rising edge dead time, 3—PWM waveform with falling edge dead time

Figure 11 Experimental diagram of complementary PWM waveform with dead time

Figure 12 shows the speed of a DC motor under open-loop control.

In summary, this study uses the PIC16F1508 microcontroller as the controller, employs its unique Complementary Waveform Generator (CWG) module, drives a DC motor via an H-bridge, and uses a DC tachogenerator to detect the speed and feed it back to the microcontroller's servo system. The ability to output complementary waveforms with dead time using only a microcontroller not only simplifies and stabilizes the overall system structure but also significantly reduces system cost, providing a valuable reference for researchers of DC motor servo systems.

Read next

CATDOLL 108CM Coco (TPE Body with Hard Silicone Head) (Dark Tan Tone)

Height: 108cm Weight: 14.5kg Shoulder Width: 26cm Bust/Waist/Hip: 51/47/59cm Oral Depth: 3-5cm Vaginal Depth: 3-13cm An...

Articles 2026-02-22