Hi srd,
I have now tested the code, and a division-by-zero error did not occur. The minimum flow rate for the calculation is 0.1 m³/h.
Please note that at very low flow rates, the update of the measured value may take a significant amount of time, as the calculation is only performed upon receipt of a pulse. This is a technical constraint that cannot be changed.
If the interval between pulses exceeds 360 seconds, the result is set to zero.
//Timer for pulse generation (for simulation only)
T02 (
EN := I01,
RE := T02Q1,
ST := ,
I1 := IA01 *100, //adjustable time at IA01
I2 := ,
Q1 => ,
QV => );
//This calculation is for a maximum flow rate of 360 m³/h (10 Hz pulse).
//and minimum 0.1 m³/h -> 1 pulse every 360 s
ED01 (
EN := ,
I1 := T02Q1, //pulse
Q1 => );
T01 (
EN := true,
RE := M01,
ST := ,
I1 :=T#900s000ms,
I2 := ,
Q1 => ,
QV => );
M01:=FALSE;
//Flow approaches zero
//If the interval between pulses exceeds 360 seconds, the result is set to zero.
M02:=T01QV >= 360000;
IF M02 THEN
MD20:=0;
MD21:=0;
MD22:=0;
MD23:=0;
M01:=TRUE; //resert timer;
END_IF;
IF ED01Q1 and not M02 THEN
MD22:=MD21;
MD21:=MD20;
MD20:=T01QV;
MD23:= (MD20 + MD21 + MD22)/3; //Averaging of the times over 3 pulses in ms
MD24:= 36000000 / MD23;//result in l/h
M01:=TRUE; //resert timer
END_IF;
MD25:= MD24 / 1000;//result in m³/h
//You cannot pass the result from MD24 directly to LS01, as this will cause an overflow.
//max input is 16bit
//scale to 4-20mA
LS01 (
EN := true,
I1 := (MD24 / 100), //0.1 m³/h
X1 := 0,
Y1 := 819,
X2 := 3600,
Y2 := 4095,
QV => QA05);
Thomas