Implementing a Keep-Last Counter on Siemens LOGO! 0BA7/0BA8

David Krause11 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. Overview

The "Keep-Last Counter" pattern is a recurring application need on Siemens LOGO! logic modules: a counter accumulates events during the active day, the value is displayed on the LOGO! TD/LOGO! TDE or pushed into a message text, and at the rollover point (midnight, end-of-shift, batch boundary) the accumulated count is copied into a second variable that represents the previous period total. The daily counter then resets to zero and the cycle repeats.

On LOGO! 0BA6, 0BA7, and 0BA8 the pattern is implemented without any custom function block: it uses the standard Counter (B001), Edge-triggered blocks (B002 positive edge, B005 negative edge), the MIN/MAX block (B004) as a one-shot sample-and-hold, and the Analog Amplifier (B007) to remove the unwanted decimal place that the MIN/MAX output always carries. The combination is small (six to seven blocks) and survives a power failure provided that the remanence bit is set on the Counter and on the MIN/MAX block.

This reference covers the architecture, parameter-by-parameter setup, the behavior at Data Log upload (which forces STOP/RUN), and the differences between firmware generations 0BA6, 0BA7, and 0BA8 — most notably the introduction of cross-block references on 0BA8.

2. Functional Requirements

The application has three observable requirements that drive the block design:

  1. Today Counter — increments by 1 every time digital input D1 receives a rising edge. Resets to 0 at the end of the day (or any user-defined boundary event).
  2. Yesterday Total Count — holds the value the Today Counter reached at the moment of the last reset. Does not change during the active day.
  3. Survives a Data Log upload — the upload procedure toggles the LOGO! into STOP and back into RUN, which behaves like a cold restart for any non-remanent tag. The pattern must therefore be set to remanent on every block that stores user state.

Implementation strategy: treat the negative edge of the "end of day" trigger as a one-shot sampling pulse. The pulse latches the current counter value into a MIN/MAX block configured as a memory (tracking value, never overwritten by a smaller input). The counter itself is then reset to zero by the same pulse so the cycle can restart.

3. Prerequisites

Item Specification
Hardware Siemens LOGO! 8 (6ED1052-xxx08-0BA8) or LOGO! 7 (6ED1052-xxx08-0BA7); also validated on 0BA6 with limitations
Display LOGO! TDE (6ED1055-4MH08-0BA0) or built-in LOGO! display on -0BA8 BM
Programming software LOGO! Soft Comfort V8.x (for 0BA8) or V7.x (for 0BA7)
Firmware 0BA8 = FS04 or later recommended; 0BA7 = FS02 or later
Inputs used D1 (event source), optional I2/I3 for day-rollover trigger
Outputs used None required (display-only application)

4. Block Architecture and Signal Flow

The wiring uses the standard LOGO! Soft Comfort editor. Block numbers below correspond to the original reference program; the engineer is free to renumber.

Block # Block type Function in this application
B001 Up/Down Counter (or simple Counter) Counts the rising edges of D1. Output Cnt = current day's count.
B002 Edge-triggered (positive edge) Generates a one-shot pulse on the start of the rollover event (e.g., midnight flag rising).
B005 Edge-triggered (negative edge) Generates a one-shot pulse on the falling edge of the rollover event. This pulse is what reads the counter into memory and resets it.
B004 MIN/MAX Configured as MAX with a sample input. The output tracks the highest value it has ever seen and never decreases — this is the "Yesterday Total Count" memory.
B007 Analog Amplifier Removes the decimal place that the MIN/MAX block always appends. Gain = 10, offset = 0 maps 0.0..6553.5 → 0..65535. We use the inverse mapping to drop the decimal.
B006 NOT (inverter), optional Used to combine B002 and B005 into a single coherent reset envelope.

Signal flow, in order:

  1. D1 rising edge → Counter.B001.Cnt increments.
  2. End-of-day event raises a flag (e.g., from a weekly timer or external signal) → B002 produces a one-shot pulse on the rising edge.
  3. End-of-day event falls → B005 produces a one-shot pulse on the falling edge. The negative-edge pulse is the commit event.
  4. The negative-edge pulse is AND-gated (or wired directly) to the R (reset) input of B001, clearing the Today Counter to 0.
  5. The same negative-edge pulse is wired to the En (enable/sample) input of the MIN/MAX block B004. While En is high, B004 compares its In input (the current counter value) against its stored maximum and updates the maximum. Once En falls, the stored value is latched.
  6. The output of B004 is multiplied by 10 internally (because LOGO! MIN/MAX always scales to one decimal), so the displayed value carries a trailing .0. The Analog Amplifier B007 strips the decimal by dividing by 10 (gain 0.1, offset 0) — output becomes the integer "Yesterday Total Count".

