As programs grow, "change one place, collapse everywhere" sets in — the root cause is wild cross-referencing: process logic reading another module's internals, one module's state scattered through B, C and D. Decoupling's goal: a module's internals may change freely and, as long as the interface holds, nobody outside notices. This article gives module division, interface definition, handshake protocol and the checking method — four pieces.
| Module type | Responsibility | Examples |
|---|---|---|
| Equipment modules | Manage one object's full life | Motor module, cylinder module, axis module |
| Process modules | Manage one process section | Loading section, machining section, unloading section |
| Service modules | Manage horizontal functions | Alarms, recipes, communication, parameters |
The division test, one sentence: can this module's "job" be stated in one sentence? "Manages conveyor 2's start/stop and faults" can — it is a module; "handles some Ms and Ds" cannot — it is a junk drawer. Data inside a module is private; between modules only the interface area flows.
Each module defines a dedicated interface area (an interface DB / a dedicated D block) in three parts:
| Part | Content | Rights |
|---|---|---|
| Input window | Commands and setpoints others give me | Others write, this module reads |
| Output window | Status and results I give others | This module writes, others read |
| Handshake area | Request/acknowledge flags, sequence numbers | Per the protocol (below) |
The iron law: beyond the interface area, internal variables are exclusive. A full-program search must confirm: module A's internals appear only in A's code. With that held, changing A's internals (devices, algorithms) touches nobody.
For cross-module actions (a process module commanding an axis module to position), use request-acknowledge, not internal peeking:
Four points: ① requests trigger on a rising edge (no double execution); ② acknowledgements carry a sequence number or use Req/Done alternation (so last time's Done is not misread); ③ a timeout is mandatory (a dead partner module must not hang the wait forever); ④ no two-way initiation (who commands and who serves is fixed; communication flows one way).
| Flow | Verdict | Note |
|---|---|---|
| Process → equipment (commands) | Normal | Upper layer directs lower |
| Equipment → process (status) | Normal | Lower reports results |
| Equipment → equipment direct references | Dangerous | Route via upper-layer coordination or handshake |
| Lower directing upper | Forbidden | Breaks layering; report status and let the upper decide |
Two devices need a mutual lock (must not move together)? The lock lives in a common process layer or a dedicated interlock module — not as A reading "B's internal flag". Interlock-rule changes then touch one place.
| Symptom | Cause | Fix |
|---|---|---|
| Editing the motor module breaks the line elsewhere | Others referenced its internals | Privatise internals; route through the interface area |
| Requests occasionally execute twice | Level-triggered request, no edge | Edge trigger + acknowledge handshake |
| Module waits hang forever | Handshake without timeout | Add timeout and timeout alarm |
| One interlock rule changed in three places | Interlocks scattered across modules | Consolidate into the interlock module |
| Interface area decays into chaos | It became the second junk drawer | Partition the interface area too, ownership per word |
Decoupling is "containing the blast radius of change": private variables confine a change's effects inside the module; the interface area makes dependencies explicit (who depends on whom, visible at a glance); the handshake protocol fixes the timing relations (no more relying on scan-order coincidence). With the three mechanisms up, big programs go from "change one, break many" to "change one, move one".
Modularity and information hiding are general software-engineering practice, landed in PLCs as FB instances + interface DBs (following IEC 61131-3 POU reuse); request-acknowledge with timeouts is standard industrial-communication convention; safety interlock implementation still follows GB 5226.1 / IEC 60204-1 — modularising control never moves the hard-wired safety requirements.
Three review questions for every new module: do its internals leak anywhere? does its handshake carry edge + acknowledge + timeout? are the safety interlocks still hard-wired? Three yeses and the module is "plugged in", not "welded in".