A PID Loop Inside a PLC Program
The Core Idea
A proportional-integral-derivative (PID) block is one part of a programmable logic controller (PLC) control program. Measurements must reach it in the intended units, and its output must pass through the program's mode, limit, and permissive logic before reaching the equipment.
What you will learn
Follow a measurement from input-card counts into a controller.
Follow controller output (CV) from percent output back to an output-card command.
Use manual mode and an interlock without leaving the controller's state unprepared.
Why it matters
A sound tune depends on the signal path around it. Incorrect units or an unexpected program condition can defeat an otherwise correct controller calculation.
Follow the whole signal path
The transmitter represents 0–100 °C as 0–27648 counts. The heater accepts 0–27648 output counts for 0–100% power. The actual process starts at 20 °C, and the temperature request is 50 °C.
The supplied program is complete. Read its four numbered sections, then follow TT_RAW → TempPV → TempLoop.CV → HeaterCV → HEATER_RAW while it runs. Predict the engineering value for 13824 input counts, and the output word for 30% CV before checking the live tags.
Operate the program
Let automatic control warm the heater for about 60 simulated seconds. Compare setpoint (SP), scaled process variable (PV), and the independent actual-temperature trace.
Set AUTO_MODE to FALSE and MANUAL_OUTPUT to 30%. Watch which value now determines heater power.
Return AUTO_MODE to TRUE and inspect CV at the transfer. The PID block tracks the manual operating point while it runs in manual.
Set INTERLOCK_OK to FALSE, with a nonzero manual request still present. The output must become 0 counts / 0% on that scan, in either operating mode.
Restore the interlock, inspect the first automatic CV, and allow the heater to recover. Pause, then use Run checks for fresh automatic, manual, interlock, and handover trials.
The live program scans every 100 ms; 100 scans are 10 simulated seconds. The checks use the same heater model and scan interval. Automatic hold and later recovery allow ±0.6 °C; the first returning command allows at most 1 percentage point of output change from its tracked value.
Why each section matters
The input conversion uses REAL (floating-point number) arithmetic so intermediate values retain fractions. At the midpoint, 13824 counts becomes 50 °C. The PID compares temperature with temperature, rather than comparing raw counts with degrees.
The block's CV is in percent output. A 30% command becomes approximately 8294 counts at the output card. That card command drives the physical heater, which changes the next measurement and closes the loop.
The interlock requests manual 0% while the block continues to execute. Simply overwriting the final output word can stop heating for a scan but leave the automatic controller's internal correction unprepared. Here the returning auto command starts near the tracked value and then responds to the remaining temperature error.
Where Ladder fits
The same path in Ladder is input scaling math, mode/interlock logic, a PID instruction, and output scaling math. Statement order in this Structured Text (ST) example plays the same practical role as rung order: establish the values before the controller uses them, then write the resulting command.
You do not need to rewrite the PID control law to add a loop to a PLC program. The program handles the measurement, operating modes, permissives, and command around a stateful controller block.
The 0–27648-count ranges are this exercise's stated card configuration. Real modules and PID blocks can use different ranges, parameter names, units, execution periods, and tracking options. Check the hardware and controller documentation before copying values.
Check your understanding
Trace one input reading and one output command through every conversion. Explain why the interlock overrides an 80% manual request, why the controller still executes, and what the first returning auto sample proves. The simulator checks can record completion; manual completion is also available.
Enable JavaScript to run the embedded simulator and complete the interactive exercises.