FB_TemperaturePID
Description
This function block provides PID"Proportional-Integral-Derivative" A PID controller is a generic control-loop feedback mechanism widely used in industrial control systems. An "error" occurs when an event or a disturbance triggers off a change in the process variable. A PID controller attempts to correct the error between a measured process variable and a desired setpoint by calculating and then outputting a corrective action that can adjust the process accordingly temperature control with auto tuning.
Figure 8-232: The TemperaturePID user-defined function block
Arguments
Inputs
iEN | BOOL | Enable function |
iREFTEMP | LREAL | Reference temperature [°C] |
iTEMP | LREAL | Actual temperature [°C] |
iSTART | BOOL | Start PID or auto tuning |
iMODE | BOOL | FALSE-automatic, TRUE-tuning |
iKP | LREAL | PID Proportional Gain |
iKI | LREAL | PID Integral Gain |
iKD | LREAL | PID Derivative Gain |
iTC1S | BOOL | Sampling Time is 1s |
iTC5S | BOOL | Sampling Time is 5s |
iPROGCYCLE | LREAL | Execution time of the function [ms] |
Outputs
oOK | BOOL | FunctionA function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. enabled |
oCHECKSTABLE | BOOL | TRUE when checking if ambient temperature is stable |
oTUNESTART | BOOL | Tuning is started |
oTUNEOK | BOOL | Tuning is completed |
oTAU | LREAL | System Time Constant[s] |
oPWM | BOOL | PWM command for heater |
oERR | BOOL | Function error |
oERRID | INT | Function ID error (in case of oERR=TRUE) |
oPOWER | LREAL | % of power requested from heater (100%=full power) |
oTICK | BOOL | PulseWhen the step gets activated, the action is activated for a single execution, and possibly once again when the step is deactivated every sampling time |
Usage
Tuning Process
Tuning consists of three steps.
- Check if the ambient temperature is stable: the measured delta_temp=Tmax-Tmin must be lower than 0.1*Tmax.
This step takes 10 cycles (10*iTC5s
or10*iTC1s
).
The tuning fails (oERR=TRUE, oERRID=1
) if the ambient temperature is greater than 0.1*Tmax, otherwise Tamb=(Tmax+Tmin)/2. - Start tuning Phase1: output oPWM is kept TRUE until the final measured temperature iTEMP gets over iREFTEMP/2. After that oPWM is kept LOW.
- Start tuning Phase2: with oPWM kept LOW the temperature gets down until the final value is lower than
[(iREFTEMP/2-Tamb)*0.368+Tamb]
.
After, PID gains are calculated as:
Kp=10
Ki=0.14
delta_time = time to complete Phase2 Kd=SQRT(delta_time)*7
The tuning is completed.
-
-
oTAU may be useful for setting the proper sampling time (1s or 5s).
Start PID Controller
Upon starting the PID controller, the output oPWM is modulated 5 times within the sampling time (blue line is oTICK, green line is oPWM) and each pulse length depends on output oPOWER (100%=full length).
Example
ST
//Run PID function with determined proportional, integral, and derivative gains
//send PWM output to command heater
udfbThPID( TRUE, 90, Temp_mes, TRUE, FALSE, KP, KI, KD, FALSE, TRUE, 1);
Tau_Calculated := udfbThPID.oTAU;
PWM_CMD := udfbThPID.oPWM;
Power := udfbThPID.oPOWER;
Tick := udfbThPID.oTICK;
FBD
FFLD