FB_TemperaturePID

 Function Block - Provides PID temperature control with auto tuning.

Inputs

Input

Data Type

Range

Unit

Default

Description

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

Output

Data Type

Range

Unit

Description

oOK

BOOL

 

 

Function 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 Constants.

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

 

 

Pulse every sampling time.

Remarks

Figure 1: FB_TemperaturePID

Usage

Tuning Process

Figure 2: FB_TemperaturePID Usage 1

Tuning Procedure

  1. Verify 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 or 10*iTC1s).
    The tuning fails (oERR=TRUE, oERRID=1) if the ambient temperature is greater than 0.1*Tmax, otherwise Tamb=(Tmax+Tmin)/2.
  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.
  3. 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

Figure 3: FB_TemperaturePID Usage 2

  • When starting the PID controller:
    • The output oPWM is modulated five times within the sampling time (blue line is oTICK, green line is oPWM).
    • Each pulse length depends on output oPOWER (100%=full length).

Figure 4: FB_TemperaturePID Usage 3

FBD Language Example

FFLD Language Example

IL Language Example

Not available.

ST Language Example

//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;