带pid算法的程序2(Program with PID algorithm 2)
带pid算法的程序2(Program with PID algorithm 2)
PID temperature control algorithm for C language
1. PID debugging steps
Without a control algorithm than PID regulation is more effective and more convenient. Now some fashionable point basic regulator from PID. Even we can say: PID regulator is the other control algorithm.
Why PID is so widely used and enduring?
Because the basic problem is solved by PID control theory to solve the stability, rapidity and accuracy of the system is. Adjusting the parameters of PID, can realize the premise of system stability, taking into account the system load ability and anti disturbance ability, at the same time, the PID regulator is introduced in the integral item system adds a zero point, make it become a first-order system, the steady-state error of the step response of the system it is zero.
The automatic control system of the controlled object vary, PID parameters must also change, in order to meet the requirements of the performance of the system. This will bring considerable trouble to users, especially for beginners. Following a brief general steps of debugging PID parameters:
1. negative feedback
Automatic control theory is also called negative feedback control theory. First check system wiring, determine the system
feedback negative feedback. For example, the motor speed control system, the input signal is required, the motor is transferred, the feedback signal is positive (PID algorithm, error = input feedback), and the higher the motor speed, the greater the feedback signal. The rest of the system with this method.
The general principle of 2.PID debugging
A. in the output oscillation, increasing the proportional gain of P.
B. in the output oscillation, reduce the integral time constant Ti.
C. in the output oscillation, increase the differential time constant Td.
3. general steps
A. determines the proportional gain P
To determine the proportional gain P, remove the integral and differential PID first, Ti=0, Td=0 (general is to see specific PID parameters, the PID control instructions) for the pure proportion. The input set for the system to allow the maximum value of the 60%~70%, by 0 gradually increase the proportion of P gain, until the system oscillation; in turn, the proportional gain decreases gradually from P, until the system oscillations disappear, record the proportional gain P at this time, P PID set the proportional gain for the value of 60%~70%.
The proportional gain P debugging.
B. determine the integral time constant Ti
The proportional gain P is determined, the initial value setting a larger integration time constant Ti, and decreases with the increase of Ti, until the system oscillation, in turn, gradually increase the Ti, until the system oscillations disappear. Record the Ti Ti PID, set the integral time constant for the current value of 150%~180%. The integral time constant Ti debugging.
C. determine the integral time constant Td
The integral time constant Td is generally not set for 0. If you want to set the same, and method of determining P and Ti, not the 30% oscillation.
D. system load, load transfer, and then fine tune the PID parameters, to meet the requirements.
2.PID control.
At present the level of industrial automation has become an important symbol to measure the level of modernization in all walks of life. At the same time,
The control theory developed from classical control theory, modern control theory and intelligent control theory in three stages. A typical example is the fuzzy intelligent control of automatic washing machine etc.. The automatic control system
can be divided into open-loop and closed-loop control systems. A control system includes a controller, sensors, transmitters, actuators, input and output interface. The controller output through the output interface actuator to controlled system; the amount charged control system through the sensor, transmitter, through the input interface to the controller. Different control system, the sensor, transmitter, actuator is not the same. For example, the pressure control system to use pressure sensor. The electric heating control system sensor is a temperature sensor. At present, PID control and intelligent PID controller or controller (instrument) has a lot of products have been widely used in engineering practice, a wide variety of products PID controller, the major companies have developed a PID parameter self-tuning regulatorfunction smart regulator (intelligent regulator), which automatically adjust the parameters of PID controller is realized through intelligent adjustment or self correction, adaptive algorithm. The use of PID control to realize the pressure, temperature, flow, liquid level controller, programmable controller can realize the control functions of PID (PLC), and can realize PC control PID system and so on. The programmable controller (PLC) is the control module to realize the closed-loop control by using PID, and programmable logic controller (PLC) can be directly connected with the ControlNet, such as Rockwell PLC-5 etc.. The controller and can realize the control functions of PID, such as Rockwell Logix series, it can be directly connected with the ControlNet, to realize the remote control function by using network.
1, the open loop control system
Open loop control system (open-loop control system) is refers to the output of the controlled object (controlled volume) of the controller (controller) did not affect the output. In this control system, does not depend on the volume will be charged back to the formation of anti any closed loop.
2, the closed-loop control system
The closed loop control system (closed-loop control system) is characterized by the output system object (controlled volume) will be sent back to impact the output of the controller, forming one or more closed loop. The closed loop control system with positive and negative feedback, if the feedback signal and the system for a given value of signal contrast is called negative feedback (Negative Feedback), if the same polarity is called positive feedback, the general closed-loop control system with negative feedback, also known as negative feedback control system. Many examples of the closed-loop control system. Such person is a closed-loop control system with negative feedback, the eye is the sensor as feedback, the human body system through the amendment to all the right moves last. If there is no eyes, no feedback loop will become an open loop control system. Another example, when a truly automatic washing machine has to continuously check whetherclothes washed and cut off the power automatically after cleaning, it is a closed loop control system.
3 step response
Step response is a step input (step function) when added to the system, the output of the system.
The steady-state error is the response of the system into a steady state, poor expected output and actual output of the system. With a steady, fast three words to describe the performance of the control system can be. Stability refers to the stability of the system (stability), a system must be able to work, must first be stable, the step response appears to be convergent; quasi refers to the accuracy, control accuracy, steady state error (Steady-state error), it said the system steady-state output value and the expected value of the difference; fast control system refers to the rapid response, usually used to quantitatively describe the rise time.
The principle and characteristics of 4 PID control
In engineering practice, the regulator control law isproportional integral differential control widely, referred to as PID control, also known as PID regulator. The PID controller has been nearly 70 years of history, with its simple structure, good stability, reliable operation, convenient adjustment and become one of the main technologies in industrial control. When fully grasp the structure and parameters of the controlled object can not, or not accurate mathematical model, control theory is difficult to use other technologies, the structure and parameter of the controller must rely on experience and on-site testing to determine the application of PID control technology is the most convenient. That is when we do not fully understand a system and the controlled object, or cannot obtain system parameters through effective means of measurement, the most suitable PID control technology. PID control, in practice there are PI and PD control.
The PID controller is based on the error, using proportional integral differential control of the calculated volume control.
The proportion of control (P)
Proportional control is one of the most simple way of control. The controller output and the input error signal proportional. When only the proportional control system output steady-state error (Steady-state error).
Integral (I) control
In the integral control, the controller output and input error signal proportional to the integral of the relationship. An automatic control system, if there is the steady-state error in steady state, the control system is called with steady state error system (System with Steady-state Error). In order to eliminate the steady-state error, the controller must introduce the integral term". Integral of the error depends on the time, with the increase of time integral increases. So, even if the error is very small, the integral term will increase with the increase of time, it is to promote the output of the controller increases to further reduce the steady-state error until zero. Therefore, the proportion + integral (PI) controller can make the system without steady-state error to enter steady state.
Differential (D) control
In the differential control, the controller output and
differential input error signal (i.e. the error is proportional to the change rate). The automatic control system may be unstable or even oscillation overcome the errors in the adjustment process. The reason is because there is a large inertia component (link) or backward (delay) components, inhibit the role of error, the change is always behind the error. The solution is to inhibit the role of error change "in advance", which is close to zero in the error, inhibit the role of error should be zero. That is to say,
The controller only introduced quotratioquot is often not enough, the proportion of the role is only to enlarge the amplitude error, and now need to increase the "differential", it can change the trend of prediction error, in this way, with the proportion of + differential controller, it can advance the control action is equal to the error suppression zero, or even negative, so as to avoid the amount charged with a serious overshoot. So a greater inertia of the object or delay, the proportion + differential (PD) controller can dynamic characteristics in the process of adjustment to improve the system.
5, the parameter setting of PID controller
PID controller parameter tuning control system design is the core content. It is based on the characteristics of the controlled process to determine the proportional coefficient, PID controller integration time and the size of the time differential. A lot of PID controller parameter tuning method, summed up in two categories: firsttuning the theoretical calculation. It is mainly based on the mathematical model,
through theoretical calculations to determine the parameters of the controller. This method the calculated data may not be directly used, also must adjust and revise engineering. The two is the tuning method works, it mainly depends on the engineering experience, directly in the control test system, and the method is simple and easy to grasp, is widely used in engineering practice. PID controller parameter tuning method works, mainly the critical ratioreaction curve and attenuation method. The three methods have their own characteristics through their common test, then according to the engineering experience formula of controller parameter tuning. But no matter what kind of controller parameters obtained by the method, are needed in the actual operation of the final adjustment and improvement. Now commonly used is the critical ratio method. The whole process of PID controller parameters using the method given as follows: (1) first pre select a short sampling period for the system; (2) only with proportional control link, until the system step response input critical oscillation, the ratio of down time amplification coefficient and critical oscillation period; (3) parameters in a certain degree of control by formula PID controller.
The 3.PID controller parameters tuning, regulation system can refer to the following parameters of empirical data PID:
T: P=20~60% T=180~600s, D=3-180s temperature.
P: P=30~70%, T=24~180s,
The level of L: P=20~80%, T=60~300s,
The flow of L: P=40~100%, T=6~60s.
4. commonly used PID formula:
To find the optimal parameter setting, check the order from small to great
The first is the ratio of integrals, and finally the differential increase
The oscillation curve is very frequent, the proportion of the dial to zoom
Floating around the curve of Grand Bay, dial to pull small proportion
The curve deviates from the slow recovery, the integration time to drop
The fluctuation cycle is long, the integration time longer
The oscillation frequency curve quickly, put down the differential
Moment to slow wave. Differential time should be lengthened
The ideal curve two wave, high to 4 lower than 1
A look at two more analysis, quality of regulation is not low
#include
#include
#include
#include
Struct {PID
Unsigned int SetPoint;
/ /设定目标期望值
unsigned int型的比例;/ /比例常数比例常数
unsigned int积分;/ /积分常数积分常数
unsigned int衍生物;// const微分常数衍生物
unsigned int LastError;//错误[ 1 ]
unsigned int preverror;//错误[ 2 ]
unsigned int sumerror;/ /和错误
};
结构PID SPID;/ / PID控制结构
unsigned int击溃;/ / PID的响应(输出)
unsigned int凛;/ / PID反馈(输入)
公司^ data1 = P1 0;
普通时钟= P1 ^ 1;
普通加= P2 ^ 0;
普通潜艇= P2 ^ 1;
公司停止= P2 ^ 2;
普通输出= P3 ^ 4;
公司^ DQ,P3 3;
unsigned char的旗帜,flag_1 = 0;
unsigned char high_time,low_time,数= 0;//占空比调节参数
unsigned char set_temper = 35;
unsigned char的脾气;
unsigned char我;
unsigned char j = 0;
unsigned int的;
/
***********************************************************
延时子程序,延时时间以12m晶振为准,延时时间为30us×时间
*********************************************************** /
延时(unsigned char的时间)
{
unsigned char m,n;
对于(n = 0;n,时间;n + +)
对(M = 0;M,2;M + +){ }
}
/
***********************************************************
写一位数据子程序
*********************************************************** /
无效write_bit(unsigned char bitval)
{
EA = 0;
DQ = 0;/*拉低DQ以开始一个写时序*/
如果(bitval = = 1)
{
_nop_();
DQ = 1;/*如要写1,则将总线置高*/
}
延迟(5);/*延时90us供da18b20采样*/
DQ = 1;/*释放DQ总线*/
_nop_();
_nop_();
EA = 1;
}
/
***********************************************************
写一字节数据子程序
*********************************************************** /
无效write_byte(unsigned char Val)
{
unsigned char我;
unsigned char温度;
EA = 0;
tr0 = 0;
为(i = 0;i < 8;i++)/ * * /写一字节数据,一次写一位
{
温度= val > >我;/ *移位操作,
This will be written to the lowest secondary displacement.
Temp=temp&1;
Write_bit (Temp); / * * / write this bit to the bus
}
Delay (7); / * * / delay 120us
/ / TR0=1;
EA=1;
}
/**********************************************************
*
Read a data subprogram
***********************************************************
/
Unsigned char (read_bit)
{
Unsigned char I, value_bit;
EA=0;
DQ=0; / * low DQ, and began to read the sequence.
(_nop_);
(_nop_);
DQ=1; / * * / bus release
For (i=0; i<2; i++) {}
Value_bit=DQ;
EA=1;
Return (value_bit);
}
/**********************************************************
*
Read a byte data subprogram
***********************************************************
/
Unsigned char (read_byte)
{
Unsigned char I, value=0;
EA=0;
For (i=0; i<8; i++)
{
(if) (read_bit) / * read a byte of data, a sequential read once,
and shift.
Value|=0x01< > 4;
Temper | J = I; / * * / 获取的温度放在temper中
}
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Initialize PID structure
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * /
Void (* pp pidinit struct PID)
{
Memset (PP, 0, sizeof (struct PID));
}
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Pid计算部分
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * /
Unsigned int (* pp pidcalc struct PID, unsigned int nextpoint)
{
Unsigned int derror, error;
PP - > Error = - / / 偏差 nextpoint setpoint;
PP - > sumerror + = error; / / 积分
Derror = PP PP lastError - > - > preverror; / / 当前微分
Preverror = PP PP - > - > lastError;
PP - > lastError = error;
Return (PP - > * / / 比例项 proportion error
+ * PP PP - > - > integral sumeror / / 积分项
+ * - > PP derivative derror); / / 微分项
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * *
温度比较处理子程序
* * * * * * * * * * * * * * * * * * * * * * * * * * * /
Compare _ (Temper)
{
Unsigned char I;
If (> Set _ Temper Temper)
{
If (set _ Temper temper - > 1)
{
High _ time = 100;
Low _ time = 0;
}
Else
{
For (i = 0; I < 10; I + +)
_ Temper () {get;
Rin = S; / / read input
Rout (& SPID = pidcalc Rhine); / / perform PID interation
}
如果(high_time < = 100)
high_time =(char)(路线800);
其他的
high_time = 100;
low_time =(100-high_time);
}
}
如果(set_temper <=脾气)
{
如果(temper-set_temper > 0)
{
high_time = 0;
low_time = 100;
}
其他的
{
为(i = 0;i < 10;i++)
{ get_temper();
Rin = S;/ /读取输入
击溃= pidcalc(和SPID,RIN);//执行PID迭代
}
如果(high_time,100)
high_time =(char)(路线10000);
其他的
high_time = 0;
low_time =(100-high_time);
}
}
/ /其他
/ { }
}
/ *****************************************************
T0中断服务子程序,用于控制电平的翻转,40us * 100 = 4ms周期
****************************************************** /
无效serve_t0()中断1使用1
{
如果(+ +计数< =(high_time))
输出= 1;
如果(count <= 100)
{
输出= 0;
}
其他的
数= 0;
TH0 = 0x2F;
TL0 = 0xE0;
}
/ *****************************************************
串行口中断服务程序,用于上位机通讯
****************************************************** /
无效serve_sio()中断4使用2
{
/ * EA = 0;
Ri = 0;
我= SBUF;
如果(我= = 2)
{
而(RI = = 0){ }
Ri = 0;
set_temper = SBUF;
SBUF = 0x02;
而(TI = = 0){ }
Ti = 0;
}
如果(我= = 3)
{
Ti = 0;
SBUF =脾气;
而(TI = = 0){ }
Ti = 0;
}
EA = 1;* /
}
无效disp_1(unsigned char disp_num1 [ 6 ])
{
unsigned char N,A,M;
对于(n = 0;n,6;N + +)
{
/ / K = disp_num1 [N].;
为(A = 0;< 8;+ +)
{
时钟= 0;
M =(disp_num1 [N]和1);
disp_num1 [n] = disp_num1 [N] > > 1;
如果(M = = 1)
1 = 1;
其他的
1 = 0;
_nop_();
时钟= 1;
_nop_();
}
}
}
/ *****************************************************
显示子程序
功能:将占空比温度转化为单个字符,显示占空比和测得到的温度
****************************************************** /
无效display()
{
无符号字符代码[ ] = { 0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,
0xe0,0xfe,0xf6 };
unsigned char disp_num [ 6 ];
unsigned int k,k1;
K = high_time;
K = K % 1000;
K1 = K / 100;
如果(K1 = = 0)
disp_num [ 0 ] = 0;
其他的
disp_num [ 0 ] = 0x60;
K = K % 100;
disp_num [ 1 ] [ 10 ] =数K;
disp_num [ 2 ] [ 10 ] =数%;
K =脾气;
K = K % 100;
disp_num [ 3 ] [ 10 ] =数K;
disp_num [ 4 ] [ 10 ] =数k + 1;
disp_num [ 5 ] [ 10 ] =数量/;
disp_1(disp_num);
}
/
***********************************************************
主程序
***********************************************************
/
main()
{
unsigned char z;
unsigned char a,b,flag_2 = 1,COUNT1 = 0;
unsigned char菲尔[ ] = { 2,0xce,0x6e,0x60,0x1c,2 };;
TMOD = 0x21;
TH0 = 0x2F;
TL0 = 0x40;
SCON = 0x50;
PCON = 0x00;
0xfd Th1 =;
0xfd TL1 =;
PS = 1;
EA = 1;
EX1 = 0;
ET0 = 1;
ES = 1;
tr0 = 1;
TR1 = 1;
high_time = 50;
low_time = 50;
PIDInit(和投资);//初始化结构
SPID。比例= 10;//设置PID系数
SPID。积分= 8;
SPID。导数= 6;
spid.setpoint = 100;//设置PID设定值
而(1)
{
如果(+ = = 0)
{
EA = 0;
for (a = 0; a < 5; a + +)
for (b = 0; b < 102; b + +) {}
if (plus = = 0)
{
seen _ temperate + +;
flag = 0;
}
}
else if (i = = 0)
{
for (a = 0; a < 5; a + +)
for (b = 0; a < 102; b + +) {}
if (i = = 0)
{
seen _ temper - -;
flag = 0;
}
}
else if (stop = = 0)
{
for (a = 0; a < 5; a + +)
for (b = 0; b < 102; b + +) {}
if (stop = = 0)
{
flag = 0;
break;
}
ea = 1;
}
get _ temper ();
b = temper;
if (flag _ 2 = = 1)
a = b;
if ((abs (a - b)) > 5)
temperate = a;
else
temperate = b;
a = temper;
flag _ 2 = 0;
if (+ + count1 > 30)
{
display ();
count1 = 0;
}
to compare _ temper ();
}
tr0 = 0;
z = 1;
while (1)
{
ea = 0;
if (stop = = 0)
{
for (a = 0; a < 5; a + +)
for (b = 0; b < 102; b + +) {}
if (stop = = 0)
disp _ 1 (phil);
/ / break;
}
ea = 1;
}
}
本文档为【带pid算法的程序2(Program with PID algorithm 2)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。