HMI macros are small programs on the panel: they can scale data, manage pop-ups, query history. But as macros multiply, logic "moves house" — control logic migrates into the HMI while the PLC becomes a mere database. The iron division: judgement and control in the PLC; display and input assistance in the HMI. This article covers what macros may do, what they must not, and how the two sides cooperate.
| Function | Where | Reason |
|---|---|---|
| Start/stop judgement, interlocks, flow control | PLC | Control logic must be single, reliable, auditable |
| Alarm judgement and logging | PLC judges, HMI displays | Alarms must not depend on the screen being on |
| Display-only format scaling | HMI macro | Affects display only, never control |
| Login, permissions, screen jumps | HMI macro | Pure human-interface affairs |
| Operation logs, queries, exports | HMI macro | Screen-level matters |
| Parameter-validity checking | PLC as the last gate (HMI pre-check auxiliary) | The final defence sits on the control side |
The test, one sentence: with the HMI dead, should the machine still run correctly on this logic? Yes — PLC; it is only "invisible or ugly on screen" — HMI.
| Use | What the macro does | Cooperation |
|---|---|---|
| Scaled display | Read raw value × factor for display; reverse-scale on input | PLC stores raw only; scaling lives only in the HMI |
| Permission management | Login check, show/hide buttons by level | PLC holds a permission-level word; the macro reads and shows/hides |
| Alarm history paging | Read the PLC's alarm history area page by page | PLC records; the macro leafs through |
| Input pre-check | Range-check on entry, prompt without writing | The PLC still clamps as the backstop |
| One-key export | Pack data to USB / export CSV | Data from the PLC area; the macro only moves it |
Note the "scaling in one place only" principle: the scaling factor lives either only in the HMI macro or only in the PLC — both sides doing it guarantees an eventual edit-miss and display/control divergence.
① Interface-area planning: a dedicated HMI read/write region (setpoints, status, commands, alarms) with fixed D-area blocks and a drawn mapping table; ② command handshake: HMI buttons write a "command word + command number", the PLC processes on edge detection and writes back "done/failed" — the same protocol as module handshakes; ③ standardised alarm area: active alarm word + history area in fixed format, HMI-mapped by bit/word; ④ write protection: critical parameters (calibration, interlock settings) kept out of HMI-writable addresses, or protected by a "write-enable word" (HMI writes the enable first, edits, and the enable auto-locks on timeout).
| Step | HMI macro | PLC |
|---|---|---|
| 1 | Check the ready status word | Status word refreshed by the PLC |
| 2 | Write parameters to the agreed area, write command number, set the request bit | Detects the request bit's rising edge |
| 3 | Wait for the done bit (macro polls with timeout) | Executes, writes the result code, sets done |
| 4 | Read the result code, show success/reason | Clears done for the next round |
The macro's "wait" is polling with a timeout (macros cannot block); never a dead loop — a looping macro freezes the screen thread and the whole panel stops responding.
| Symptom | Cause | Fix |
|---|---|---|
| Machine uncontrolled when the HMI dies | Key control logic inside macros | Move the logic back to the PLC |
| Buttons execute multiple times when tapped | Command on level, no edge/handshake | Command word + edge + done handshake |
| Display and control values disagree | Scaling on both sides | Scaling in one place only |
| Operator edits what he should not | No permission zones / write-enable | Tiered permissions + write-enable protection |
| HMI occasionally freezes | Dead-loop waiting in a macro | Polling + timeout |
The PLC–HMI relation is master and servant: the PLC is the machine's brain, the HMI its face and mouth. Macros make the face cleverer (scaling, guidance, records) — but the brain's duties (judgement, control, protection) yield not one inch. Every "control logic in a macro" scheme is exposed the moment the HMI loses power — test the division with that sentence and it never goes wrong.
The functional allocation between HMI and control follows GB 5226.1 / IEC 60204-1 (control functions must not depend on the human-machine interface); macro syntax and capabilities follow the HMI manual (Weinview, Kinco, Pro-face etc.); parameter write-protection and permission management follow the corporate quality system.
Add one review question: "with the screen dead, what happens to this logic?" — no answer means it moves back to the PLC.