Design and implementation of DC motor PWM speed control system based on ATmega8

Publisher:yuehuiLatest update time:2012-02-24 Source: 21ICKeywords:ATmega8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I. Introduction

DC motors have been widely used due to their good linear speed regulation characteristics, high efficiency, simple control, good speed regulation performance and small size. In conventional motor speed control methods, the motor works unstably and has large losses, especially at low voltage and light load. In addition, the working frequency is limited by the power supply frequency, which makes it difficult to meet the high-precision speed regulation requirements and is not conducive to widespread promotion [1]. The

purpose of our research is to make the circuit have low cost, high control accuracy, convenient debugging and parameter modification, and convenient and flexible application in high-power and high-reliability DC motor control systems.
References [2] and [3] use advanced algorithms and use LTM18200 and L298 as motor control circuits, which have the advantages of high control accuracy, good stability and fast response speed, but their driving ability is low and the cost is high.

II. Principle of DC Motor PWM Speed ​​Regulation The

DC motor speed expression is:



Where: U—armature terminal voltage; I—armature current; R—armature circuit total resistance; —per-pole magnetic flux; K—motor structural parameters.
The speed control methods for DC motors can be divided into the excitation control method that controls the excitation flux and the armature control method that controls the armature voltage. At present, most DC motors use a switch drive method, which makes the semiconductor power device work in a switch state and controls the motor armature voltage through pulse width modulation (PWM) to achieve speed regulation.

PWM (Pulse Width Modulation) - Pulse width modulation technology modulates the width of a series of digital pulses. Under the action of the pulses, when the motor is powered on, the speed increases, and when the power is off, the speed gradually slows down. As long as the power-on and power-off time are changed according to a certain rule, the motor speed can be controlled to realize the digitalization of DC motor speed regulation [4], as shown in Figure 1.



3. Control system hardware design

This speed control system is mainly composed of ATmega8 microcontroller, drive circuit, speed detection circuit and communication interface circuit, as shown in Figure 2.

[page]


1. Introduction to ATmega8 microcontroller[5]

ATmega8 is an enhanced AVR RISC CMOS microcontroller with the advantages of high speed, low power consumption, rich on-chip resources, and strong power supply anti-interference ability. ATmega8 has 32 general working registers and a rich instruction set, with a hardware multiplier, 8K FLASH and 1K SRAM, 8-way 10-bit ADC and three-channel PWM output, supports ISP function, and can easily program and modify the device online.

2. ATmega8 implements PWM control

ATmega8's 16-bit T/C can achieve precise program timing, waveform generation and signal measurement. ATmega8 waveform generator uses double buffered output compare register OCR1A/B to compare with T/C value to generate PWM signal, and outputs interference-free pulse, phase-correct, variable frequency PWM signal through output compare pin OC1A/B.

PWM converts pulses with different duty cycles (ratio of motor armature voltage on time to power cycle) into different voltages to drive DC motor to rotate. By changing the duty cycle, different speeds are obtained to realize motor start, stop, and reverse functions.
The microcontroller compares the deviation between the preset speed and the measured speed, obtains the control quantity through PID algorithm, changes the output pulse width of PWM signal according to the control quantity, realizes the control of motor speed after the drive circuit power amplification, and then enters the next control cycle.

3. Driving circuit principle

DC motors are often required to work in forward and reverse situations, so a reversible PWM system is needed. The reversible PWM system can be divided into a bipolar drive reversible PWM system and a unipolar drive reversible PWM system. The bipolar reversible system runs smoothly at low speed, but the current fluctuation is large and the power loss is large. In particular, the dead zone must be increased to avoid the danger of the switch tube being directly connected, which limits the increase in the switching frequency; the unipolar drive method can avoid the switch tube being directly connected, which can greatly improve the reliability of the system. Although there will be a current cut-off under light load, it can be overcome by increasing the switching frequency or improving the circuit design.

