Troubleshooting
Why water flow from pulse counts reads wrong in ladder logic
Short answer
Three pulses of 1 m³ in a 5-minute gate must read 36 m³/h. When the number reads wrong, the ladder is at fault in one of three ways: the counter increments on the input level instead of the rising edge, the counter is cleared before the compute rung, or the gate TON never restarts. Count edges, compute before clearing, and break the timer enable for one scan at each gate end.

On this page
Your arithmetic is right and the ladder is what breaks the reading. Three pulses of 1 m³ in a gate of 5 minutes (1/12 h) must give 36 m³/h, and a correct program shows that after every gate. Wrong values trace back to three faults: the counter increments on the input level instead of the rising edge, the counter is cleared before the compute rung reads it, or the gate TON never restarts and the display freezes. Each fault has its own symptom, and each fix is one rung.
The formula and the worked example #
Flow in cubic metres per hour equals the pulse count times the pulse weight divided by the gate time in hours. In integer form, multiply by 60 and divide by the gate time in minutes, where GateMinutes is that gate time in minutes:
Flow (m³/h) = Count × Weight × 60 ÷ GateMinutes
Worked example: a 5-minute gate is 5 ÷ 60 = 1/12 h, about 0.0833 h. Three pulses at 1 m³ each collect 3 m³ in the gate, and 3 ÷ (1/12) = 3 × 12. The integer form confirms it: 3 × 1 × 60 ÷ 5 = 180 ÷ 5 = 36 m³/h. Multiply before you divide, because integer division truncates and a small product loses less than a large one.
Counting pulses inside a timed window is the same method as frequency measurement from timed pulse counts on an S7-200; a flow rung only adds the weight multiplication after the window closes.
Build the gate window from a TON #
One TON and two binary inputs are enough. The tag names here are mine for this example, not your platform's: GateTimer is the TON with its preset equal to the gate time in the timer's own time base; PulseIn is the pulse input, I1 in your sketch; PrevPulse and GateEnd are BOOL bits that start FALSE; PulseCount and FlowRate are DINT registers that start at 0; RunEnable is the second binary input, used as a run permit or a manual reset.
Build and recycle the window with two rungs:
- Rung 1: RunEnable and NOT GateEnd in series enable GateTimer.
- Rung 2: the GateTimer done bit and NOT GateEnd in series drive the GateEnd coil, so GateEnd is on for exactly one scan.
The reset is already inside rung 1: on the gate-end scan, NOT GateEnd breaks the timer enable, the accumulator clears, the done bit drops, and the TON restarts on the next scan. Do not instead put the done bit in series with the timer's own enable — that also resets the timer, but the edge lasts less than one scan and no rung after it can act on it. The pattern assumes coils update as each rung is solved; the bench test below confirms the sequence on your controller.
Count each pulse on the rising edge #
A level-based increment adds one count on every scan while the input is high, so a single pulse lands as tens or hundreds of counts and the flow reads far too high. Count the transition, not the level:
- Edge rung: PulseIn and NOT PrevPulse in series add 1 to PulseCount.
- Last rung of the program: move PulseIn into PrevPulse, so the stored state follows the input by one scan.
An edge rung fixes double counting, not lost pulses. When the pulse is short against the scan time and the input filter, counts go missing instead, and why a PLC misses short input pulses and how to catch them walks through that timing.
| Symptom at the counter | Cause | First fix |
|---|---|---|
| Jumps by tens or hundreds per pulse | level counting: the rung fires every scan while the input is high | add the PrevPulse edge rung |
| Misses pulses | pulse width close to the scan time or the input filter setting | widen the pulse or move it to a high-speed input |
| Never clears | clear rung not driven by GateEnd | drive the clear from the GateEnd rung |
| Correct count, flow reads 0 | clear sits above the compute rung | move compute above clear |
Clear after the compute rung #
On the gate-end scan, rung order decides the number. Compute and store first, clear second:
- Compute rung: on GateEnd, write FlowRate = PulseCount × Weight × 60 ÷ GateMinutes into the holding register.
- Clear rung: below the compute rung, on GateEnd, move 0 into PulseCount.
If the clear sits above the compute, the compute reads an empty register and the flow reads 0 after every gate, which is the most common zero-reading fault. Write FlowRate only when GateEnd is true, so the display holds between gates instead of collapsing while the counter sits empty. For a pulse weight below one cubic metre, compute in the smaller unit and scale once at the display rung.
If your controller ships a totalizer instruction instead, use it: the Studio 5000 Logix Designer instruction set documents a Totalizer (TOT) instruction that does gated counting and accumulation, and the rungs above rebuild that core from a plain TON where no totalizer exists.
Prove the window on the bench #
- Set the GateTimer preset to 1 minute and Weight to 1, so the arithmetic stays trivial.
- Pulse the input exactly 3 times inside one gate. PulseCount must step 1, 2, 3: one count per pulse and nothing more.
- At the gate end, FlowRate must read 3 × 1 × 60 ÷ 1 = 180 m³/h.
- Restore the 5-minute preset, pulse 3 times again, and confirm 36 m³/h.
- Confirm PulseCount returns to 0 and FlowRate holds steady through the next gate until the next GateEnd.
- Add a first-scan bit that clears PulseCount, GateEnd and the timer, and discard the first result after every power-up: a gate cut short by a power cycle or a mode change leaves a partial count against a full gate divisor, which reads low.
Resolution and the decision by symptom #
The display moves in steps of one pulse per gate. With a 1 m³ pulse weight, one extra pulse adds 12 m³/h. Lengthen the window to narrow the step: a 10-minute gate makes one pulse worth 1 ÷ (10 ÷ 60) = 6 m³/h, and a smaller pulse weight narrows it the same way.
Then fix by symptom:
- Reads far too high and jumps wildly: level counting. Add the PrevPulse edge rung.
- Reads 0 after every gate: the clear sits above the compute. Swap them on the GateEnd scan.
- Collapses to 0 between gates: FlowRate is recomputed from an empty counter. Write it only on GateEnd.
- Freezes at one value: the done bit never drops because the timer never restarts. Break the enable with NOT GateEnd for one scan.
- Reads low right after power-up: a partial gate against a full divisor. Clear on the first scan and discard that first result.
Questions asked
What does the display show when no pulse arrives during a gate?
The compute rung stores 0, so the reading drops to 0 m³/h, and that is a correct reading rather than a fault: real flow is below one pulse per gate. With a 1 m³ pulse weight, flow under 12 m³/h shows as 0 in most gates and as one step when a pulse lands near the gate end.
Can the gate be timed without a TON?
Yes, on a platform with a real-time clock. In a logger sketch, the compare NE RTC_Sec, REG2, Q1 fires once per second by detecting each change of the seconds register; counting 300 of those ticks reproduces the same window length, and the tick counter's finished value replaces the TON done bit in rung 2. That frees you from the timer entirely on clock-equipped controllers.
How do I handle a pulse weight that is not a whole cubic metre?
Compute in the smaller unit and scale once at the display. A meter that pulses every 10 L collects 30 L in a 5-minute gate, and 30 × 60 ÷ 5 = 360 L/h, which the display rung divides by 1000 to show 0.36 m³/h. Multiply before dividing so integer math stays exact.
Does the gate TON need a separate reset instruction?
No. A TON resets whenever its enable rung goes false: the accumulator clears and the done bit drops. Rung 1 breaks the enable with NOT GateEnd for the one scan after the gate ends, and that is the whole reset. A separate reset coil belongs only to timer instructions that latch the done bit; drive it from the same GateEnd pulse that runs the compute.