5. Step-by-Step Configuration

5.1 Counter B001

  1. Insert a Counter block.
  2. Set Threshold (On) to the maximum count for the day, e.g., 9999.
  3. Set Start value to 0.
  4. Set Direction to Up.
  5. Wire D1 to input Cnt.
  6. Wire the negative-edge pulse from B005 to input R.
  7. Enable Remanence — tick the box so the count survives power loss. (Note: the Today Counter does not strictly need remanence to survive a Data Log upload if you also accept that the current day will restart at 0 after upload; enable it for production use.)

5.2 Positive-Edge B002

  1. Insert an Edge-triggered block, trigger = positive edge.
  2. Input = the end-of-day flag (e.g., output of a weekly timer that goes high at 23:59:50).
  3. Output Q = one-shot pulse, used as a visual indicator or to gate downstream logic.

5.3 Negative-Edge B005

  1. Insert a second Edge-triggered block, trigger = negative edge.
  2. Input = the same end-of-day flag.
  3. Output Q = the commit pulse that drives both the counter reset (B001.R) and the MIN/MAX sample enable (B004.En).

5.4 MIN/MAX Block B004

  1. Insert a MIN/MAX block.
  2. Set mode to MAX (track the highest input value).
  3. Wire the output of B001 (Cnt) to input In.
  4. Wire the output Q of B005 to input En.
  5. Enable Remanence on the MAX value. This is the most critical remanence setting — without it, the "Yesterday Total Count" resets to 0 on every power cycle and on every Data Log upload.

5.5 Analog Amplifier B007

  1. Insert an Analog Amplifier block.
  2. Set Gain = 0.1 (divides by 10, strips the trailing decimal).
  3. Set Offset = 0.
  4. Wire the output of B004 (Out) to input In.
  5. Wire the output Out of B007 to the message text on the TDE/display.

6. Remanence and Data Log Upload Behavior

The Data Log upload in LOGO! Soft Comfort puts the LOGO! into STOP mode for the duration of the transfer, then automatically restarts it into RUN. From the controller's perspective this is indistinguishable from a power cycle: every non-remanent tag is re-initialized to its default value. The user-visible symptom is that both the Today Counter and the Yesterday Total Count drop to zero after every upload.

Critical: Always tick Remanence on the Counter (B001) and on the MIN/MAX block (B004). If only one is set, the value that is not retained will be lost on the next Data Log upload.

On firmware 0BA8 the Set/Reset tag list in the program properties exposes every block instance that supports remanence. On 0BA7 and earlier, the remanence tickbox is on the block itself. Validate by performing the following field test:

  1. Run the program; let the counter reach a non-zero value (e.g., 13).
  2. Trigger the rollover event manually and verify that the Yesterday Total becomes 13 and Today drops to 0.
  3. Cycle power on the LOGO! (or perform a Data Log upload) and confirm that both values are preserved.

7. Block-by-Block Parameter Table

Block Parameter Value Note
B001 Counter On threshold 9999 Application-specific; sized for one day
B001 Counter Start value 0 Reset by R input
B001 Counter Remanence ON Survives power loss / upload
B002 PosEdge Edge type Positive Marker for start of rollover
B005 NegEdge Edge type Negative Drives the commit
B004 MIN/MAX Mode MAX Sample-and-hold on the high value
B004 MIN/MAX En source B005.Q One-shot sampling window
B004 MIN/MAX Remanence ON Mandatory for "Yesterday Total Count"
B007 Amp Gain 0.1 Strips the MIN/MAX decimal
B007 Amp Offset 0 —

8. Reference Function on 0BA8 vs 0BA7

On 0BA8, blocks can address one another by symbolic name (e.g., B004.Out) instead of by block number. This is documented in the Siemens Industry Online Support article "How can you configure references between blocks in LOGO! 8?" (entry ID 109471094). Two practical consequences for this application:

  1. Math instruction limitation — the LOGO! Math block (analog math) does not accept references to other blocks as operands in any firmware generation; it operates only on its direct input pins. For this reason we use the dedicated Analog Amplifier block (B007) for the divide-by-ten conversion rather than the Math block.
  2. Block-number portability — when porting a 0BA7 program to 0BA8 you may re-insert the negative-edge block and the MIN/MAX block; the symbolic references will resolve automatically and the program continues to operate without rewiring. On 0BA7 you must keep the original block numbers and manually rewire if the topology changes.

