A two-position switch object with no polarity setting writes a fixed value from each position: one position writes 0, the other writes 1. Leave the bitmap and the raw tag alone and invert the Boolean once in one mapping point, so the written 0 drives the machine command 1 and the written 1 drives the command 0. Test both drawn positions with the machine outputs isolated.
A two-position switch object with no polarity option writes a fixed value from each position, and no editor setting will change that. You do not need it to. Keep the bitmap and the switch exactly as they are, and invert the Boolean once, in one named mapping point between the switch and the machine command: the position that writes 0 drives the command 1, and the position that writes 1 drives the command 0. Use NOT, or XOR against the constant 1. Then test both drawn positions with the machine outputs isolated before the command path runs the machine again. This page covers the case where the switch sits over a fixed graphic, such as a bitmap of an older operator terminal, so the drawing decides what each position has to mean.
Symptoms and what each one points to
Match what you see to a cause before you change anything:
- The machine runs when the drawing points at STOP and stops when it points at RUN. The command path reads the raw tag, so the drawing and the written bit are opposites.
- The label edit changed nothing on the floor. The
"Off Text"and"On Text"properties change what the object prints and the colors behind the text. The value each position writes comes from the object's output mapping, which the default switch keeps fixed. - The polarity was right until a project change and wrong after it. Someone added a second inversion, in the editor or in the logic, and two inversions cancel.
- The command flips twice per press or drifts between presses. The XOR sits in an event action, so it adds a flip each time it fires, or its second input is a value that changes.
All four have one fix: exactly one inversion, in a place with a name.
The fix: one inversion in one named place
Put the whole inversion in one place:
- In the HMI, as a mapped or scripted tag that carries the inverted value, when the HMI software supports one.
- In the PLC, as one rung or block at the interface between the panel and the machine logic, when maintenance reads the PLC program.
For a BOOL the inversion is NOT x, which returns the same result as x XOR 1. IEC 61131-3, the standard that defines the common PLC languages, defines NOT and XOR as Boolean operators. Both forms exist in ladder, in function block and in structured text. Name the mapping after the machine function, with an example name such as conveyor_run_cmd, so maintenance finds it where they already look.
The mapping reads:
| Value the switch writes | Mapped machine command |
|---|---|
| 0 | 1 |
| 1 | 0 |
The raw tag keeps its values. Diagnostics, alarms and anything else that reads it still see the raw bit; only the command path sees the inverted value. If the selector must drive more than two machine states, rebuild it as logic in the PLC: a forward-off-reverse selector driven by a PLC state machine shows that layout.
Why XOR against 1 inverts and XOR against a variable toggles
XOR against a fixed 1 maps a Boolean to its opposite: 0 XOR 1 gives 1, and 1 XOR 1 gives 0. The same operator becomes a toggle in two cases. Placed in an event action that fires once per press, every press adds one more flip, so the command alternates. Placed against a second input that changes, the command follows that input's changes. Compute the command from the tag's current value on every scan, and keep the presses and the changing inputs out of it. An event-driven flip is a one-shot, and a one-shot stands or falls on its reset path; PLC flag triggers an HMI event once: check the reset path covers that failure in detail.
Example: a selector over a fixed terminal bitmap
Scenario. A conveyor cell keeps the faceplate of its older operator terminal as a bitmap, because the panel layout cannot change. The engraving puts the RUN mark where the overlay switch object writes 0 and the STOP mark where it writes 1. Both tags are BOOL: selector_bit is the tag the switch writes into the PLC, and conveyor_run_cmd is the command the machine logic reads. The conveyor normally runs at about 0.5 m/s, so a reversed stop command moves real product in the wrong direction.
The inversion goes in one PLC interface block:
conveyor_run_cmd := selector_bit XOR 1
Checked at both drawn positions:
- RUN mark: selector_bit = 0, so conveyor_run_cmd = 0 XOR 1 = 1. The command is 1, run, and the drawing says RUN.
- STOP mark: selector_bit = 1, so conveyor_run_cmd = 1 XOR 1 = 0. The command is 0, stop, and the drawing says STOP.
Hold each drawn position for 30 seconds and watch the command stay put. Then test four transitions: each position held, and each change of position, drawn RUN to drawn STOP and drawn STOP to drawn RUN. Every check shows exactly one inversion, so the drawing and the machine agree.
Test before the command path returns to service
- Back up the HMI project and write down the tag the switch writes and the value it holds at each drawn position.
- Place the inversion in the one mapping point. Leave the bitmap, the switch object and the raw tag untouched.
- Isolate the machine outputs or hold the machine in a controlled test state. Do not use a live machine response as the first polarity test: a reversed command starts equipment while the operator expects it to stop.
- Select each drawn position and read the raw tag and the mapped command on two consecutive scan cycles. Each command must equal the drawing's meaning at that position.
- Cycle both directions, one drawn position to the other and back, and watch the command follow the drawing each time. Wait at least 2 seconds at each position so any delayed write shows up.
- Prove the writes with the drives disabled before motion is allowed. Operator panel PLC link setup: test writes before motion walks through that test.
After the outputs go back in service, verify the chain once more in both directions: screen position, raw tag, mapped command, machine response. If the screen also shows machine feedback, invert the feedback mapping in its own point so the lamp agrees with the drawing.
Recommendation
Recommendation: keep the fixed bitmap and the raw tag exactly as they are, and invert the Boolean once, in one named mapping point between the switch and the command, using NOT or XOR against the constant 1. Test each drawn position with the outputs isolated, then both directions of travel, before the command path runs the machine. If your editor offers a polarity option on the switch object, use it and remove the mapping inversion, so the polarity still exists in exactly one place.
Write the exception down
Record three things where maintenance reads them: the bitmap is fixed and decides what each drawn position means; the visible polarity is intentionally opposite the bit the switch writes; the inversion lives in one named place, with the tag names written out. Note that the raw tag still holds its written value at each position, so nobody adds a second inversion or relabels the object to match the drawing. A mapping named after the machine function, next to the panel, gives the next person the whole story before they change anything.
Questions
Why did editing the Off Text and On Text labels change nothing?
Those properties change the text the object prints and the colors behind it. The value each position writes comes from the object's output mapping, which the default switch keeps fixed. With a fixed bitmap the engraving decides what each position means, so relabeling cannot close the gap; invert the value once in the mapping.
What changes for a three-position selector?
A three-position selector writes two bits or an integer code, so a single XOR against 1 is the wrong tool. Map each position to its command explicitly, one line per position, in the same single named place. Two bits inverted one at a time can produce a command code that no drawn position represents, so map the whole code and test every position of the selector.
What about the lamps that show state on the same screen?
Decide what each lamp is supposed to show. A lamp driven by the machine feedback bit shows what the machine did; a lamp driven by the selector tag shows what was commanded. Map the feedback path in its own inversion point, separate from the command mapping, and check the pair in both directions so a stopped machine never reads as running.
Does XOR against 1 work in every PLC language?
IEC 61131-3 defines XOR as a Boolean operator in each of its languages, and XOR against the constant 1 returns the opposite of a BOOL. In structured text write it as an expression; in ladder or function block place a NOT block, or an XOR against a constant TRUE. The two forms are equivalent, so choose the one your maintenance staff reads fastest and test both values, 0 and 1, after placing it.
Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.