# Realization of PID temperature control

Source: Internet
Author: User
realization of PID temperature control

Introduction to PID
PID (proportional Integral derivative) control is a control strategy which is mature and widely used in control engineering, and after long-term engineering practice, a complete set of control methods and typical structures have been formed. It is not only suitable for the control system known in the mathematical model, but also can be applied to the industrial process which is difficult to be determined by most mathematical models, and has achieved satisfactory application effect in many industrial process control.
PID work rationale: Due to the various disturbances from outside the continuous production, to achieve the field control object value to maintain a constant goal, the control role must be constantly carried out. If the disturbance occurs in the field control object value (hereinafter referred to as the controlled parameter) changes, the field detection element will be collected after the change of the transmitter to the PID controller input, and its given value (hereinafter referred to as SP value) to compare to get the deviation value (hereinafter referred to as the E value), The regulator according to this deviation and with our pre-set parameter control rules issued control signal, to change the regulator's opening, so that the regulator's opening increase or decrease, so that the field control object value change, and tend to the given value (SP value) to achieve control purposes, as shown in Figure 1, in fact, the PID The essence is the deviation (e value) proportional, integral, differential operation, according to the results of the operation of the process of controlling the implementation of the part.

Fig. 1 schematic diagram of analog PID control system
The control law of PID controller can be described as:
(1)
The proportional (P) control can quickly react to errors, thereby reducing the steady-state error. However, proportional control does not eliminate steady-state errors. The increase of the proportional magnification factor will cause the instability of the system. Integral (I) control function is: As long as the system has an error, the integration controller is constantly accumulating, output control amount, to eliminate the error. Therefore, as long as there is enough time, the integral control will be able to completely eliminate the error, the system error is zero, thereby eliminating the steady state error. The integral effect is too strong will make the system overshoot, and even make the system oscillation. The differential (D) control can reduce overshoot, overcome oscillation, improve the stability of the system, speed up the dynamic response speed of the system, reduce the adjustment time, and improve the dynamic performance of the system. According to the control characteristics of different controlled objects, it can be divided into different control models such as P, PI, PD, PID and so on.

Realization of digital PID
In the continuous-time control system (analog PID control system), the PID controller is widely used. Its design technology is mature, has formed a typical structure for a long time, the parameter setting is convenient, the structure changes flexibly, can satisfy the general control requirement. With the rapid development of computer, the computer is introduced into the field of PID control, and digital PID control appears.
Because the computer is based on the sampling control theory, the calculation method can not follow the traditional simulation PID control algorithm (as shown in Equation 1), so the control model must be discretized, the discretization method: T is the sampling period, K is the sampling sequence number, the form of summation instead of integral, in the form of increment (seeking difference) instead of differential, This allows the continuous calculation of the PID formula to be discrete:
(2)
Type 1 can be discrete as:
(3)
Or:
(4)
This can allow the computer or single-chip to achieve PID control by sampling, the specific PID control is divided into position PID control and incremental PID control, Formula 4 gives the total size of the control, so called full-scale or position-type control; If the computer only calculates the adjacent two times, Only consider on the previous basis, the size of the output of the computer changes, rather than the calculation of all output information, this control is called the incremental PID control algorithm, the essence is to seek the size of δμ, and Δμk =μk-μk-1; So the formula 4 does the self-subtraction transformation:
(5)
which

design of PID algorithm for temperature control
This design uses the position-based PID algorithm described above, the temperature sensor sampling input as the current input, and then subtract the deviation from the set value Ek, and then the PID operation to produce the output fout, and then let the Fout control timer time to control the heater. In order to facilitate the PID operation, we first establish a PID structure data type, which is used to save the p, I, D coefficients, and the set values, the accumulation of historical errors and other information needed for the PID operation:

typedef struct PID
{
float SetPoint; Set Target desired Value
float proportion; Scale factor Proportional Const
float Integral; Integral coefficient Integral Const
float derivative; Differential coefficients derivative Const
int lasterror; Last deviation
int sumerror; Historical Error Cumulative value
} PID;
PID Stpid; Define a Stpid variable

The following is the PID arithmetic program, the PID operation returns the value of Fout,fout determines whether heating, heating time is how much.
The C implementation code of the PID operation:

Float Pidcalc (PID *pp, int nextpoint)
{
int derror,error;
Error = pp->setpoint*10-nextpoint; deviation, set value minus current sample value
Pp->sumerror + = Error; Integral, historical deviation accumulation
Derror = error-pp->lasterror; Current differential, deviation subtraction
Pp->preverror = pp->lasterror; Save
Pp->lasterror = Error;
+ pp->integral * Pp->sumerror//Points
-Pp->derivative * derror//Differential term
);
}

In the actual operation, because the water has a great thermal inertia, and the PID operation of I (integral term) has a very obvious delay effect so can not be preserved, we must remove the integral term, but the D (differential term) has a strong predictability, can speed up the reaction speed, suppress overshoot, Therefore, the integral function should be properly strengthened to achieve a better control effect, the system finally selects the PD control scheme, the following C code shows the implementation process of PD control:

Float Pidcalc (PID *pp, int nextpoint)
{
int derror,error;
Error = pp->setpoint*10-nextpoint; deviation, set value minus current sample value
Derror = error-pp->lasterror; Current differential, deviation subtraction
Pp->preverror = pp->lasterror; Save
Pp->lasterror = Error;
Return (Pp->proportion * Error//scale item
-Pp->derivative * derror//Differential term
);
}

Temperature Control Implementation
Through the temperature of the PID operation, the result is fout, the parameter determines whether heating, heating time is how long. The program is as follows:

Stpid.proportion = 2; Setting the PID scale value
stpid.integral = 0; Set the PID integral value
Stpid.derivative = 5; Set PID Micro-score
FOut = Pidcalc (&stpid, (int) (FT*10)); PID calculation
if (fout<=0)
*p_ioa_buffer &= 0xff7f; Temperature above setpoint, heater off
Else
*p_ioa_buffer |= 0x0080; Temperature below the set value, open the heater

The heating time is calculated by the main function and controlled by the Timerb interrupt. The Fout parameter is obtained through the PIDCALC function in the main program, and if the parameter is greater than "0", the heater is turned on. IRQ2_TMB interrupts are in the allowed state, each entering a IRQ2_TMB interrupt, the FOut parameter minus 1 until FOut = 0, stop heating. If the PIDCALC calculation results are larger than the target temperature difference, then the heating time is relatively long, if the calculation results are relatively small, the temperature difference from the target is smaller, the heating time is relatively short.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.