Extending LOGO! 8 OBA8 Up/Down Counter Past 32767 for Flow Meters

David Krause12 min read
PLC HardwareSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Problem Statement

A 4-wire Hall-effect flow sensor (e.g., the Seeedstudio G3/4) outputs 330 pulses per litre. On a Siemens LOGO! 8 (OBA8) base module, accumulating that signal into a "total fuel dispensed" register quickly runs into a numerical wall: the on-board Up/Down Counter can hold 0 to 999,999 internally, but the moment you scale pulses into litres with a Gain or analog math block, the legacy 16-bit signed arithmetic ceiling of 32,767 clips the result. With one decimal of resolution (0.1 L) that means 3,276.7 L maximum — less than a single 8-hour shift on a 9 L/min dispenser.

This article documents the field-proven workaround: a two-stage cascaded counter pair. Counter 1 accumulates 0 to 330 pulses; on every 330-pulse carry, Counter 1 resets to zero and Counter 2 (whole litres) increments by one. Counter 2 then tracks 0 to 999,999 L in real time, with no division or scaling math required. The value can be displayed on the LOGO! Web Server, on the LOGO! TDE text panel, or polled by a SCADA tag.

2. Prerequisites

  • Siemens LOGO! 8.3 (OBA8) base module: 6ED1052-1MD08-0BA1 (LOGO! 12/24RCE), 6ED1052-1MD08-0BA8 (12/24RCEo), 6ED1052-1CC08-0BA1 (LOGO! 24CE), or 6ED1052-1FB08-0BA1 (24CEo). The high-frequency inputs I3, I4, I5, I6 are rated for 5 kHz on these 24 VDC variants. See the LOGO!Soft Comfort online help: Up/Down Counter for the input-frequency table.
  • LOGO!Soft Comfort V8.3 engineering software. Free download from the Siemens Industry Online Support portal.
  • 24 VDC power supply, fused at 1 A, with the LOGO! and the flow sensor sharing the same GND reference.
  • Hall-effect flow sensor: Seeedstudio SEN0216 (G3/4) or equivalent, 330 pulses/L ±10 %, open-collector NPN, 5 to 24 VDC, 1 to 30 L/min.
  • 10 kΩ pull-up resistor if the sensor output is open-collector. The Seeedstudio G3/4 includes one internally; verify on the specific board revision.
  • Ethernet cable for the LOGO! Web Server view.

3. Why the 32,767 Limit Exists

The Up/Down Counter block (function-block icon in FBD) in LOGO!Soft Comfort stores its value in a 32-bit register. When you reference the counter's numeric value in a Message Text, an Analog Threshold, or a Gain block, the legacy function libraries up through LOGO! 7 applied 16-bit signed integer math, clamping the result to -32,768 to 32,767. LOGO! 8 OBA7 (firmware 1.16.x and later) and OBA8 (firmware 1.81.x and later) extended several math blocks to 32-bit, but the on-screen text renderer and some analog blocks still exhibit 16-bit clipping depending on context.

The simplest, most portable fix is to never scale. Count whole units in a second register, and let the second register's natural 0 to 999,999 range do the work for you. The technique works on every LOGO! 8 firmware version, which makes it safe to deploy without auditing the controller's firmware build.

4. Hardware Wiring

4.1 Terminal Layout

For a LOGO! 12/24RCE (article number 6ED1052-1MD08-0BA1) the relevant terminals are:

  • 1, 2: 24 VDC sensor supply output (fused internally, 200 mA total)
  • 3, 4: 0 V (GND)
  • 5: I1 (4 Hz, regular digital input)
  • 6: I2 (4 Hz, regular digital input)
  • 7, 8: AI1, AI2 (0 to 10 V analog, not used in this project)
  • 9: I3 (5 kHz, fast counter) — FLOW SENSOR SIGNAL
  • 10: I4 (5 kHz, fast counter)
  • 11: I5 (5 kHz, fast counter)
  • 12: I6 (5 kHz, fast counter)
  • 13, 14: Q1, Q2 (relay outputs, optional — used here for a "tank low" or "refill needed" flag)

