Research on PID and PWM liquid flow control system based on AVR microcontroller atmega32

Publisher:光明2599Latest update time:2013-12-12 Source: eefocusKeywords:atmega32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Introduction
Liquid flow control is usually achieved by solenoid valves. In recent years, the structure and control mode of solenoid valves have
changed . With the entry of computers into the control field and the continuous emergence of new power electronic power components, the pulse width modulation (PWM) control mode using fully controlled switching power components has been widely used. This control mode is easy to implement in a single-chip microcomputer, thus providing an opportunity for the digitalization of solenoid valve control.
 The proportion, integral, and differential of the deviation are linearly combined to form a control quantity, and this control quantity is used to control the controlled object. Such a controller is called a PID controller. The PID controller first appeared in analog control systems. The traditional analog PID controller realizes its function through hardware (electronic components, pneumatic and hydraulic components). With the emergence of computers, it was transplanted into computer control systems, and the original hardware-implemented functions were replaced by software, so it was called a digital PID controller, and the entire set of algorithms formed was called a digital PID algorithm. Compared with analog PID controllers, digital PID controllers have very strong flexibility and can adjust parameters online according to experiments and experience, so better control performance can be obtained.
2. Liquid flow control system composition
This system uses the AVR series atmega32 microcontroller as the core. By setting the PWM control register of atmega32 to generate a PWM wave with adjustable pulse width, the input voltage of the proportional solenoid valve is modulated to achieve variable control of the liquid flow. The microcontroller collects the actual flow signal through the turbine flowmeter, and uses the digital PID algorithm inside it to modify the value of the PWM control register according to the signal, so as to achieve precise variable control. In order to prevent external interference signals from entering the control system, optical coupling isolation is used between the microcontroller and the turbine to improve the reliability of the system. Temperature sensors and pressure sensors are used to monitor the pressure and temperature in the spray rod. Human-computer dialogue is achieved through a 4*4 keyboard and a 128*64 LCD module, which is convenient for user operation. The system schematic diagram is shown in Figure 2-1:


Figure 2-1

3 Hardware Part
3.1 PWM Drive Circuit

The PWM pulse signal output by the single-chip microcomputer is input to the G poles of Q1 and Q2 through 7406 and 7407 respectively. In the high-level interval of each PWM cycle, Q1 is turned on, Q2 is turned off, and the solenoid valve is turned on. In the low-level interval of each PWM cycle, Q1 is turned off to cut off the power supply, and the induced electromotive force of the solenoid valve forms a loop through the internal freewheeling diode of Q2. At this time, the G pole of Q2 is at a high level, but the switching diode is turned off due to the clamping effect of the diode. Therefore, by adjusting the PWM wave of the single-chip microcomputer, the duty cycle of the solenoid valve input voltage can be adjusted, thereby achieving flow regulation.
3.2 Proportional solenoid valve
Proportional solenoid valve has been used in the late 1960s and was originally used in hydraulic control systems. With the development of single-chip microcomputers and integrated circuits, it has gradually been applied to the flow control of various liquids. The working principle of the proportional electromagnet is as follows: After the coil is energized, magnetic flux is generated inside the yoke and the armature, and electromagnetic attraction is generated, which attracts the armature to the yoke. At the same time, the spring on the armature is compressed. When the electromagnetic force and spring force on the armature are balanced, the armature stops moving. The suction force of the proportional electromagnet has a linear relationship with the current or voltage of the coil within the effective stroke range. Therefore, by adjusting the input current or voltage, the size of its opening can be controlled, thereby achieving the purpose of variable control. The characteristic curve of the proportional solenoid valve used in this system is shown in Figure 3-1: (Kvs represents the flow rate when the proportional solenoid valve is at its maximum opening, and Kv represents the flow rate value corresponding to a certain voltage or current value).

