Siemens LOGO! Multiple Counters from One Digital Input: Production Counter with Gap Detection
This engineering reference documents a field-proven application pattern on the Siemens LOGO! logic relay: driving three independent counters from a single 24 V digital input, while simultaneously detecting product-flow gaps that exceed a defined threshold. The pattern uses an off-delay timer and a NAND gate to derive a derived count pulse for the secondary counters without requiring additional sensors or wiring.
1. Problem Definition
On a LOGO! base module, every block (counter, timer, gate) consumes a block number from the program. A naive implementation connects input I3 directly to the count input of three counters, but that fails for two reasons:
- When a product arrives every 0.7 s, the off-delay never expires, and the secondary counters do not see a distinct edge for each product.
- Without a retriggerable timer and an edge-derivation stage, an off-delay cannot drive a counter input directly, because the timer output is a level, not a one-shot.
The required behaviour is summarised in the table below.
| Counter | Function | Counts when | Reset |
|---|---|---|---|
| B030 (Up counter) | Total / run-time product counter | Every rising edge on I3 | Manual or shift reset |
| B031 (Up counter) | Daily missed-product counter | When I3 gap > 0.9 s | Daily reset |
| B060 (Up counter) | Weekly missed-product counter | When I3 gap > 0.9 s | Weekly reset |
2. Prerequisites
- LOGO! base module: any current LOGO! 8 generation (ordering prefix 6ED1052-* for 24 V DC variants, or 6ED1052-* for 230 V AC variants depending on sensor supply). Inputs are 24 V DC sourcing on the standard BM.
- Firmware: LOGO! 8.3 or later is recommended for stable retentive counter behaviour and Soft Comfort V8.4 compatibility. Update via SD card or Web-based Management.
- Sensor: a 24 V DC PNP sensor (inductive, photoelectric, or reed) wired to digital input I3. Maximum count frequency: 5 Hz with mechanical contacts and up to 40 Hz with electronic sensors on a LOGO! BM. The 0.7 s nominal spacing equals ~1.43 Hz, which is well within both limits.
- LOGO! Soft Comfort: V8.3 or later (engineering software). Simulation mode is mandatory before any live download.
- Power supply: 24 V DC regulated for the sensor and the BM's 24 V input rail.
- Operator panel (optional): LOGO! TDE text display or a connected HMI for viewing counter values without a PC.
Reference the official LOGO! 8 System Manual (Siemens Support entry ID 109751304) for hardware pin-outs and input electrical limits.
3. Block Selection
Four block types are required. The block numbers (B030, B031, B060, B064) are assigned by Soft Comfort in program order; they are not fixed to those values, but the engineering pattern is the same regardless of numbering.
| Block | Type | Function in this program | Key parameters |
|---|---|---|---|
| B030 | Up/Down counter | Total product counter, counts every I3 rising edge | On, Ref, Dir, Count=I3, Reset |
| B031 | Up/Down counter | Daily missed-product counter | On, Ref, Dir, Count=NAND_out, Reset=day pulse |
| B060 | Up/Down counter | Weekly missed-product counter | On, Ref, Dir, Count=NAND_out, Reset=week pulse |
| B064 | Off-delay (Ta) | Retriggerable 0.9 s watch on I3; expires only on a gap | Trg=I3, Ta=0.9 s, Q drives NAND input 1 |
| NAND | Basic NAND gate | Derives a one-cycle HIGH pulse when B064 expires | Inputs: B064.Q, constant 1 (or B030.Q inverted) |
4. Timing Design: Why 0.7 s and 0.9 s
The off-delay is the heart of the gap detector. The principle is:
- Every rising edge on I3 retriggers B064. The off-delay output Q remains HIGH.
- If a new product arrives within 0.9 s, the timer is restarted and Q stays HIGH.
- If 0.9 s passes without a retrigger, Q goes LOW. This is the only condition that should advance the missed-product counters.
The 0.2 s margin between the nominal 0.7 s spacing and the 0.9 s threshold absorbs sensor jitter, indexing variability, and the LOGO! scan time. A tighter margin (for example 0.75 s) increases false positives; a wider margin (for example 1.2 s) allows real missed products to pass undetected.
4.1 Timing diagram
The diagram shows the steady-state behaviour: while products arrive on schedule, B064.Q is held HIGH, and the NAND output to B031/B060 stays LOW (no count). On a missed product, B064 expires to LOW, and a single one-cycle count pulse is generated for the secondary counters.
5. FBD Program Structure
The function block diagram in Soft Comfort is built in three rows.
5.1 Row 1 — Total product counter (direct)
I3 ─────────────► [B030 Count]
[B030 On ] ◄── 24V (constant 1)
[B030 Ref] ◄── 0
[B030 Dir] ◄── constant 0 (count up)
[B030 Rst] ◄── operator / shift reset
Each rising edge of I3 increments the total. B030 output value is held in retentive memory (LOGO! 8 with battery or persistent flag) so a power cycle does not lose the count.
5.2 Row 2 — Off-delay gap detector
I3 ─────┬──────────────► [B064 Trg]
│ Ta = 0.9 s
│ [B064 Q] ─────────┐
│ │
└──── (not used for B030) ▼
[NAND in1]
The off-delay's Q output is fed into the first input of the NAND gate. Ta is the off-delay time; on a LOGO! 8 the parameter accepts values from 0.05 s up to 99:59 h in 10 ms increments.
5.3 Row 3 — Secondary counters via NAND edge
B064.Q ──────► [NAND in1]
const 1 ─────► [NAND in2]
NAND.Q ──────► [B031 Count] (daily missed)
NAND.Q ──────► [B060 Count] (weekly missed)
With both NAND inputs at HIGH during normal operation, the output is LOW and no count occurs. When B064.Q goes LOW on a missing product, the NAND output goes HIGH for one cycle, generating the count edge for both secondary counters.
6. Wiring and Sensor Integration
The sensor must produce a clean 24 V PNP signal. Mechanical switches (limit switches, micro-switches) require debouncing — the LOGO! BM does not include hardware input filters on standard digital inputs, only on the high-speed counter inputs (I1/I2 on some variants). For 0.7 s spacing and a mechanical contact, a 5 Hz-capable input is adequate; however, a small RC filter (100 Ω + 100 nF) on the input terminal is recommended practice.
| Terminal | Signal | Wire colour (suggested) | Notes |
|---|---|---|---|
| Sensor +V | 24 V DC out (LOGO! 24 V sensor supply) | Brown | Use LOGO! sensor supply terminal to avoid ground loops |
| Sensor out | To BM digital input I3 | Black | PNP, NO (normally open) |
| Sensor 0 V | LOGO! 0 V / M terminal | Blue | Common reference |
| I3 terminal | Digital input 3 on the BM | Black (continued) | Configured as a standard digital input, not high-speed |
Reference the LOGO! 8 manual for the exact terminal layout of your BM variant (LOGO! 8.3 / 8.4 modules have different connector pitches than LOGO! 6/7).
7. LOGO! Soft Comfort Simulation
Before any download, the program must be exercised in simulation mode. Soft Comfort's simulation provides:
- An interactive I/O panel that lets you force I3 HIGH and LOW with a click.
- A timeline view that shows the on/off state of every block (B030, B031, B060, B064) for visual debugging.
- Parameter override so you can shorten Ta to 0.2 s and verify the gap detection logic in seconds, then restore Ta to 0.9 s for the live program.
7.1 Simulation procedure
- Build the FBD in Soft Comfort as described in section 5.
- Press the Simulation button (or F5).
- Click I3 to force HIGH for 100 ms, then LOW.
- Verify that B030 increments by 1; B031 and B060 do not increment because B064 is still HIGH (retriggered every <0.9 s).
- Stop pressing I3. Watch the timeline: after 0.9 s of inactivity, B064.Q falls.
- On the falling edge of B064.Q, verify that B031 and B060 each increment by 1, and that B030 does not increment (the NAND edge fires only on the falling edge of B064, not on the I3 input).
- Reset the simulation, then drive I3 at a faster pace than 0.9 s (for example 0.5 s spacing) and confirm the secondary counters stay at zero.
8. Download and Commissioning
- Connect the LOGO! BM to the PC via Ethernet (LOGO! 8 supports direct Ethernet access) or via USB cable (USB programming cable, 6ED1057-1AA01-0BA0).
- In Soft Comfort, choose Tools → Transfer → PC → LOGO!. Select the correct IP address; the default after first power-up is 192.168.0.1 with DHCP fallback.
- Click Transfer. The BM stores the program in non-volatile flash and restarts.
- After the restart, watch the LED for I3 to confirm the sensor is wired correctly. On a standard BM, the corresponding I-LED lights when the input is HIGH.
- Drive a known number of products through the line and confirm B030 on the LOGO! display or in the Web-based Management counter view.
- Stop the line for 1.5 s. Confirm that B031 and B060 each increment by exactly 1.
- Restore normal production. Confirm B031/B060 no longer increment while products are flowing.
9. Verification Procedure
The verification stage must cover the four operating states of the program.
| Test case | Input stimulus | Expected result | Pass criterion |
|---|---|---|---|
| TC1: Normal flow | I3 pulses at 0.7 s spacing for 60 s | B030 increments by ~85; B031 and B060 unchanged | All three counters match expected values within ±1 count |
| TC2: Single missed product | 1.5 s gap inserted in a normal flow | B031 and B060 each increment by 1; B030 unchanged | Single increment, no spurious counts |
| TC3: Long stop | Stop the line for 10 s | B031 and B060 increment by 1, not by many | Exactly one increment per gap (level-to-edge conversion correct) |
| TC4: Power cycle | Power off for 30 s during normal flow | B030 retains its count; B031/B060 also retain (if retentive) | Counter values preserved |
| TC5: Daily reset | Operator triggers daily reset | B031 resets to 0; B030 and B060 unchanged | Only the targeted counter resets |
10. Troubleshooting Matrix
| Symptom | Likely root cause | Diagnostic step | Corrective action |
|---|---|---|---|
| B030 counts but B031/B060 never count | B064 is being retriggered continuously because I3 is held HIGH (sensor stuck or wiring shorted HIGH) | Read I3 LED state; if it stays lit, check sensor wiring and PNP/NPN type | Replace sensor or correct wiring polarity |
| B031/B060 count on every product | NAND wired as inverter of I3 instead of B064.Q, or NAND in1 is connected directly to I3 | Inspect the FBD: trace NAND in1 back to B064.Q only | Re-wire NAND in1 to B064.Q |
| B031/B060 count multiple times on one gap | Bounce on the off-delay output, or NAND in2 is not held constant | Look at the timeline during a 1.5 s gap; count the NAND transitions | Add a 50 ms pulse generator on NAND.Q before the counter inputs, or use the count-on-edge property of the counter block |
| Counts lost on power cycle | Retentivity not enabled for the counter blocks | Open the counter block properties and check the Retentive flag | Enable Retentive = on for B030, B031, B060; ensure the LOGO! has a battery or the program is set to retentive on power-down |
| False gap detection on slow products | 0.9 s Ta is too tight for actual product spacing on the line | Measure I3 period with a stopwatch or scope | Increase Ta to 1.2–1.5 s, keeping the 0.2 s safety margin |
| No count, but I3 LED toggles | Counter block's Count input wired to wrong signal, or block is disabled (On = 0) | Open B030 properties; verify On is connected to a constant 1 | Reconnect the On input to 24 V constant |
| Counts work in simulation but not on the BM | Program was not transferred, or old program is still running | On the BM, navigate to Program → Clear Prg and re-transfer | Re-transfer and verify the start screen matches the new program name |
11. Edge Cases and Field-Proven Caveats
- Sensor bounce with mechanical contacts: a mechanical limit switch bouncing at 0.7 s spacing does not normally cause problems on a LOGO! input, but a faulty switch with a contact-resistance rise can produce intermittent counting. Verify by reading the I3 LED state for a clean on/off pattern.
- LOGO! scan time: the scan period of a LOGO! 8 BM is typically 8–20 ms depending on program complexity. The 0.9 s Ta parameter is unaffected by scan time because the off-delay is hardware-tied to the system clock.
- Number of blocks: a LOGO! 8 BM supports up to 400 blocks (LOGO! 8.3) and 800 blocks (LOGO! 8.4). The four-block program described here consumes a negligible share.
- Replacing the off-delay with an on-delay: an on-delay would not work here. An on-delay would create a pulse on retrigger, not a gap. The off-delay is mandatory.
- Adding a permissive input: the NAND gate is intentionally over-specified (one input is a constant 1). Replace the constant 1 with a digital input, for example I4, so the operator can disable gap-counting during line setup.
-
Logging counts: LOGO! 8 with the LOGO! Web-based Management tool can publish counter values over HTTP/MQTT for SCADA capture. The block value is accessible at
/Var/<blockname>.CVin the integrated web server. - Time-based daily/weekly reset: use a weekly time switch block (e.g. on Monday 06:00) to drive the reset of B031 (daily) and B060 (weekly). The weekly time switch is built into the LOGO! and requires no external wiring.
12. Extending the Pattern
The same off-delay + NAND + counter arrangement can be extended to:
- Multiple product types: one off-delay per product type (different Ta per type) and a multiplexer on the NAND output to drive type-specific counters.
- Stack-light annunciation: drive a Q-output to a stack light that turns on whenever a gap is detected, in parallel with the counter increments.
- Email/SMS alert: on LOGO! 8.3+ with a LOGO! CMR (cellular router) or LOGO! CSM, push the count delta to a webhook or SMS gateway whenever B031 increments.
- Integration with HMI: expose B030, B031, B060 over Modbus TCP (LOGO! 8 supports Modbus server on port 502) and let the HMI poll the registers for trend display.
For the Modbus register map of LOGO! 8, see the LOGO! 8 System Manual, section on Modbus communication.
13. Summary
Three counters on one input is not a hardware problem on the Siemens LOGO!; it is a logic design problem. The clean solution uses:
- A direct connection from I3 to the total counter (B030) for every-edge counting.
- A retriggerable off-delay (B064, Ta = 0.9 s) to detect a gap in the pulse train.
- A NAND gate to convert the off-delay's level output into a one-cycle count edge.
- The NAND output to drive the count inputs of the daily (B031) and weekly (B060) counters in parallel.
The pattern is verifiable entirely in Soft Comfort simulation, deploys in minutes over Ethernet or USB, and uses four blocks total — well within the capacity of any LOGO! 8 base module.
Can a single Siemens LOGO! input drive more than one counter at the same time?
Yes. A digital input can be connected to the Count input of multiple counter blocks in parallel. To avoid double-counting on a shared level, place a NAND edge-detection stage between the input and any counter that should see a one-cycle pulse rather than a continuous level. In the application described here, B030 counts every edge directly while B031 and B060 are driven by the NAND output to count only on a gap event.
Why does my off-delay not increment the secondary counters during normal product flow?
Because the off-delay is retriggered on every I3 rising edge. As long as products arrive within Ta (0.9 s in the reference design), the timer's Q output never goes LOW, and the NAND edge never fires. The secondary counters will only increment on a genuine gap that exceeds 0.9 s. If you need them to count on every product instead, wire the NAND input to I3 directly and remove the off-delay from the path.
What value should I use for the off-delay Ta?
Ta must be longer than the nominal product spacing and shorter than the longest acceptable gap. With a nominal spacing of 0.7 s, the reference design uses Ta = 0.9 s to give a 0.2 s margin. For lines with variable product pitch, measure the longest and shortest inter-product intervals and set Ta at the longest normal interval plus 20–30%.
Do the counter values survive a power cycle on LOGO! 8?
Yes, if the Retentive flag is enabled on each counter block. Open the counter block in Soft Comfort, expand the parameter group, and tick Retentive = on. On a LOGO! 8 base module without a battery, the program and retentive variables are stored in non-volatile flash; with a battery installed, retention is guaranteed for the duration of the battery's service life.
Can I test the program before wiring the sensor?
Yes. Use LOGO! Soft Comfort's simulation mode (F5) to force I3 HIGH and LOW from the on-screen panel. For a faster simulation, temporarily reduce Ta to 0.2 s in the block properties so the off-delay expires in 0.2 s instead of 0.9 s, then restore the value before downloading to the BM. This lets you exercise both normal and gap conditions in a few seconds.