You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
XML
80 lines
2.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
|
|
<POU Name="CTRL_PID" Id="{72b5746a-41f6-4016-b19d-146ea4e1e3e0}" SpecialFunc="None">
|
|
<Declaration><![CDATA[FUNCTION_BLOCK CTRL_PID
|
|
VAR_INPUT
|
|
ACT : REAL; (* PV value measured by the way *)
|
|
SET : REAL; (* SP default Set Point *)
|
|
SUP : REAL; (* noise reduction *)
|
|
OFS : REAL; (* ofset for the output *)
|
|
M_I : REAL; (* MANUAL_IN (PID_OUT) input value for manual operation *)
|
|
MAN : BOOL; (* switch to manual mode, MANUAL = TRUE *)
|
|
RST : BOOL; (* asynchronous reset input *)
|
|
KP : REAL := 1.0; (* controller gain *)
|
|
TN : REAL := 1.0; (* reset of the controller *)
|
|
TV : REAL := 1.0; (* derivative of the controller *)
|
|
LL : REAL := -1000.0; (* lower output limit *)
|
|
LH : REAL := 1000.0; (* upper output limit *)
|
|
END_VAR
|
|
VAR_OUTPUT
|
|
Y : REAL; (* output OF the controller. In manual mode (manual = TRUE) is: Y = MANUAL_IN + OFFSET *)
|
|
DIFF : REAL; (* deviation *)
|
|
LIM : BOOL; (* TRUE if the output has reached a limit *)
|
|
END_VAR
|
|
VAR
|
|
pid : FT_PIDWL;
|
|
co : CTRL_OUT;
|
|
END_VAR
|
|
]]></Declaration>
|
|
<Implementation>
|
|
<ST><![CDATA[(*
|
|
version 2.0 30. jun. 2008
|
|
programmer hugo
|
|
tested by oscat
|
|
|
|
FT_PI is a PI controller with manual functionality.
|
|
The PID controller works according to the fomula Y = e *(KP+ KI * INTEG(e) ) + offset, while e = set_point - actual.
|
|
a rst will reset all internal data, while a switch to manual will cause the controller to follow the function Y = manual_in + offset.
|
|
limit_h and Limit_l set the possible output range of Y.
|
|
the output flags lim will signal that the output limits are active.
|
|
*)
|
|
|
|
DIFF := CTRL_IN(SET, ACT, SUP);
|
|
pid(in := DIFF, kp := KP, tn := TN, tv := TV, lim_l := LL, lim_h := LH, rst := RST);
|
|
co(ci := pid.Y, OFFSET := OFS, man_in := M_I, lim_l := LL, lim_h := LH, MANUAL := MAN);
|
|
Y := co.Y;
|
|
LIM := co.LIM;
|
|
|
|
(* revision history
|
|
|
|
hm 1.12.2006 rev 1.1
|
|
changed algorithm to trapezregel for higher accuracy.
|
|
|
|
hm 3.1.2007 rev 1.2
|
|
added integ_band to select when the integrator is active.
|
|
|
|
hm 3.3.2007 rev 1.3
|
|
added default values to inputs KP, TN, TV, LIMIT_L und LIMIT_H.
|
|
|
|
hm 31.oct 2007 rev 1.4
|
|
total rewrite of the module to avoid failures when one of the limits is 0
|
|
|
|
hm 3.11.2007 rev 1.5
|
|
added noise input to filter noise
|
|
added output diff
|
|
set limit output false when output is within limits
|
|
overfolw was not set correctly
|
|
|
|
hm 5. jan 2008 rev 1.6
|
|
improved code for better performance
|
|
*)]]></ST>
|
|
</Implementation>
|
|
<LineIds Name="CTRL_PID">
|
|
<LineId Id="25" Count="9" />
|
|
<LineId Id="36" Count="1" />
|
|
<LineId Id="39" Count="4" />
|
|
<LineId Id="46" Count="22" />
|
|
<LineId Id="9" Count="0" />
|
|
</LineIds>
|
|
</POU>
|
|
</TcPlcObject> |