S7-200 32-Bit Counter: Resolving Multiple-Call Errors

David Krause3 min read
S7-200SiemensTroubleshooting
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

When one S7-200 32-bit library counter works but multiple calls jump by tens or hundreds, inspect the library administration byte before changing the preset or sensor. The reported case used separate current-value double words, yet every library call shared one configured Library Memory byte. That shared state is the leading fault hypothesis.

Observed failure pattern

The affected application counted conveyor bags at approximately one event every 2–3 seconds, occasionally one every 30 seconds. A single counter advanced normally as 1, 2, 3. Adding a second counter caused both values to increase irregularly, sometimes by tens or hundreds.

Item Reported configuration Assessment
Engineering software MicroWin 4.0.4.16; later upgraded to SP9 An upgrade alone does not remove a memory collision.
CPU CPU 224, 02.01, 214-1BD23-0XB0 Environment in which the symptom was observed.
Expansion module EM277 PROFIBUS DP, 277-0AA22-0XA0 No evidence identifies this module as the cause.
Preset 2147000000 No evidence connects the preset to the jumps.
Counter values VD200 and VD204 Separate current-value locations; verify that no other tags overlap them.
Library Memory One globally configured V byte Likely shared administration state across calls.

Why separate CV addresses are insufficient

Each counter call has its own CV, but the library also requires a V-memory byte for internal administration. MicroWin exposes only one Library Memory assignment rather than an administration-byte parameter on each counter call. Multiple calls can therefore reuse the same internal byte.

Keep both kinds of storage exclusive. A byte such as VB0 also lies inside VW0 and VD0, and its individual bits occupy V0.0 through V0.7. Assigning VB0 to the library while logic uses any overlapping bit, word, or double word can corrupt the library state. Likewise, each CV double word must not overlap another tag.

Decision path

  1. Run only the first counter. If it increments once per detected bag, record that result.
  2. Add the second counter without changing the physical input conditions. If irregular jumps begin, prioritize shared library state and overlapping V memory.
  3. Audit the configured Library Memory byte and every bit, byte, word, and double word that crosses it.
  4. Audit VD200 and VD204 against the complete symbol and memory map.
  5. Monitor the count-enable condition. If it remains true for multiple scans, the logic can add repeatedly even when the library memory is isolated.

Isolate the administration state for each call

If the library must remain in use, preserve a different administration byte for each counter around the single globally assigned Library Memory byte. The following evidence-supported pattern assumes VB100 is configured as Library Memory, VB101 stores counter 1 state, and VB102 stores counter 2 state:

Move VB101 to VB100
Call counter 1 library instruction
Move VB100 to VB101

Move VB102 to VB100
Call counter 2 library instruction
Move VB100 to VB102

Repeat the load-call-save sequence for each additional instance, using a unique nonoverlapping storage byte. Do not access VB100, VB101, or VB102 elsewhere as bits or as parts of words or double words.

Alternative and verification

The simpler architectural alternative is application logic that adds to a DINT current value instead of relying on shared library administration memory. The evidence identifies ADD_DI as the relevant addition instruction, but it does not supply complete edge-detection or rollover logic. Preserve the existing preset behavior explicitly if replacing the library.

Verify either correction against the physical sensor: one qualified bag event must produce exactly one increment in only the intended counter. Test each counter alone, then all counters together. Watch the administration bytes, CV values, and count-enable conditions concurrently. If a CV still jumps while its administration storage remains unchanged by other logic, determine whether the enable condition spans multiple PLC scans and reset or edge-qualify it as required.

FAQ

Why does an S7-200 32-bit counter jump when I add a second counter?

The leading cause in this case is multiple library calls sharing the one globally configured Library Memory byte. Isolate each call's administration state with a unique byte and also check whether the count condition remains true for multiple scans.

Can two S7-200 counters use VD200 and VD204?

Those are separate CV locations in the reported configuration, but both must remain exclusive throughout the memory map. Also verify that no bit, byte, or word tag overlaps either double word.

How do I give each MicroWin library counter its own memory byte?

Configure one working byte such as VB100 in Library Memory, then load a counter-specific byte into VB100 before each call and save VB100 back afterward. For two calls, the supported pattern uses VB101 for counter 1 and VB102 for counter 2.

Back to blog