4.2 Sensor Connection

The Seeedstudio G3/4 has three leads: red (+), black (GND), yellow (signal).

Sensor wire LOGO! terminal Notes
Red 1 (+24 V) Sensor supply, fused internally at 200 mA
Black 3 (GND) Common reference, mandatory
Yellow 9 (I3) Fast counter, 5 kHz capable

The internal 10 kΩ pull-up on the Seeedstudio board pulls the open-collector transistor to +24 V when no flow is present, registering as a logic "1" on I3. Pulses are active-low; the LOGO! high-speed counter accepts both polarities depending on the counting direction configured in the block. Use a shielded cable, terminate the shield to PE at the LOGO! end only, and keep the run under 3 m to avoid capacitive degradation of the 5 kHz edges.

5. Cascaded Counter Logic

5.1 Block Diagram

Flow Sensor 330 pulse/L I3 5 kHz B001 U/D 0 → 330 pulses Carry @ 330 B002 U/D Whole litres 0 → 999,999 L LOGO! Web Server Fuel_Total_L @ 1 Hz B003 Reset B001 After each carry, B001 = 0

5.2 Function Block Layout

The FBD program uses three blocks:

  1. B001 — Up/Down Counter (pulse accumulator, 0 to 330)
  2. B002 — Up/Down Counter (whole-litre accumulator, 0 to 999,999)
  3. B003 — Reset (clears B001 on the carry event)

5.3 B001: Pulse Accumulator

  • Counting input: I3
  • Direction input: tied to logic "1" (count up)
  • On threshold: 330
  • Off threshold: 0
  • Start value: 0
  • Output: "On" flag fires for one scan cycle each time the count crosses 330 going up. This is the carry pulse.

5.4 B002: Whole-Litre Accumulator

  • Counting input: B001 On output (a 1-scan pulse at the carry moment)
  • Direction input: tied to logic "1"
  • On threshold: 999,999
  • Off threshold: 0
  • Start value: 0
  • Output: not used for control; the value is the running total

5.5 B003: Pulse-Counter Reset

  • Trigger input: B001 On output
  • Target: B001
  • Action: resets B001 to 0 immediately after the carry edge

The two events — B002 increment and B001 reset — occur in the same LOGO! scan, which runs in roughly 1 ms on OBA8 firmware. The 1 ms scan is two to three orders of magnitude faster than the carry period at maximum flow (165 Hz pulse rate, carry every 2 s), so no race condition exists. If you observe a one-cycle glitch on B001 reading 331 before the reset fires, update to OBA8 firmware 1.82.x or later, which executes the Reset block in the same scan as the On-flag transition.

6. Program Code (FBD)

+24V ──┐
       ├──[I3]──► [B001 U/D]──(B001.On)──┬──► [B002 U/D]──► Fuel_Total_L
GND ───┘             Th=330  St=0         │         Th=999999  St=0
                                          │
                                          └──► [B003 Reset B001]

7. Parameter Table

Block Parameter Value Description
B001 Cnt I3 Pulse input from flow sensor
B001 Dir Lo (logic 0) Always count up
B001 OnThr 330 Generate carry pulse at 330
B001 OffThr 0 Reset threshold if direction reversed
B001 Start 0 Initial value
B002 Cnt B001.On Carry pulse input
B002 Dir Lo Always count up
B002 OnThr 999,999 Saturation at maximum display
B002 OffThr 0 Reset threshold (not used)
B002 Start 0 Initial value
B003 Trigger B001.On Reset on the carry edge
B003 Target B001 Reset B001, leave B002 unchanged

8. Real-Time Display on the LOGO! Web Server

  1. In LOGO!Soft Comfort, open Tools → Options → Ethernet. Enable the LOGO! Web Server and assign a static IP, for example 192.168.0.10/24.
  2. In the Message Text editor, create a display line that references B002, e.g., Total: [B002] L. Rename the variable tag to Fuel_Total_L in the variables table for clarity on the web page.
  3. Download the program to the LOGO! and cycle power.
  4. From a PC on the same subnet, browse to http://192.168.0.10. The web server shows the live B002 register, updating every 1 s by default.
  5. The web server does not reset the counter. It is a non-destructive viewer, satisfying the "I want to see real time" requirement that pure data-log roll-overs cannot meet.