The system adopts limited multiplication unipolar reversible PWM drive control, as shown in Figure 3. It can change the control method of the switch tube to make the two ends of the DC motor armature obtain a voltage wave that is 1 times higher than the PWM control signal frequency, which can make up for the current cut-off problem caused by the limited unipolar drive. It has the advantages of strong driving ability, simple control, high reliability and low cost.


PWM is connected to the PWM signal output of the OCR1A pin of ATmega8, and IN1 and IN2 are connected to the forward and reverse control signals of the motor; the specific logic functions of PWM, IN1 and IN2 are shown in Table 1:



4. Control system program design

The control program adopts C language modular structure. It mainly includes main program, PID control program, interrupt service program and motor forward and reverse control program.

1. Main program flow chart

The main program mainly completes the functions of related interrupt initialization, calling display, judging interrupt type and executing corresponding interrupt service program. Its structure is shown in Figure 4:


2. Digital PID controller[1]

In the control system, the PID controller, which uses the proportional P, integral I, and differential D of the deviation between the output and the given quantity to form the control quantity through linear combination, has been widely used. It is easy to set parameters and flexible to change the structure.
PID expression:



Where: u(t) - control quantity; KP - proportional gain factor; TI - integral time; TD - differential time.

This system uses a rotor position sensor, and uses the pulse signal output by the sensor to reflect the motor speed. The signal output by the sensor is sent to the microcontroller after passing through the sampling and conditioning circuit. This pin is used as the input port of the external interrupt source. As the motor rotates, the microcontroller will continuously receive pulse signals. When a rising edge is received, timer T0 will be started to start timing until the next adjacent rising edge is received. The timing result of timer T0 is the time required for the motor to rotate one circle, and the motor speed can be calculated based on this.

Using the PID algorithm, the real-time collected motor speed value is compared with the set value to obtain the deviation, and the speed regulation is achieved using software programming.

This system adopts position digital PID algorithm, and the simplified schematic diagram of its control algorithm is shown in Figure 5:


Using the full-quantity algorithm, the expression can be simplified by substituting difference for differentiation:



Where: ; ;
u(k)——the control quantity at the Kth sampling moment; KP——the proportional amplification factor; kI——the integral amplification factor; kD——the differential amplification system; TS——the sampling period; u0——the base value of the control quantity, that is, the control when k=0.
The PID algorithm flow chart is shown in Figure 6:

[page]

3. Control procedures

