If I understand the OP's question, he has an analog input to his PLC that represents flow. He wants to generate an output pulse at each 1000 gallons of flow.
Let's assume you have already scaled the 4 - 20 mA signal from the flow meter to engineering units like gallons per minute. Once per second capture the GPM value and divide it by 60 (because one second is 1/60th of a minute) and add the result to a running total. When the running total reaches 1000 generate your pulse output, subtract 1000 from the running total and wait for it to reach 1000 again.
If the flow varies a lot and you need more accuracy, instead of using the captured GPM value each second, take the average of the current sample and the value you captured one second ago.
Using a REAL to totalize has a risk, try for example to add 20,000,000 and 1 with REALs, the result will be 20,000,000, the 1 will not be added.
For me better to use a big integer
What makes you say that? When you sample the flow rate once per second and add that sample to the running total you are making accommodation for changes in the flow rate. You can sample more frequently than once per second if necessary, limited only by the PLC's scan time and the update rate of the analog input module's A/D conversion.Obviously, we are all assuming the flow rate is fairly constant...
What makes you say that? When you sample the flow rate once per second and add that sample to the running total you are making accommodation for changes in the flow rate. You can sample more frequently than once per second if necessary, limited only by the PLC's scan time and the update rate of the analog input module's A/D conversion.