Saving Siemens LOGO! Counter Values: VM Mapping and Retentivity
The Siemens LOGO! logic module stores counter actual values as 32-bit signed double integers (DInt, DWord). To survive a power loss, retain the value across a program stop/start, or expose the count to an HMI panel, the value must be copied into the volatile variable-memory (VM) area using the VM mapping parameter of the counter block. This reference details every step required to retain a counter across power-down, map it to a VD register for a Weintek HMI, and avoid the common +32767 saturation pitfall in the analog network output.
1. Overview of the LOGO! Counter Memory Model
The Up/Down Counter block (block number B003) and the Counter function (B002) in LOGO!Soft Comfort V8.x and V8.4 always expose their actual value as a 32-bit signed integer occupying 4 bytes in the LOGO! internal image. The value is only kept in the module's volatile work memory by default; a loss of supply voltage, a STOP-to-RUN transition triggered by an empty program, or the download of a modified program resets the actual value to zero.
Two mechanisms make the value persistent or externally visible:
| Mechanism | Survives power loss? | Survives program download? | Visible to HMI? |
|---|---|---|---|
| Default (no retentivity, no VM) | No | No | No |
| Block retentivity flag (Rem = on) | Yes | No — value is reset to 0 when a new program is transferred | No (not in HMI tag space) |
| VM mapping (Parameter VM Mapping) | No by itself — VM is volatile unless backed by retentivity | No | Yes — VD/VW/VB registers can be polled by Modbus or read by an HMI |
| Block retentivity + VM mapping (recommended) | Yes | No | Yes |
The official LOGO! manual LOGO! 0500 manual (A5E00067781) describes the block-level retentivity switch on the counter function in section "LOGO! Functions, page 112". The companion LOGO! manual (logo_e_09_99) repeats the same parameter definition for the Cnt counter block on page 89/97.
2. Prerequisites
- LOGO!Soft Comfort V8.1 SP1 or later (V8.4 recommended for the LOGO! 8.2 devices).
- LOGO! 0BA8 base module (any variant). For VM mapping to a real HMI, at least LOGO! 8 with Ethernet or LOGO! 7 with the LOGO! TD/AM2 RTD on RS-232.
- Counter block (B002) or Up/Down Counter (B003) inserted in the FBD program.
- Optional: Weintek cMT Series or MT Series HMI with Ethernet. The integration procedure below uses EasyBuilder Pro V6.x or later.
- Active Ethernet connection between LOGO! (port on 0BA8) and the HMI. Static IP assignment in the LOGO! is recommended.
3. Configuring Block Retentivity on the Counter
Open the counter block in LOGO!Soft Comfort and switch to the block properties dialog (double-click the block, or right-click > Block Properties). Locate the Remanence (Rem) checkbox in the lower part of the dialog and tick it. The block graphic then displays an "R" glyph at the counter output to indicate the value is now retained across power-down.
- Select the counter block on the FBD diagram.
- Right-click and choose Block Properties.
- In the dialog, scroll to the Remanence field and set the retentive bit
on. - Click OK. The counter block now shows the retentivity flag in the diagram.
- Download the program to the LOGO! module with PC → LOGO! transfer.
4. Mapping the Counter Actual Value to VM
Retentivity keeps the value inside the LOGO! but does not expose it to the HMI. To make the value visible to external devices, open the block properties of the counter and configure the VM Mapping parameter. The VM address format is VD<base>, VW<base>, or VB<base>, depending on the data type the HMI expects.
- Open the counter block properties.
- Click the VM Mapping field. LOGO!Soft Comfort offers a free address in the VM area automatically.
- Accept the suggestion, or enter a manual address. For a 32-bit counter actual value, use a
VDaddress (e.g.VD0,VD4,VD8, ...). Each VD consumes 4 bytes. - Click OK. The diagram now shows a small VM symbol next to the counter output.
- Repeat the procedure for any other counter that must be exposed.
The available VM size depends on the LOGO! device:
| Device | VM bytes | Useful range for user data | Max VD count |
|---|---|---|---|
| LOGO! 0BA7 | 256 B | VB0 – VB255 | 64 |
| LOGO! 0BA8 Standard | 850 B | VB0 – VB849 | 212 |
| LOGO! 0BA8 FS04+ | 1300 B | VB0 – VB1299 | 325 |
| LOGO! 8.1 (0BA8.1) | 1300 B | VB0 – VB1299 | 325 |
| LOGO! 8.2 (0BA8.2) | 2000 B | VB0 – VB1999 | 500 |
Reserve the lower 48 bytes (VB0 – VB47) for the LOGO! system markers; user-defined mappings are normally placed at VD48 and higher to avoid colliding with the network input/output areas, the analog flag bytes, and the S7-compatible marker region.
5. Addressing the Counter from a Weintek HMI
The Weintek HMI communicates with the LOGO! over Modbus TCP (port 502) or via Siemens S7/LOGO! drivers. With the S7-200 ISO-on-TCP driver the LOGO! exposes the VM area at the symbolic address VW<n> or VD<n>, which is why the LOGO! manual calls them VD/VW/VB registers.
In EasyBuilder Pro:
- Create a new project for the Weintek panel (e.g. MT8071iE or cMT3072X).
- Add a new Siemens LOGO! (S7-200) device. Set the LOGO! IP and rack/slot 0/1.
- Insert a Numeric Display object. Click the Read Address field and enter
VD<base>wherebasematches the VM mapping configured in the LOGO! counter block properties (e.g.VD0if the counter was mapped to VM address 0). - Set the display data format to 32-bit Signed (DInt). A 16-bit display will read only the low word and saturate visually at 32767 even though the LOGO! counter internally holds higher values.
- For a writeable counter (manual reset from the HMI), insert a Numeric Input bound to the same
VDaddress and enable the Use write address option. - Download the project to the HMI. Cycle the LOGO! power once to confirm that the HMI reflects the new value after the next Modbus poll.
6. Avoiding the 32767 Saturation Pitfall
The LOGO! analog network output and the Mathematical Instruction block both internally process values as 16-bit signed integers. If the counter actual value is wired directly into a math block or into an analog flag/analog output network node, the output saturates at +32767 once the count exceeds 32767 counts. This is a soft saturation, not an overflow — the counter itself keeps counting in 32-bit space.
To avoid the saturation when the application needs values above 32767:
- Read the count from the VM-mapped
VDdirectly, not from the analog output node of the counter block. - If the HMI is the only consumer, skip the math block and bind the HMI tag to the
VDmapped in section 4. - If a math operation is required above 32767, scale the value with the math block: read the high word
VW<base+2>(multiplied by 65536) and add the low wordVW<base>. Alternatively, swap the analog path for a counter-to-PWM converter with a 32-bit integer follow-up block. - On the Weintek HMI, the Numeric Display object can apply its own scaling: Linear Scale with input range −2,147,483,648 to 2,147,483,647.
7. Program Download Requirements
A frequent error reported by users attempting to save counter values to a LOGO! 0BA8 is that the program download fails with the message "The output of the count block needs to be terminated to an X / M / Q". The LOGO!Soft Comfort compiler enforces that every block output that carries a state must be wired to at least one of:
- A digital input
I(only as a feedback reference, not physically), - An open connector
X, - A marker
M(digital flag) or analog flagAM, - A digital output
Qof the base module or an attached DM/SM/AM expansion module.
When the counter is used purely as a data source for the VM, terminate the block output to a marker M1 that is unused elsewhere. This satisfies the compiler, the simulation runs, and the program can be transferred.
8. Step-by-Step Procedure: Counter Persistence + HMI Display
- In LOGO!Soft Comfort, drop an Up/Down Counter block (B003) on the FBD diagram.
- Connect a digital input to the Count trigger and a second input (or constant) to the Direction trigger.
- Open the counter block properties. Tick Remanence = on and set the threshold to the maximum useful count, e.g.
100000for a 100,000-pulse product counter. - In the same dialog, click the VM Mapping field. Accept the next free address; the cursor lands on
VD48for a fresh project. - Drag from the counter output to an open connector or to a free marker
M1so the compiler is satisfied. - Compile the program with F5. Resolve any errors until the status bar shows "no errors".
- Connect the LOGO! to the PC, click PC → LOGO!, and transfer the program.
- Power-cycle the LOGO!. The counter actual value should remain at the last value before the power-down.
- On the Weintek HMI, add a Numeric Display with read address
VD48, data type 32-bit Signed, and minimum/maximum −2147483648 / 2147483647. - Cycle the LOGO! power again. Confirm that the HMI still shows the retained count after the LOGO! reboots.
9. Verification Procedure
After implementation, run the following checks:
- Power-loss test: Disconnect the LOGO! supply, wait 10 seconds, reconnect. The counter should resume at the last value.
- Reset test: Pulse the Reset input of the counter. The HMI should drop to 0 within one Modbus poll cycle (typically 200 ms on the LOGO! 8).
- Overflow test: Drive the count input faster than 5 Hz and observe the HMI value climbing past 32767 without flattening. This validates that the 32-bit path is used end-to-end.
- Program-change test: Make a cosmetic edit to the FBD diagram and re-download. The counter value is allowed to reset to 0 in this case — document this in the operating procedure.
10. Troubleshooting Matrix
| Symptom | Probable cause | Resolution |
|---|---|---|
| HMI always shows 0 even though the count input is pulsing | VM mapping is missing on the counter block | Open block properties > VM Mapping > assign a free VD address |
| HMI shows a constant value after a power cycle | Retentivity is off, or VM is mapped to a non-retentive area | Enable block retentivity (Rem = on) |
| Count resets to 0 after a program change | Normal behavior — retentive flags are cleared on transfer | Use a data log block on LOGO! 8.2 or restart the process manually |
| HMI saturates at 32767 | Display object is bound to a 16-bit register or analog output | Rebind to the 32-bit VD and set the data type to 32-bit Signed |
| Download fails: "output of the count block needs to be terminated" | Counter block output is unconnected | Wire the output to marker M1 or to an open connector |
| HMI shows wrong value (e.g. 32x the real count) | Endianness mismatch between LOGO! (little-endian) and a custom driver | Use the Weintek LOGO! driver which auto-swap; otherwise enable byte swap in the HMI tag |
| Counter drifts after many power cycles | Battery-less module loses retentive data after 80 hours of powered-off storage | Install the LOGO! battery cartridge 6ED1971-2BA00 or use an SD card data log |
11. Field-Proven Caveats
- The LOGO! retentive memory uses a small supercapacitor or an optional battery. Without the battery cartridge, retentive data decays within roughly 80 hours of powered-off storage; the counter value can quietly drift to zero on long shutdowns.
- Counter inputs above 5 Hz must be debounced in the LOGO! block parameters, otherwise false counts can occur on noisy mechanical contacts.
- The HMI Read/Write cycle through Modbus TCP on the 0BA8 base module is limited to a single connection. Multiple HMIs require a switch and multiple LOGO! sessions — only one is allowed at a time.
- When the program is in STOP, the LOGO! clears the actual value of all blocks regardless of retentivity. Bring the module back to RUN with the same program to resume.
- Always perform a final live test with the actual field sensor connected — simulations in LOGO!Soft Comfort will not detect input-wiring or debounce problems.
12. FAQ
Why does my Siemens LOGO! counter lose its value after a power loss?
By default, the counter block is not retentive. Open the block properties and set the Remanence (Rem) flag to on so the actual value is stored in the retentive memory of the LOGO!. Without the optional battery cartridge (6ED1971-2BA00) the value can still decay after roughly 80 hours of powered-off storage.
How do I send a counter value to a Weintek HMI?
Enable the VM Mapping on the counter block properties and assign a VD address (e.g. VD48). In EasyBuilder Pro, create a Numeric Display bound to the same VD48 address using a Siemens LOGO! (S7-200) driver and a 32-bit Signed data type. Cycle the LOGO! power once to confirm the HMI tracks the retained value.
Why does the HMI display stop at 32767 even though the counter is higher?
You are reading a 16-bit signed integer. The counter is internally a 32-bit DWord. Either bind the HMI tag to the 32-bit VD address with a 32-bit Signed data type, or use the high and low VW words and reconstruct the value on the HMI. Avoid wiring the counter output into a math or analog output block, which is intrinsically 16-bit and saturates at 32767.
Why does my program refuse to download to the LOGO! with a counter block?
The compiler requires that every block output is wired to a marker (M), open connector (X), or output (Q). Connect the counter output to a free marker such as M1 to satisfy the rule, then transfer the program again.
Does counter retentivity survive a program download?
No. Downloading a new or modified program resets every retentive flag and clears the counter actual value to zero. Use the data log function on the LOGO! 8.2 with an SD card if you need to persist the count across program edits.