Problem Overview
When configuring a Siemens SIMATIC HMI panel — Comfort Panel (TP/KP series), Unified Comfort Panel (MTP/ETP series), or a WinCC RT Professional runtime — in TIA Portal, a common pattern is to bind the InvertBit system function to a momentary pushbutton's Press event in order to toggle a Boolean tag (for example, M0.0) on each operator press. The button's appearance is animated to show a red flashing circle when the bit is 0 and a green flashing circle when the bit is 1.
Under a specific misconfiguration, InvertBit is bound to the Press event rather than the Release event. During runtime simulation — both with the TIA tag simulator and with PLCSIM — the tag M0.0 remains stuck at 0 and the red animation runs continuously, even though the operator is clearly pressing the button. The same tag toggles correctly when two separate buttons are used (one bound to SetBit, the other to ResetBit), proving that the tag, the HMI animation, and the PLC-side wiring are all functional. The defect is isolated to the event-function binding of the single toggle button.
Symptoms
- A Boolean tag (M0.0) does not transition from 0 to 1 when a button configured with
InvertBiton the Press event is actuated. - The same tag toggles correctly when
SetBit(rising-edge) andResetBit(falling-edge) are used on two separate buttons, confirming the tag and animation work in isolation. - The issue reproduces in both the TIA Portal PLCSIM-coupled HMI simulation and on the live panel firmware download.
- The associated HMI appearance animation (color/flashing circle) does not reflect a state change because the underlying tag never changes.
- Two
InvertBitcalls per physical press-release cycle cancel each other out, leaving the bit in its original state.
Root Cause Analysis
The Siemens HMI runtime evaluates Press, Release, and Click as three distinct event points on a momentary pushbutton:
- Press — leading edge, generated when the contact closes (finger touches the surface).
- Release — trailing edge, generated when the contact opens (finger leaves the surface).
- Click — combined event: a Press followed by a Release at the same screen coordinate, internally debounced by the runtime.
On Siemens Comfort Panel firmware revisions below V16 (and on certain early Unified Panel images), a single physical press can be reported by the touch controller as two contact closures in rapid succession, especially on capacitive panels under noisy electrical environments. When InvertBit is bound to the Press event, the runtime invokes the function twice in quick succession, toggling the bit 0→1→0 within milliseconds. The end state observed by the operator is the original value (0), even though two transitions occurred.
A second, more fundamental cause is operator-intent alignment. A toggle action should take effect when the operator commits the press — i.e., when the finger is lifted. Binding the toggle to Press means the action is registered before the operator has confirmed their intent, which is undesirable in process-control applications. The Siemens-recommended practice for a toggle on a momentary button is therefore to bind InvertBit to the Release event (or, where available, to the Click event on Unified Comfort Panels and WinCC RT Professional).
The root cause is reinforced by the official TIA Portal V20 documentation for the C-scripting InvertBit system function in WinCC RT Professional, which states: "Inverts the value of the given tag of the 'Bool' type: If the tag has the value of 1 (TRUE), it will be set to 0 (FALSE)." The function is non-atomic and non-idempotent: calling it twice in succession on the same tag is a logical no-op. This is precisely what happens when a single physical press is reported as two contact events.
Reference: InvertBit (RT Professional) – TIA Portal V20 Documentation.
Diagnostic Procedure
Before changing the configuration, perform the following checks to rule out other root causes:
-
Verify the tag binding. Select the button on the screen canvas, open Properties → Events → Press, and confirm the function list shows
InvertBitwith a parameter field referencing the HMI tag. If the parameter field is empty, the function executes against a null tag reference and the bit never changes. -
Verify the tag data type. Open the HMI tag table and confirm the data type of the bound tag is
Bool.InvertBitis defined only forBooltags; passing it to aWord,Int, orRealis silently rejected by the runtime and produces no transition. Per the Siemens TIA Portal V20 reference, the function is specified for "the given tag of the 'Bool' type". - Verify HMI vs PLC tag mapping. If M0.0 is a PLC tag, ensure the HMI tag is correctly mapped to the PLC address and the acquisition mode is set to Cyclic in operation (default) so the runtime sees updates within one acquisition cycle (typically 100 ms to 1 s depending on the configured cycle).
-
Verify the simulation mode. In TIA Portal, start the HMI simulation with the tag simulator enabled. If
InvertBitworks in tag simulation but not in PLCSIM-coupled simulation, the defect is in the HMI–PLC connection (PROFINET device name, IP address, area pointer, slot/rack), not in the event function. - Check the system event log. On WinCC RT Professional, enable the system diagnostic trace via Tools → Trace → System Events and watch for entries such as "Function call rejected" or "Tag type mismatch" when the button is pressed. Comfort Panels surface similar messages in the Control Panel → System Events log.
- Verify user authorization. If the operator lacks the required user rights for the button, the runtime silently rejects the event. Check the button's Properties → Security → Authorization setting.
If all six checks pass and the symptom persists, the root cause is the Press-vs-Release event selection, and the fix described in the next section applies.
Solution: Bind InvertBit to the Release Event
- In the TIA Portal project tree, expand the HMI device and open Screens → [target screen].
- Select the pushbutton object on the canvas.
- In the Inspector window, open Properties → Events.
- Expand the Release event category (not Press).
- From the system function list, select
InvertBit. - Click the function parameter field and choose the HMI tag bound to M0.0 (Bool type).
- Compile the HMI project (Project → Compile → Software (rebuild all)).
- Download to the panel or start the simulation with the tag simulator.
- Press and release the button. M0.0 toggles 0→1→0→1 on each release event.
The Press event is the leading edge; on touch panels, a single operator finger press can register as multiple contact events depending on capacitive-noise filtering and firmware debounce settings. The Release event is the trailing edge and is generated exactly once per completed press. For a toggle, the operator's intent is confirmed at release, which matches the engineering intent of InvertBit and avoids the double-call no-op.
Event Timing Comparison
The diagram below illustrates the runtime's view of a single physical press on a panel that reports a contact-bounce event. Note the double Press edge and the resulting double InvertBit call when bound to Press, vs the clean single call when bound to Release:
Alternative Solution: Use the Switch Graphic Object
For applications where the user expects a sticky on/off control — a light-switch graphic, a maintain-state toggle, or a run/stop selector — Siemens recommends the Switch object instead of a momentary button with InvertBit.
- From the Toolbox panel, expand Controls and drag a Switch onto the screen.
- In Properties → General, set the Process Value property to the M0.0 HMI tag.
- The switch automatically reflects the current bit value and writes the opposite value to the tag when tapped. Internally, the switch encapsulates the equivalent of
InvertBit. - Bind the appearance animation (red/green flashing circle) to the same tag's appearance property using the standard Siemens animation dialog.
This approach removes the event-binding question entirely because the switch object encapsulates the toggle logic. It is also more intuitive for the operator, who sees a graphic that visually represents the on/off state.
Alternative Solution: Two-Button SetBit/ResetBit Pattern
If a single toggle button is not strictly required, retain the proven two-button pattern:
-
Button A (ON): Press event →
SetBit(M0.0) -
Button B (OFF): Press event →
ResetBit(M0.0)
This pattern is robust because SetBit and ResetBit are idempotent: pressing Button A twice in a row does not un-set the bit, which avoids the double-toggle hazard of InvertBit on a misbehaving event. The trade-off is screen real estate — two buttons occupy more space than one.
Advanced Alternative: C-Script in WinCC RT Professional
On WinCC RT Professional, InvertBit is also exposed to C scripting. The official signature from the TIA Portal V20 documentation is:
void InvertBit(Tag& tag);
For full control over the toggle, an engineer can write a C action that debounces the input and only calls InvertBit on the rising edge of a confirmed click:
static int lastState = 0;
int currState = GetTagBit("HMI_Tag_M0_0");
if (currState != 0 && lastState == 0) {
// Rising-edge detected: confirmed click
InvertBit(GetTagObject("HMI_Tag_M0_0"));
}
lastState = currState;
However, this approach is only necessary for highly specialized applications; in the vast majority of cases, switching the event binding to Release is the correct and simplest fix.
Verification Procedure
After applying the Release-event fix, perform the following checks to confirm the solution:
- Tag simulator check. In TIA Portal, start the HMI simulation with the tag simulator enabled. Add the M0.0 HMI tag to the simulator's watch list. Each button press-release cycle should toggle M0.0 between 0 and 1 exactly once.
- Animation feedback check. The flashing circle animation should switch between red (M0.0 = 0) and green (M0.0 = 1) on every release. If the animation lags by more than 500 ms, the HMI tag's acquisition cycle may be set too long; reduce it to 100 ms for snappier feedback.
- PLCSIM cross-check. Couple the HMI simulation to PLCSIM and add M0.0 to a PLC VAT (Variable Table). Each release should flip the bit visible in the PLC within one PROFINET cycle (typically 1–4 ms).
- Live panel check. Download the compiled project to the physical Comfort or Unified panel. Verify the same toggle behavior with a finger press-release on the touch surface.
- Long-press test. Hold the button for 5 seconds; on release, M0.0 should toggle exactly once. If it toggles multiple times, the firmware revision may have a debounce issue. Update to the latest panel image available on Siemens Industry Online Support.
- Rapid-tap test. Tap the button rapidly (5 taps in 2 seconds). After stabilization, M0.0 should reflect the parity of the tap count (5 toggles → back to 0 if started at 0). This confirms deterministic edge handling.
HMI Event Model Reference
The Siemens HMI runtime exposes the following standard events on a Button object (TIA Portal WinCC Comfort/Advanced, Unified Comfort Panels, and WinCC RT Professional):
| Event | Edge | Typical Use Case |
|---|---|---|
| Press | Rising (contact close) | SetBit, momentary action start, "press and hold" interaction |
| Release | Falling (contact open) | InvertBit, ResetBit, action confirmation |
| Click | Press + Release debounced | Single-shot toggle, debounced interaction |
| Change | State transition | Internal animations, dependent property updates |
| Activate | Screen activation | Initialize tag values on screen open |
| Deactivate | Screen deactivation | Cleanup, save state on screen close |
For toggle semantics, Click is the most explicit event because it is debounced by the runtime and represents a complete press-release cycle. Where available (Unified Panels, WinCC RT Professional V16+), prefer Click over Release for InvertBit.
InvertBit System Function — Full Reference
Per the TIA Portal V20 documentation (InvertBit (RT Professional)):
| Property | Value |
|---|---|
| Function name | InvertBit |
| Category | System functions → Bit operations |
| Signature (C) | void InvertBit(Tag& tag); |
| Return value | void (none) |
| Parameter | A reference to an HMI tag of type Bool
|
| Behavior | Reads the current value, computes its logical NOT, writes the result back. Non-atomic. |
| Supported panels | SIMATIC Comfort Panels (TP/KP), Unified Comfort Panels (MTP/ETP), WinCC RT Advanced, WinCC RT Professional |
| Minimum firmware | Comfort Panels V13, Unified Panels V15, RT Professional V13 |
| Not supported for | PLC tags directly; an HMI tag must be mapped to the PLC address |
| Idempotency | Non-idempotent; double-call within a single scan is a no-op |
Related System Functions
| Function | Purpose | Idempotent? | Notes |
|---|---|---|---|
| SetBit | Force tag to TRUE (1) | Yes | Use for one-way ON control |
| ResetBit | Force tag to FALSE (0) | Yes | Use for one-way OFF control |
| InvertBit | Toggle tag value | No (double-call = no-op) | Use for momentary toggle button on Release event |
| SetTag | Write arbitrary value to tag | No | Use for Word, Int, Real, Byte types |
| GetTag | Read current tag value | Yes | Use in scripts for branching logic |
| SetTagBit | Set a specific bit in a Word/Int tag | Yes | For bit-level access in non-Bool tags |
| ResetTagBit | Reset a specific bit in a Word/Int tag | Yes | For bit-level access in non-Bool tags |
Firmware Version-Specific Behavior
The Press-vs-Release toggle defect is most commonly observed on the following firmware loads:
| Panel Family | Affected Firmware | Fixed In | Recommended Action |
|---|---|---|---|
| Comfort Panels (TP700–TP2200) | V13.0.x, V14.0.x | V16.0.4+ | Update via HSP or TIA Portal project transfer |
| Unified Comfort Panels (MTP700–MTP2200) | V15.0.x, V15.1.x | V16.0.0+ | Update via TIA Portal V17 or later |
| WinCC RT Advanced | V13 SP1, V14 SP1 | V16 Update 4+ | Update RT Advanced installation |
| WinCC RT Professional | V13, V14, V15 | V16+ | Update RT Professional installation |
Even on the latest firmware, binding InvertBit to Press is not recommended because the operator-intent argument remains. Always use Release or Click for toggle operations.
Troubleshooting Matrix
| Symptom | Likely Root Cause | Fix |
|---|---|---|
| InvertBit on Press does not toggle | Double-edge coalescing; Release also bound | Move InvertBit to Release event; remove Press binding |
| Tag stays at 0 after first press, toggles after second | Authorizing user missing | Assign correct user authorization to the button |
| Tag toggles in tag simulator, not in PLCSIM | HMI–PLC connection issue | Verify PROFINET device name, IP, area pointer |
| Tag does not exist error in HMI alarm log | HMI tag not mapped to PLC | Create mapping in HMI tag table |
| Multiple toggles per press | Contact bounce + debounce too low | Update firmware; or use SetBit/ResetBit pattern |
| No event fires at all | Button disabled by animation state | Check Properties → Appearance → Operator control enable |
| Compilation warning: "Tag type mismatch" | Wrong tag type bound to InvertBit | Bind only to Bool HMI tag |
Field-Proven Caveats
- Debounce on older firmware: On Comfort Panel firmware V14 and earlier, a Press event can be generated twice within a single physical press. Updating to V16 or later resolves the contact-bounce issue at the firmware level.
- Screen layer trap: If the button is on an animated layer (slide-in / fade-in), the Press event can be eaten by the layer swap. Always test toggle behavior on the base screen first.
- User authorization: If the operator does not have the required authorization for the button, the Press event is rejected silently. Check Properties → Security → Authorization.
-
Multiple events on one button: Binding
InvertBitto both Press and Release is a common mistake and causes a double-toggle per press-release cycle. BindInvertBitto exactly one event. - Animation priority: If the appearance animation has a higher event priority than the toggle function, the visual feedback can update before the tag is written. To avoid flicker, set the appearance animation to update on tag value change (not on event).
-
PLC scan time vs HMI cycle: The PLC may read M0.0 between the two
InvertBitcalls, see no net change, and never trigger a downstream action. This is rare but worth knowing in fast-scan applications.
Best Practice Checklist
- Bind
InvertBitto Release on a momentary pushbutton, never to Press. - Confirm the bound HMI tag is of type
Boolbefore compiling. - Prefer the Switch object for maintain-state toggles.
- Set the HMI tag acquisition cycle to ≤ 100 ms for responsive feedback.
- Update panel firmware to V16 or later to eliminate contact-bounce.
- Test toggle behavior in both the tag simulator and PLCSIM before downloading to the live panel.
- Verify the operator's user authorization matches the button's required rights.
FAQ
Why does InvertBit on the Press event not toggle my tag on a Siemens Comfort Panel?
The Press event is a leading-edge event and on certain panel firmware loads (especially below V16) the runtime can coalesce Press and Release within a single scan, causing InvertBit to be called twice and the bit to return to its original state. Bind InvertBit to the Release event (or the Click event on Unified panels) to fix it.
Can I bind InvertBit to a PLC tag directly in TIA Portal?
No. InvertBit operates on HMI tags of type Bool. Create an HMI tag of type Bool, map it to the PLC address (for example M0.0 or %MW0), and bind InvertBit to the HMI tag. The runtime propagates the change to the PLC on the next acquisition cycle (typically 100 ms).
What is the difference between InvertBit and SetBit/ResetBit for a toggle button?
InvertBit reads the current value, inverts it, and writes it back, so it depends on the runtime's view of the tag state and is non-idempotent. SetBit/ResetBit unconditionally force the tag to 1 or 0 and are idempotent. For a single momentary button used as a toggle, InvertBit on the Release event is the canonical pattern; for two separate On/Off buttons, SetBit and ResetBit are more robust.
Which Siemens HMI panels support InvertBit?
InvertBit is supported on SIMATIC Comfort Panels (TP/KP series, firmware V13 and later), Unified Comfort Panels (MTP/ETP series, V15 and later), WinCC RT Advanced, and WinCC RT Professional. It is not supported on older OP/TP170 or basic panels.
How do I verify the toggle in TIA Portal without a physical panel?
Start the HMI simulation in TIA Portal with the tag simulator enabled. Add the M0.0 HMI tag to the simulator's watch list and observe its value while pressing and releasing the button on the simulated screen. Each complete press-release cycle should produce exactly one 0→1 or 1→0 transition when InvertBit is bound to the Release event.