The following is part of the program for ATmega8 microcontroller to implement motor control:
Initialization of PWM controller:
void timer1_init(void)
{ OCR1A = 0; //Initialize to 0, motor stop
OCR1B = 0; //Initialize to 0, motor stop
TCCR1A = (1< TCCR1B = (1< TCNT1 = 1;
CLR_IN1;
SET_IN2;
CLR_IN3;
SET_IN4;
}
Timer 0 interrupt service function, used to control the time of PWM1A:
SIGNAL(SIG_OVERFLOW0)
{ if(Timer0_Tick < PWM1A_counter)
{ Timer0_Tick++;}
else{printf("ACK:");
SET_IN3;
SET_IN4;
OCR1A = 0;
TIMSK &= ~_BV(TOIE0);
}
}
Motor forward rotation, speed is the speed (adjustable from 0 to 255), choose is the motor channel selection (R is right, L is left):
void for_ward(uchar speed,char choose)
{ if(ch =='R')
{ OCR1B = speed; // PWM1B_EN;
SET_IN1;
CLR_IN2; }
Else
{ OCR1A = speed; // PWM1A_EN;
SET_IN3;
CLR_IN4; }
}

V. Conclusion

Using the PWM signal generated by the ATmega8 microcontroller, the digital PID algorithm is added to control the motor speed, which improves the control accuracy of the system and ensures the stability of the motor speed; the start, stop, left and right turn and speed of the motor are defined by the program. During debugging, only the duty cycle of the PWM signal needs to be modified to achieve speed control, and the output port level can be changed to achieve the forward and reverse rotation of the motor. Various controls can be achieved without changing the system hardware circuit, which can effectively shorten the development cycle and improve efficiency; combined with the limited multiplication unipolar reversible PWM motor drive circuit, the system's driving ability is enhanced, and the system's reliability and cost performance are improved. The circuit design is simple, the motor control is convenient, and it is conducive to wide promotion.

Keywords:ATmega8 Reference address:Design and implementation of DC motor PWM speed control system based on ATmega8

Previous article:ATmega48 sensor button design based on Atmel QTouch
Next article:Design of LED rotating screen based on ATmega16L chip

Recommended ReadingLatest update time:2024-11-18 13:39

Three-phase PWM motor driver A3936 and its application [Figure]
Brushless DC motors have the advantages of simple structure, reliable operation, and easy maintenance of AC motors, as well as high efficiency and good speed regulation performance of DC motors. They are increasingly used in industrial control, instrumentation, aerospace and other fields. A3936 is a new generation of
[Power Management]
Three-phase PWM motor driver A3936 and its application [Figure]
Speed ​​measurement based on 51 single chip PWM speed regulation digital tube display
#include "reg52.h" //MCU header file #define uchar unsigned char //Macro definition, use uchar to represent unsigned char, called unsigned character data type, with a value range of: 0 to 255. #define uint unsigned int //Macro definition, use uint to represent unsigned int, called unsigned integer data type, with a va
[Microcontroller]
Speed ​​measurement based on 51 single chip PWM speed regulation digital tube display
Design of online UPS based on new PWM rectification control technology
  1 Overview     PWM front-end controlled rectifier is widely used in three-phase AC/DC voltage system due to its advantages such as DC voltage change, input power factor correction (PFC) and input current harmonic control. The three-phase AC/DC voltage system composed of front-end rectifier, DC capacitor and inverte
[Power Management]
Design of online UPS based on new PWM rectification control technology
Simple and practical LED driver solution with PWM and analog dimming functions
PT4115 is a step-down constant current source IC in continuous inductor current conduction mode (Figure 1), which can directly convert DC voltage into a stable constant current output. This chip is suitable for the driving circuit of green lighting LED lamps and has the advantage of a very simple application circuit.
[Power Management]
Simple and practical LED driver solution with PWM and analog dimming functions
PWM/Analog Driver Leads WLED Backlight Dimming Analysis
W LED is popular. PWM and analog dimming drivers will excel in different fields for different application requirements . In view of this, the industry has developed solutions that can switch between analog and PWM dimming modes to meet different market needs. White light emitting d
[Power Management]
PWM/Analog Driver Leads WLED Backlight Dimming Analysis
Robotics Tutorial 1: How to use 51 MCU to output PWM wave
1. Theoretical knowledge     The PWM function has a dedicated module inside high-end microcontrollers such as Freescale and STM32. When using such chips to implement the PWM function, you only need to set the corresponding registers to achieve the control of the cycle and duty cycle. However, if you want to use a 51 m
[Microcontroller]
PWM control output circuit of single chip microcomputer
Electronics enthusiasts provide you with a single-chip microcomputer PWM control output circuit. The current of the output circuit is between 4 and 20MA. I hope it will be helpful to your work and study. The specific circuit diagram is as follows:
[Microcontroller]
PWM control output circuit of single chip microcomputer
S3C2440 development board bare metal program series 05 - timer PWM
1. PWM Overview Timers 0, 1, 2, and 3 have PWM functions. TCNTBn is the initial count value. After the timer is turned on, it counts down by 1. The value of TCMPBn is used for comparison. The initial value is 0, so when TCNTBn counts down by 1 to 0, it is equal to TCMPBn, and TOUTn will flip. Therefore, the value
[Microcontroller]
S3C2440 development board bare metal program series 05 - timer PWM
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号