4. Software
4.1 PWM wave generation
The design uses the single-chip microcomputer atmega32 to generate PWM signals. The PWM mode of the atmega32 timer/counter can be divided into two categories: fast PWM and frequency (phase) adjustment PWM. This design uses the fast PWM mode. Fast PWM can get a relatively high frequency PWM output, and the response is relatively fast, so it has high real-time performance. At this time, the counter only works in a one-way forward counting mode. The upper limit value of the counter determines the frequency of PWM, and the value of the comparison match register determines the size of the duty cycle. The control register settings of fast PWM mode are as follows:
   //Output port initialization
   PORTD=0x44;
   DDRD=0x20;
   //T/C1 initialization
   TCCR1A=0xC3;/*OC1A outputs high level when compare match, clears ICP falling edge capture when at top value,
   clock 1/8 division (tentative), that is, working in inverted pwm mode*/
   TCCR1B=0x0A;//10-bit fast pwm mode
   TCNT1H=0x00;//start at 0
   TCNT1L=0x00;[page]

4.2 PID Algorithm

The basic principle of the conventional PID algorithm is shown in Figure 4-1 below. The control law of the analog PID controller is:

  ——Proportional coefficient; ——Integral constant; ——Differential constant; ——Control constant.
Since the single-chip control is a sampling control, it can only calculate the control quantity according to the deviation value at the sampling time, and cannot continuously output the control quantity and perform continuous control like analog control. In addition, the amount of data processed by the single-chip is limited. Considering comprehensively, the system adopts incremental PID control, and its algorithm is as shown in formula 4-3:

Where is the sampling error of this time; is the sampling error of the previous time; is the sampling error of the previous time. The flow chart of its control program is shown in Figure 4-2

The program implemented in C is as follows:
void PID()
{float u; //voltage difference
  sint z; //this output increment
  sint temp1; //temporary record value
  float t;
  t=itime*T;
  Speed_change(); //Convert flow rate into digital quantityif
  (Ek==(0-Sheding_liusu)) //When Ek is greater than a certain value, directly add the maximum value
  {temp1=0x0000;
   SetOutputOCR1A(temp1); }//Set the output compare register valueelse
     {
   Ek=Sheding_liusu-Celiang_liusu;
   u=A*((Ek-Ek_1)+(t/B)*Ek+(C/t)*(Ek-2*Ek_1+Ek_2)); //Incremental PID algorithmz
   =u/U1*0x03FF;
   temp1=GetOutputOCR1A(); //Read the output compare register valuetemp1
   =temp1+z;
   SetOutputOCR1A(temp1);
   Ek_2=Ek_1;
   Ek_1=Ek;}
  TCNT1=0x00;}
5. Simulation under Matlab
Matlab is an analysis and simulation software for control systems. It can be used to simulate the control system conveniently and accurately. In order to verify the reliability of the digital PID algorithm, the simulink component under Matlab6.5 is used to simulate the incremental digital PID algorithm. The simulation program is shown in Figure 5-1, and the simulation results are shown in Figure 5-2.

As shown in Figure 5-2, Kp=0.5, Ki=0.001, Kd=0.001,
the simulation results show that the use of PID to adjust the PWM square wave has good dynamics and stability, thus proving the feasibility of the liquid flow control system.
6. Conclusion
  This paper introduces the solution of using digital PID algorithm combined with the PWM function of AVR microcontroller to realize liquid flow control, and uses Matlab software for simulation to prove the feasibility of the system. Compared with the hardware PID controller, the digital PID algorithm is easy to operate to adjust the control parameters, and the system setting is flexible. This control system can be applied to liquid flow control in industries such as industry and agriculture, and can also be used for solenoid valve control in hydraulic systems. The
author's innovation in this paper:
Traditional liquid flow control mostly uses high-speed switching solenoid valves. The frequent switching of solenoid valves will produce a large hysteresis, which is not conducive to the real-time performance of the control system. The system uses PWM signals to control the size of the proportional solenoid valve opening, realizes continuous control of the flow, reduces hysteresis, and uses incremental digital PID algorithm to adjust the closed-loop control, making the system adjustment more accurate and stable.
References:
[1] Liu Jinkun, Advanced PID Control Matlab Simulation (2nd Edition), Electronic Industry Press, 2004.
[2] Wang Xiaoming, Single Chip Microcomputer Control of Electric Motor, Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.
[3] Wang Zhenglin et al. Process Control and Simulink Application, Electronic Industry Press, 2006.
[4] Nie Huiping, Solid Coriolis Flowmeter Measurement and Control System Based on ARM and uCOS-II, Microcomputer Information, 2005, Vol. 21, No. 7-2.

