When intermediate flags multiply, M devices run short, or you want block snapshots, using the 16 bits of one data register D as 16 flags is standard practice: individual bits read and write directly (D100.3), and the whole word copies in one instruction. Done well it saves resources and is elegant; done casually it becomes a mine where "a bit vanished and nobody can find where". The sections below cover the syntax, read/write, snapshot and the rules.
| Operation | Syntax (ladder/ST) | Meaning |
|---|---|---|
| Read a bit | LD D100.3 | Conducts when bit 3 of D100 is ON |
| Write a bit | SET D100.3 / RST D100.3 | Set or reset bit 3 alone |
| Whole-word test | LD= D100 K0 | All 16 flags OFF test |
| Whole-word snapshot | MOV D100 D200 | 16 flags backed up in one instruction |
Platform note: Mitsubishi FX3U/FX5U support bit designation on word devices (D100.3); older series or some brands do not — there, use WAND/WOR/WXOR bit arithmetic for indirect access (below). Confirm which style your platform supports before coding.
Read bit n: D100 AND K(2^n) — non-zero means ON. Set: D100 = D100 OR K(2^n). Reset: D100 = D100 AND NOT K(2^n) (masked AND with the inverted mask). Wrap "set / reset / read" into three small function blocks taking the D address (or a fixed block plus bit number), so the whole project calls them uniformly instead of hand-writing masks everywhere.
① A step's sub-states (waiting / running / done / fault) live in one word's four bits, and whole-state tests become word comparisons (D100 = K8 means "done") — cleaner than four separate Ms. ② Alarm/permission flag groups snapshot wholesale: MOV to the backup area before a stop, restore after — 16 flags saved and restored in one instruction each. With BMOV, a row of Ds (D100~D103) becomes a 64-flag group whose backup is still a few instructions.
| Rule | Reason |
|---|---|
| Bit-purpose table in the comments | What D100.0~.15 each mean, written down — otherwise in three months nobody knows what .7 does |
| One word, one owner | Two logics writing different bits of one word; one bad mask and they trample each other |
| No whole-word assignment on shared words | MOV K0 D100 clears the bits other functions own |
| Comms mapping words kept separate | Host-side word reads should not mix with flag groups |
The biggest mine is the third: "clearing the flag word with a quick MOV K0" — other functions' bits die with it. Shared words clear only through bit operations on your own bits, or through one agreed clearing point.
| Symptom | Cause | Fix |
|---|---|---|
| A flag "disappears by itself" | A whole-word assignment elsewhere overwrote it | Find the MOVs, switch shared words to bit operations |
| Masked set corrupts other bits | Mask miscalculated / OR written as addition | Use the packaged set/reset blocks |
| Host reads garbage flags | Byte order / nibble alignment differs | Agree alignment with the host and test once live |
| Restored snapshot partly wrong | Snapshot and restore areas mismatch | Pair them on the same parameters |
| Nobody knows a bit's meaning | No bit-purpose table | Add the table; make it a mandatory comment item |
"A word as a flag group" organises bit resources so they can be operated as a whole: bit-level access for flexibility, word-level for efficiency. The preconditions are a clear bit table and single ownership. When resources are tight or block snapshots are needed it is a sharp tool; used without a table it is an unfindable mine — the difference is entirely discipline.
Word-device bit designation and bit-instruction syntax follow the PLC's programming manual (Mitsubishi FX3U/FX5U applied instructions; WAND/WOR/WXOR and bit designation); host byte-order conventions follow the communication protocol documents; flag groups feeding safety interlocks still pass the unified safety stage per GB 5226.1 / IEC 60204-1.
The day a flag-group word is created, its bit table goes into the program-header comments — that table is the word's household register; no register, no flag word.