PID processing instruction
The PID processing instruction is used to regulate a process (e.g. a heater) given a measured value (e.g. temperature) and a predetermined output value (e.g. 20°C).
Input
Detailed explanation of parameters, please refer to PID_DUT_31
Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_PID_BASIC
The function calculates a PID algorithm whose parameters are determined in a data table in the form of an ARRAY with 30 elements that is entered at input s.
if the parameter settings are outside the permissible range
if the parameter settings are outside the permissible range
In the global variable list you define variables that can be accessed by all POUs in the project.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR_EXTERNAL
EnableAutoTuning: BOOL:=FALSE;
(*Switch Auto Tuning On *)
Set_Value_SP: WORD:=0;
(*A/D CH0*)
Process_Value_PV: WORD:=0;
(*A/D CH1*)
Output_Value_MV: WORD:=0;
(*D/A*)
END_VAR
VAR
PidParameters: PID_DUT_31;
(*PID Parameters*)
END_VAR
In the initialization of the variable PidParameters of the data type PID_DUT_31, the MV upper limit is set to 4000. The proportional gain Kp is initially set at 80 (8), Ti and Td at 200 (20s) and the sampling time Ts at 100 (1s).
The standard function MOVE copies the value 16#8000 to the member Control of the DUT PidParameters when the variable EnableAutoTuning turns from FALSE to TRUE (i.e. activates the control mode auto-tuning in the function F355_PID_DUT).
The variables Set_Value_SP and Process_Value_PV are assigned to the members SP and PV of the DUT PidParameters. They receive their values from the A/D converter channel 0 and 1.
Because the F355_PID_DUT function block has an EN output connected directly to the power rail, the function is carried out when the PLC is in RUN mode. The calculated controller output stored by the member MV of the DUT PidParameters is assigned to the variable Output_Value_MV. Its value is returned via a D/A converter from the PLC to the output of the system.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,E_MOVE,,10,2,17,6,,?DEN?Da_Num?AENO?C);
B(B_VAROUT,,PidParameters.Control,17,4,19,6,);
B(B_VARIN,,16#8000,8,4,10,6,);
B(B_CONTACT,,EnableAutoTuning,5,3,7,5,R);
B(B_COMMENT,,Enable Auto Tuning,2,1,12,2,);
L(1,4,5,4);
L(7,4,10,4);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_VARIN,,Set_Value_SP,9,2,11,4,);
B(B_VAROUT,,PidParameters.SP,11,2,13,4,);
B(B_COMMENT,,Fill the DUT PID_DUT_31 with the corresponding values,2,1,24,2,);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 2 ;
NETWORK_BODY
B(B_VARIN,,Process_Value_PV,9,0,11,2,);
B(B_VAROUT,,PidParameters.PV,11,0,13,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_VARIN,,PidParameters,8,5,10,7,);
B(B_F,F355_PID_DUT!,Instance,10,3,18,7,,?DEN?D@'s'?AENO);
B(B_COMMENT,,Carry out the PID arithmetic,2,1,21,2,);
L(1,5,10,5);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_VARIN,,PidParameters.MV,9,2,11,4,);
B(B_VAROUT,,Output_Value_MV,11,2,13,4,);
B(B_COMMENT,,Write manipulated value to the output,2,1,21,2,);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
END_BODY
(* Auto Tuning: *)
if DF(EnableAutoTuning) then
PidParameters.Control:=16#8000;
end_if;
(* Fill the DUT PidParameters with the corresponding input values: *)
PidParameters.SP:=Set_Value_SP;
PidParameters.PV:=Process_Value_PV;
(* Carry out the PID arithmetic: *)
F355_PID_DUT(PidParameters);
(* Write the manipulated value to the output: *)
Output_Value_MV:=PidParameters.MV;