Keywords:atmega32 Reference address:Research on PID and PWM liquid flow control system based on AVR microcontroller atmega32

Previous article:Atmega32 MCU serial port driver
Next article:ATMEGA32 microcontroller controls stepper motor program

Recommended ReadingLatest update time:2024-11-16 00:48

Based on stc12pwm wave
#include #include #define FOSC 110592000L//This is long type data, 11.0595mhz typedef unsigned char BYTE; typedef unsigned int WORD; sfr CCON = 0xD8; sfr CMOD = 0xD9; sfr CCAP0L = 0xEA; //The lower 8 bits of the capture/compare register of PCA module 0. 0000,0000 sfr CCAP0H = 0xFA; sfr CL = 0xE9; //PCA c
[Microcontroller]
Share two methods of STC15 timer simulating PWM
I just searched and found that there is no post analyzing PWM in this way in the forum, so I posted one. Flashlight LED control or motor speed control cannot do without PWM. Here are two methods to simulate PWM. If it is not correct, I hope you can give me some advice.     //Use timer loading to simulate PWM. This m
[Microcontroller]
Share two methods of STC15 timer simulating PWM
STM32 receives serial port data and outputs PWM
#include #include "sys.h" #include "usart.h" #include "delay.h" #include "led.h"  #include "key.h" #include "exti.h" #include "wdg.h" #include "timer.h" #include "string.h"   //Mini STM32 development board example code 8 //PWM output experiment //Atom on point @ALIENTEK //Technical forum: www.openedv.com    //#def
[Microcontroller]
STM32F407 About TIM1 output PWM
Enable OCx output through the combination of CCxE, CCxNE, MOE, OSSI and OSSR bits (TIMx_CCER and TIMx_BDTR registers). In fact, the MOE and AOE bits of the TIMx_BDTR register need to be set to 1. This is different from the normal configuration of PWM output. The code is as follows↓ /***********************************
[Microcontroller]
ATmega32 Standby Mode
Standby mode When SM2..0 is 110, the SLEEP instruction will put the MCU into Standby mode. The only difference between this mode and Power-down mode is that the oscillator continues to work. The wake-up time only takes 6 clock cycles. Extended Standby mode When SM2..0 is 111, the SLEEP instruction will put the MCU
[Microcontroller]
ATmega32 Standby Mode
STM32F103_TIM3 outputs PWM wave to realize full-color breathing light
1. LED lights 1. Must be full-color RGB_LED light 2. 256 colors are mixed by different red, green and blue LEDs, which is the same as the color mixing RGB888 in computer drawing. Each light uses 8 bits to control its brightness, and all lights off represent black. two, 1. LED brightness level table /* LED br
[Microcontroller]
Freescale Smart Car--A Simple Introduction to Fuzzy PID Algorithm
Before explaining fuzzy PID, we must first understand the principle of PID controller (this article mainly introduces the application of fuzzy PID, and does not introduce the principle of PID controller in detail). PID controller (proportional-integral-differential controller) is a common feedback loop component in in
[Microcontroller]
Freescale Smart Car--A Simple Introduction to Fuzzy PID Algorithm
Discussion on the distortion of pwm signal passing through pc817b optocoupler
OK, now we discuss the problem of PWM waveform distortion after passing through the pc817b optocoupler. As shown below: Circuit diagram of distortion after passing through the optocoupler Waveform diagram of distortion after passing through the optocoupler OK, the above is the problem, now we start to discuss and
[Analog Electronics]
Discussion on the distortion of pwm signal passing through pc817b optocoupler
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号