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.

69 lines
1.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<POU Name="SCALE_R" Id="{25a95851-a5ac-4c3a-83d0-6d0841537cfe}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION SCALE_R : REAL
VAR_INPUT
X : REAL;
I_LO : REAL;
I_HI : REAL;
O_LO : REAL;
O_HI : REAL;
END_VAR
VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[(*
version 1.2 11. jan. 2011
programmer hugo
tested by oscat
Scale_R is used to translate and scale a REAL input x to a real output.
the input is limited to I_LO <= X <= I_HI.
Type Function: REAL
Input X: REAL (input)
I_LO: REAL (min input value)
I_HI: REAL (max input value)
O_LO: REAL (min output value)
O_HI: REAL (max output value)
Output REAL (output value)
SCALE_R scales an input value REAL and calculates an output value in
REAL. The input value X is limited here to I_LO and I_HI.
SCALE_D(IN,4,20,0,100) scales an input with 4 .. 20mA to the output 0..100.
SCALE_R can also be negative output values and work with a negative slope, the values I_LO and I_HI but must always be specifed that ILO < I_HI.
*)
IF I_LO = I_HI THEN
SCALE_R := O_LO;
ELSE
SCALE_R := (O_HI - O_LO) / (I_HI - I_LO) * (LIMIT(I_LO, X, I_HI) - I_LO) + O_LO;
END_IF;
(* revision history
hm 18. may. 2008 rev 1.0
original version
hm 13. nov. 2008 rev 1.1
corrected formula for negative gradient
hm 11. jan 2011 rev 1.2
avoid division by 0
*)]]></ST>
</Implementation>
<LineIds Name="SCALE_R">
<LineId Id="13" Count="6" />
<LineId Id="38" Count="0" />
<LineId Id="40" Count="9" />
<LineId Id="52" Count="0" />
<LineId Id="51" Count="0" />
<LineId Id="20" Count="0" />
<LineId Id="7" Count="0" />
<LineId Id="22" Count="14" />
<LineId Id="21" Count="0" />
<LineId Id="37" Count="0" />
</LineIds>
</POU>
</TcPlcObject>