Note: The built-in web server is included on the LOGO! 12/24RCEo and 24CEo variants. On the LOGO! 12/24RCE (non-o) and 24CE (non-o), web server access requires the LOGO! CSM add-on Ethernet module (6GK7177-1FA10-0AA0).

9. Verification Procedure

  1. With the program loaded and the sensor dry, observe B001 in Online Test. It should read 0 and remain stable.
  2. Manually trigger the sensor with 1 L of fuel poured through it. B001 should briefly hit 330, B002 should increment from 0 to 1, and B001 should drop back to 0.
  3. Pour exactly 10 L through the sensor. Confirm B002 reads 10 at the end of the test.
  4. Run the dispenser for 60 minutes at 20 L/min. Expected B002 ≈ 1,200 L, accuracy ±10 % of nominal sensor calibration.
  5. In Online Test, place a probe on the wire from the sensor to I3. At 20 L/min you should see a 110 Hz square wave with 50 ±5 % duty cycle.
  6. Open the LOGO! Web Server from a phone. The page should refresh and show the value updating once per second without gaps.

10. Calibration

The Seeedstudio G3/4 datasheet quotes 330 pulses/L as "typical" with no tighter tolerance. To calibrate for custody-transfer or inventory control:

  1. Pump 10 L of fuel through the sensor into a calibrated container.
  2. Read B002 in Online Test. If it reads 9.7 L equivalent, the effective pulse density is 330 × (10 / 9.7) = 340 pulses/L.
  3. Adjust B001's On threshold to 340. Subsequent readings will match the calibrated volume to ±0.5 % (limited by the integer pulse boundary).
  4. Repeat after 90 days or 5,000 L of use, whichever comes first. Mechanical wear in the turbine bearings can shift the calibration by up to 3 % per year.

11. Retentive Behaviour

By default, both B001 and B002 lose their value on a power cycle. Enable retention on each block (Rem = On) to keep the cumulative total across outages. Keep retention off for B001; it is always reset by the carry and retains no useful information. Enable retention on B002 — this is your long-term total.

On the LOGO! 12/24RCEo and 24CEo variants, retention is part of the base module's on-board non-volatile memory. On the LOGO! 12/24RCE (non-o) and 24CE (non-o), retention uses the same memory area but the base module is non-Ethernet. The 12/24RCEo is the typical choice when the Web Server is required.

12. Troubleshooting Matrix

Symptom Probable cause Fix
B001 climbs past 330 without resetting B003 reset not wired Confirm B003 trigger = B001.On
B001 resets but B002 does not increment B002 count input not wired to B001.On Rewire B002 Cnt = B001.On
B001 counts slowly or not at all Sensor wired to a 4 Hz input (I1, I2, I7, I8) Move yellow wire to I3, I4, I5, or I6
B001 counts but B002 wraps at 32,767 B002 value rendered through a Gain block Remove Gain; read B002 directly via Message Text
B002 resets on power cycle Retention not enabled Set Rem = On for B002
Web server shows "--" instead of B002 Variable not exposed to the web server Add the variable to the Web Server access list under Tools → Options
Sensor reads zero even with flow Open-collector output needs external pull-up Add 10 kΩ pull-up to +24 V at I3
Counts jitter at low flow Mechanical chatter in turbine Add a 50 ms input debounce in the U/D block (only on 4 Hz inputs)
B002 displays 331 for one scan after carry Firmware execution order on early OBA8 builds Update to OBA8 firmware 1.82.x or later

13. Comparison with S7-1200 High-Speed Counter