9. Verification and Commissioning

  1. Simulation pass: In LOGO! Soft Comfort, drive D1 with a 1 Hz pulse generator. Let the counter reach 5, then force the end-of-day flag high for 2 s. Verify in the message text: Yesterday Total = 5, Today = 0.
  2. Upload test: Connect to the live LOGO!, perform PC → LOGO! download of a Data Log only (no program change). Confirm that the displayed values are unchanged after the upload completes and the LOGO! returns to RUN.
  3. Power-cycle test: Remove and re-apply the 24 V supply. Confirm remanence retention on both the counter and the MAX value.
  4. Rollover stress test: Trigger the rollover flag 50 times with the counter at zero. The Yesterday Total Count must remain at 0 (the MAX block only latches a value higher than its current memory).

10. Troubleshooting Matrix

Symptom Likely cause Corrective action
Today Counter counts correctly but Yesterday Total Count always shows 0 MIN/MAX En input never goes high, or it is wired to the wrong edge block Verify the En input is driven by the negative-edge pulse B005, not B002
Both counters reset to 0 after every Data Log upload Remanence not enabled on Counter or on MIN/MAX Open the block properties, tick the Remanence checkbox on both
Yesterday Total Count displays with a decimal place (e.g., 50.0) MIN/MAX block always outputs a value scaled to one decimal Insert the Analog Amplifier B007 with gain = 0.1, offset = 0 in the signal path
Today Counter skips a value when the rollover fires Negative edge (B005) and positive edge (B002) are swapped; the reset is firing on the wrong transition Confirm B005 is configured as negative edge on the end-of-day flag
Yesterday Total Count changes multiple times during one day En input is held high instead of pulsed; MIN/MAX is tracking live Add a one-shot (edge-triggered) between the flag and the En input; verify by single-stepping in the simulator
Reference by name resolves to "invalid" on 0BA7 Symbolic references are a 0BA8-only feature Use the legacy block-number addressing; rewire manually if block IDs change
Math instruction block rejects the reference to B004 Math block inputs do not accept block references in any firmware Replace Math with the dedicated Analog Amplifier block, which does accept block references on its In pin

11. Field-Proven Caveats

  • The MAX-mode of the MIN/MAX block only updates when En is high. If the end-of-day pulse is shorter than one LOGO! scan cycle (typically 10–50 ms depending on program size), the sample can be missed. Force the rollover flag to remain high for at least 100 ms to be safe.
  • If you cascade multiple counters, only the innermost Counter and the final MIN/MAX need remanence. Intermediate values can be live; they are reconstructed on every scan.
  • On 0BA6 the Reference function does not exist; the program must be wired strictly with block-number addressing. This pattern is fully supported on 0BA6, 0BA7, and 0BA8.
  • If you are using a weekly timer to generate the end-of-day flag, the timer output must be a boolean that toggles cleanly. A pulsed output (e.g., 1 s ON every 24 h) will work, but a sticky bit (e.g., Monday-ON until Tuesday-ON) will not produce a falling edge and B005 will never fire.

12. Frequently Asked Questions

Why does the Yesterday Total Count always display with a decimal point on LOGO! 0BA7/0BA8?

The MIN/MAX block internally scales its output to one decimal place (e.g., 500 = 50.0). Inserting an Analog Amplifier block with gain = 0.1 and offset = 0 in the signal path divides the value by 10 and removes the decimal, producing the integer display the application expects.

How do I keep both counters intact after uploading a Data Log from LOGO! Soft Comfort?

Open the properties of the Counter block (B001) and the MIN/MAX block (B004) and tick the Remanence checkbox on each. A Data Log upload forces the LOGO! through STOP and RUN, which is equivalent to a cold restart; only blocks with remanence retain their state across that transition.

Can I use the Math instruction block instead of the Analog Amplifier to drop the decimal?

No. The LOGO! Math instruction block does not accept block references on its operand inputs in any current firmware generation. Use the dedicated Analog Amplifier block (gain = 0.1) which does accept references and performs the same divide-by-ten operation in one block.

Why does the symbolic reference to B004 show as invalid when I port the program from 0BA7 to 0BA8?

Block references by symbolic name were introduced with LOGO! 0BA8. The legacy block-number addressing used in 0BA7 programs continues to work on 0BA8, but if you delete and re-insert a block the original number may change, breaking the wiring. Re-wire by selecting the new block in the input picker rather than re-typing the number.

What is the minimum end-of-day pulse width to guarantee that the MIN/MAX block latches the value?

Hold the end-of-day flag high for at least 100 ms. The MIN/MAX block only samples its input while the En pin is high, and a pulse shorter than the LOGO! scan cycle (typically 10–50 ms depending on program size) can be missed entirely.

Back to blog