Autor Thema: flow from pulse  (Gelesen 3669 mal)

Offline srd

  • Full Member
  • ***
  • Beiträge: 153
flow from pulse
« am: Oktober 29, 2026, 11:47:40 Vormittag »
Hi All, not sure if this is possible but i will ask anyway, if we have a pulse from a water meter doing 1 pulse every 10litres is it possible to convert this in to a flow (in m³) to give a 4-20mA out put.

Offline radar17892

  • Sr. Member
  • ****
  • Beiträge: 921
  • Think easy!
    • mollgruppe
Antw:flow from pulse
« Antwort #1 am: November 02, 2026, 14:10:40 Nachmittag »
Hi srd
This is just a suggestion.
Please state the minimum and maximum flow rates in your system.

Please note:
The calculation is based on the time interval between two signal edges. An average value is then determined over 3 pulses.
When the measurement begins, you should wait for these 3 calculations to be completed—this is especially important in cases of very low flow rates.


//This calculation is for a maximum flow rate of 360 m³/h (10 Hz pulse).
ED01 (
   EN := ,
   I1 := I01,   //pulse
   Q1 => );
T01 (
   EN := true,
   RE := M01,
   ST := ,
   I1 := T#999995ms,
   I2 := ,
   Q1 => ,
   QV => );
M01:=FALSE;
//Flow approaches zero
M02:=T01QV > 900000;
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
//scale to 4-20mA
LS01 (
   EN := true,
   I1 := MD25,
   X1 := 0,
   Y1 := 819,
   X2 := 360,
   Y2 := 4095,
   QV =>
);

The test program use a timer to simulate pulses

Thomas
« Letzte Änderung: November 02, 2026, 14:31:31 Nachmittag von radar17892 »
Weil Einfach einfach Einfach ist!

Offline srd

  • Full Member
  • ***
  • Beiträge: 153
Antw:flow from pulse
« Antwort #2 am: November 03, 2026, 13:55:29 Nachmittag »
thanks for that i will give it a go

Offline radar17892

  • Sr. Member
  • ****
  • Beiträge: 921
  • Think easy!
    • mollgruppe
Antw:flow from pulse
« Antwort #3 am: November 03, 2026, 20:41:10 Nachmittag »
For better resolution at LS1, I would provide the result in units of 0.1 m³/h. In that case, X2 must be 3600.

I’m testing the calculation again:
   MD23:= (MD20 + MD21 + MD22)/3; //Averaging of the times over 3 pulses in ms
   MD24:= 36000000 / MD23;//result in l/h
to ensure there’s no division by zero.
I think the second line needs to be skipped if MD23 = 0.
Please let me know the minimum and maximum flow rates so I can optimize the calculation. That would also allow for shortening the duration on Timer 1, as well as the time threshold at which flow is considered zero—which is currently set to 900 seconds.
Weil Einfach einfach Einfach ist!

Offline srd

  • Full Member
  • ***
  • Beiträge: 153
Antw:flow from pulse
« Antwort #4 am: November 04, 2026, 12:17:43 Nachmittag »
Hi Radar
            minimum flow would be 1m³/h and the max would be 70m³/h

Offline radar17892

  • Sr. Member
  • ****
  • Beiträge: 921
  • Think easy!
    • mollgruppe
Antw:flow from pulse
« Antwort #5 am: November 08, 2026, 11:27:24 Vormittag »
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
« Letzte Änderung: November 08, 2026, 11:47:29 Vormittag von radar17892 »
Weil Einfach einfach Einfach ist!