Engineers familiar with the S7-1200 may wonder why the LOGO! needs this workaround. The S7-1200 HSC (high-speed counter) supports a 32-bit integer range natively and can be configured for a single-shot or cyclic count mode, so a 0 to 999,999 L register with no scaling is the default behaviour. The LOGO! 8 OBA8 is positioned as a low-cost logic relay for sub-200-I/O applications, and the Up/Down Counter is its general-purpose primitive. The cascaded-counter trick is a LOGO!-idiomatic solution that costs three function blocks and zero additional hardware, which is well within the LOGO! 8's block budget (350 blocks on a standard base module, 400 on the -o Ethernet variants).

If you need 32-bit counters, four-quadrant arithmetic, or HSC interrupt routines, the S7-1200 is the right tool. If you need a 1-L-resolution totaliser on a 24 VDC input with 16 function blocks of logic, the LOGO! 8 OBA8 with a cascaded counter is the right tool. The decision pivots on I/O count, required precision, and existing engineering familiarity, not on raw counting performance.

14. Field Notes and Edge Cases

  • Reverse flow: if the line can be pumped backwards, wire a direction signal to B001's Dir input. The carry logic still increments B002 only when the count crosses 330 going up, which is the desired behaviour for "net dispensed".
  • Water hammer: a 5 kHz input rating gives you 6:1 headroom over the worst-case pulse rate, so water-hammer-induced spikes are filtered by the LOGO! input filter.
  • Multiple sensors: parallel two G3/4 sensors by routing one to I3 and the other to I4. Each gets its own B001 / B002 / B003 chain. The two litre totals can be summed in a separate analog math block if you need a system total.
  • Long cable runs: keep the sensor cable under 3 m and use shielded twisted pair tied to PE at the LOGO! end only. The 12/24RCE / 24CE inputs are Schmitt-triggered and tolerate up to 1 Vpp of common-mode noise.
  • Firmware update: the OBA8 firmware is upgradable in place via LOGO!Soft Comfort. After any firmware update, re-verify the carry behaviour — Siemens has changed block execution order in minor releases (1.81.x → 1.82.x) and a one-scan delay on B003 can occasionally allow B001 to read 331 for one cycle.
  • SD card data log as backup: if the LOGO! has an SD card slot, enable Data Log for the B002 variable. The SD card records to a CSV that can be imported into Excel for daily, weekly, and monthly totals. This is a non-destructive backstop — the live web server view remains the primary HMI.

15. Frequently Asked Questions

Can I just enable the message text and read B001 / 330 directly?

No. Dividing B001 (0 to 330) by 330 in a math block uses 16-bit arithmetic on legacy firmware and clips the result at 32,767. Bypass division entirely by counting whole litres in a second counter, as shown in section 5.

Does B002 really show 999,999 L on the web server and on the LOGO! TDE?

Yes. On LOGO! 8 OBA8 firmware 1.81.x and later, message text and web variables render the full 0 to 999,999 range of the Up/Down Counter register. Earlier OBA7 firmware (1.16.x) may saturate at 32,767 on some analog blocks; upgrade to OBA8 to remove the cap.

What if my sensor outputs 450 pulses/L or 1,000 pulses/L?

Change B001's On threshold to match. The cascaded architecture is independent of pulse density; only the carry threshold changes. A 1,000-pulse/L sensor at 30 L/min still outputs 500 Hz, well within the 5 kHz fast-input budget.

Will the high-frequency input survive a noisy industrial environment?

Yes. Wire the sensor with shielded cable, terminate the shield to PE at the LOGO! end only, and keep the cable under 3 m. The 12/24RCE / 24CE fast inputs are Schmitt-triggered and reject common-mode noise up to 1 Vpp. For longer runs, drop to a 4 Hz input and use a 1 ms hardware debounce RC filter on the sensor output.

Can I trigger a relay at, say, 100 L for a refill alarm?

Yes. Wire B002's On output to a digital output (Q1 or Q2) and set B002's On threshold to 100. The relay closes for one scan at the 100 L milestone. Add an SR (Set-Reset) latch with a manual-reset digital input if you need a latched alarm that requires operator acknowledgement.

Back to blog