How to use LLMs to safely speed up IEC 61131-3 PLC development—Structured Text, reviews, tests, and guardrails.
LLMs can accelerate PLC work—scaffolding Structured Text (ST), documenting tags, and creating test scenarios—without touching runtime safety. The key is guardrails and review: generate offline, validate determinism and timing, and merge only after a human‑in‑the‑loop approves.
Strong fits:
Weak fits (keep human ownership):
Treat the model as a fast junior. It drafts; you review, simulate, and decide.
Give the model structure and constraints:
Example prompt (truncated):
You are drafting IEC 61131-3 Structured Text for a non-safety motor interlock.
Constraints: deterministic, no dynamic arrays, cycle-safe, no global side-effects beyond listed outputs.
Inputs:
- estop: BOOL (true = emergency stop active)
- start_cmd: BOOL
- stop_cmd: BOOL
- motor_running: BOOL (feedback)
Outputs:
- motor_enable: BOOL
Acceptance:
- Never enable when estop is true
- Rising-edge start_cmd enables if estop=false and not motor_running
- stop_cmd or estop clears enable
Return ST only.
Example ST (illustrative):
VAR
start_z : BOOL; (* edge memory *)
start_re : BOOL;
END_VAR
(* Rising edge on start_cmd *)
start_re := start_cmd AND NOT start_z;
start_z := start_cmd;
IF estop THEN
motor_enable := FALSE;
ELSIF stop_cmd THEN
motor_enable := FALSE;
ELSIF start_re AND NOT motor_running THEN
motor_enable := TRUE;
END_IF;
Review for race conditions (e.g., feedback latency), add time filters if needed, and centralize interlocks.
Use a simple scenario table the model can generate, then replay in a simulator (Codesys, Studio 5000, TIA Portal test rigs):
For richer checks, add a small harness to feed sequences and assert outputs per scan. Even a CSV‑driven player catches many regressions.
See also: Guardrails Beyond Regex.
Can LLMs write Ladder? They can draft simple rungs, but text limits clarity. Ask for ST or vendor‑specific export formats, then translate to Ladder with a human pass.
What about timing‑critical motion? Keep motion and safety as hand‑crafted libraries. Use LLMs for wrappers, diagnostics, and documentation.
How do I keep outputs safe? Separate calculation from actuation. Compute desired states in FBs, then gate them in a single, reviewed output network.
Want more detail? Contact us and we'll share implementation notes for your use case.