MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How do you read and write bit states in batches?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

How do you read and write bit states in batches?

Treating a block of bit devices (32 states like M100~M131, a row of cylinder flags, a bank of outputs) as one whole beats writing dozens of MOV lines. Three tools do the work: BMOV moves bit blocks wholesale, FMOV fills blocks with one value, and combined addressing (KnX) treats bit groups as words. Master them and snapshot/restore, grouped outputs and grouped inputs each become a couple of instructions. The sections below cover the three methods, use cases and pitfalls.

1. Method one: BMOV block transfer of bits

BMOV transfers between bit ranges and word areas: read 16 points from M100 into one D (BMOV M100 D0 K1), or expand one D onto Y0's 16 points (BMOV D0 Y0 K1). Typical uses:

UseCodingNote
State snapshotBMOV M100 D10 K4128 intermediates photographed into D area
Snapshot restoreBMOV D10 M100 K4Moved back for rollback
Grouped outputBMOV D20 Y40 K232 outputs refreshed as words
Grouped acquisitionBMOV X40 D30 K232 inputs read in as words

Tip: start bit blocks on 16-point boundaries — arbitrary starting points make "which bit sits in which word" mental arithmetic nobody enjoys; aligned starts halve the debugging.

2. Method two: FMOV fill

FMOV writes one value to many targets: FMOV M200 K0 K4 (M200 up, 64 points all OFF), FMOV D50 K0 K10 (10 words zeroed). Grouped resets prefer FMOV/ZRST over repeated RST lines. Note that fills into bit areas only make sense for 0 and all-ones (all OFF / all ON) — "filling 0x1234 into a bit area" is meaningless.

3. Method three: bit groups as words (combined addressing)

K4Y0 denotes Y0 up, four nibbles, 16 points as one word: MOV K4Y0 D0 reads the 16 outputs into D0; MOV D1 K2Y20 writes 8 outputs as a word. This is the most direct form of batch bit operation: output banks, lamp banks and valve banks refresh as words — one line replaces sixteen.

ExpressionMeaningTypical use
K2X20X20 up, 8 points as a byteReading a DIP switch bank whole
K4Y0Y0 up, 16 points as a wordRefreshing an output bank whole
K8M100M100 up, 32 points as a double wordSnapshotting a large state group

4. Merge before writing: do not brush away neighbours' bits

The danger of batch writes is overwriting: among Y40's 16 points, some bits may be driven by other logic, and a whole-word MOV brushes them away. Rules: ① the batch-write block must be an exclusively-owned block — those 16 points answer only to the batch refresher, confirmed in the partition table; ② mixed-driven blocks use bit arithmetic: new = old AND keep-mask OR update-mask, touching only the intended bits; ③ after a batch write, the output summary runs once more so next scan cannot brush it back.

5. Common errors

SymptomCauseFix
Individual outputs flicker offBatch write fighting single-point drivers (double drive)Exclusive block or masked merge
Restore lands skewedSnapshot and restore ranges differ in start or lengthSnapshot/restore share the same parameters
Input group reads all zeroCombined addressing start wrong (K2X20 typed as K2X2)Verify starts on 8/16 boundaries
Weird values filled into bitsNon-0/non-ones fill into a bit areaBit areas take 0 or all-ones only
Batch reset misses pointsZRST/FMOV length undercountedCheck lengths against the partition table

6. Notes

Batch bit operation means "see the bit block as a word block": once a bit group has whole-block semantics (a valve bank, a lamp row, a snapshot segment), operate on it with word instructions; bits with individual semantics stay bit-level. Knowing which groups are "wholes" and which are "individuals" settles the boundaries naturally.

7. References

BMOV/FMOV and combined addressing (KnX/Y/M/D) syntax follow the PLC's programming manual applied-instruction chapters (Mitsubishi, Delta, Xinje all provide equivalents); double-drive conflicts resolve per the output-summary principle, and safety outputs still pass the unified safety stage per GB 5226.1 / IEC 60204-1 — no batch write bypasses the safety interlocks.

8. Cautions

⚠️ Three traps to avoid:
① Bits inside the refreshed block driven by other logic — flickering outputs and a double-coil hunt that ruins the afternoon;
② Snapshot and restore ranges not paired — half a word of skew after restore;
③ Combined addressing starts off the 8/16 grid — bit-number arithmetic by guesswork.

Make it a rule: any "grouped" bit block starts on a 16 boundary, is exclusively owned, and appears in the partition table. All three, and batch operations are a code-saver.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL