PLC PID Controller: Equation, Timing and Tuning Tests
A PLC PID controller repeatedly compares process variable PV with setpoint SP and adjusts control output CV. Proportional action responds to present error, integral action accumulates error, and derivative action responds to rate of change. The exact equation, gain units, execution interval, limits and manual/automatic transfer are vendor-block settings—not universal defaults.
The PID (Proportional-Integral-Derivative) function block is the most widely used feedback controller in industrial automation. It continuously calculates an error value as the difference between a setpoint (SP) and process variable (PV), then applies proportional, integral, and derivative correction to produce a control output (CV). The proportional term responds to present error, the integral term eliminates steady-state offset, and the derivative term anticipates future error based on rate of change. PID controllers are essential for temperature control, pressure regulation, flow control, level control, and speed regulation.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| SP | REAL | Setpoint - desired process value |
| PV | REAL | Process variable - measured value from sensor |
| KP | REAL | Proportional gain |
| TI | TIME | Integral time (reset time) |
| TD | TIME | Derivative time (rate time) |
| CYCLE | TIME | Sample time / execution cycle |
| MAN_ON | BOOL | Manual mode enable |
| MAN_VAL | REAL | Manual output value |
Outputs
| Name | Type | Description |
|---|---|---|
| CV | REAL | Control variable - output to actuator (0-100%) |
| ERROR | REAL | Current error (SP - PV) |
| LMN_P | REAL | Proportional component |
| LMN_I | REAL | Integral component |
| LMN_D | REAL | Derivative component |
How PLC PID controller works scan by scan
Read the waveforms and state table together. The diagram shows the sequence; the table states what the program should observe at each execution.
Closed-loop PID response diagram
SP steps upward, CV responds immediately, and PV approaches the target with a small illustrative overshoot before settling. This is a conceptual response, not tuning proof for a real process.
State table
| Moment | Input | Internal state | Output | Engineering meaning |
|---|---|---|---|---|
| Manual commissioning | Mode = MAN; operator sets CV | SP/PV tracking policy active | CV follows manual value | Verify scaling, direction and actuator movement before closing the loop. |
| Setpoint change | SP changes; error = SP − PV | P responds; I begins accumulating | CV changes within limits | The controller starts driving the process toward the new target. |
| Approaching target | Error magnitude decreases | I removes residual error; D may damp rate | CV moves toward sustaining value | Trend each term if the vendor block exposes it; do not tune from PV alone. |
| Output saturated | Demand exceeds actuator limit | Anti-windup should constrain integral | CV = configured MIN/MAX | A saturated actuator cannot deliver the requested control action; diagnose capacity before increasing gains. |
| Steady operation | PV near SP | Terms balance process load | CV supplies sustaining demand | Assess noise, cycling, valve movement and disturbance rejection over representative operation. |
Ladder and Structured Text examples
Conceptual PID block wiring
|----[ Loop_Enable ]----[ PID TemperatureLoop ]----|
| SP: TempSetpoint |
| PV: TempProcess |
| CV: HeaterDemandPct |
| Δt: 100 ms |This is vendor-neutral pseudocode, not copy-paste syntax. Scale SP and PV to the same engineering units, define output limits and execute the selected vendor instruction at its configured update interval.
Vendor-neutral wrapper pseudocode
// Map these names to the selected vendor PID block.
TemperatureLoop(
Enable := LoopEnable,
Setpoint := TempSetpoint,
ProcessValue := TempProcess,
ManualMode := ManualMode,
ManualOutput := ManualDemandPct,
CycleTime := T#100ms,
Output => HeaterDemandPct
);PID is not one portable IEC standard block. Create a reviewed wrapper only after mapping control action, gain form and units, derivative source/filter, anti-windup, manual tracking, limits and execution timing.
Vendor compatibility
A shared mnemonic does not guarantee an identical interface or state machine. Confirm the instruction help for the controller, firmware, language and library version used on the project.
| Platform | Instruction | What maps cleanly | Caveat to verify |
|---|---|---|---|
| Siemens S7-1200/1500 | PID_Compact | Closed-loop SP/PV control with automatic, manual and tuning modes | Mode transitions, input scaling, cycle time and PID_Compact version must match the selected CPU and cyclic-interrupt configuration. |
| Rockwell Logix | PID in Ladder/ST; PIDE in supported function-block environments | Regulates CV from SP/PV with configurable gains, limits and manual behavior | PID and PIDE use different structures and algorithm options. Verify independent/dependent gains, update time, scaling and derivative settings. |
| CODESYS and other IEC systems | Vendor or library PID block | Usually exposes SP/PV, gains, cycle time, limits and mode control | PID is not one IEC 61131-3 standard function block. Library interface, equation and gain units must be sourced from the installed version. |
Failure modes and edge cases to test
Control direction is reversed
PV moves farther from SP as CV changes. Return to manual, verify the process sign and configure direct/reverse action correctly.
Task interval differs from configured loop update
Integral and derivative behavior no longer matches the tuning basis. Measure actual execution and configure timing consistently.
CV remains at an output limit
Treat this as saturation or capacity evidence. Confirm anti-windup and actuator/process capability before retuning.
PV noise makes CV chatter
Verify instrumentation and filtering first. Derivative can amplify noise; use the vendor’s derivative source and smoothing controls deliberately.
Manual-to-auto produces an output step
SP/PV tracking, tieback or internal state did not align with the manual output. Configure and test bumpless transfer.
The process has significant dead time
Aggressive gain changes can create cycling. Identify process response and use a tuning method suited to dead time.
Verification checklist
- 1Verify SP, PV and CV scaling and engineering units end to end.
- 2Bump the actuator in manual and confirm control direction and field feedback.
- 3Measure the real task interval and match the PID update-time configuration.
- 4Trend SP, PV, CV, mode, limits and available P/I/D terms on one time axis.
- 5Test output saturation, sensor failure and manual/auto transfer.
- 6Document gain form and units before copying any tuning values between platforms.
Current primary and technical sources
These sources support the behavior summarized here. The exact controller, firmware, instruction and installed-library help remain authoritative for implementation.
- PID_Compact V2 parameters, STEP 7 V21
Siemens — Operating modes and current parameter interface
- Proportional Integral Derivative (PID), Logix Designer V38
Rockwell Automation — PV, SP, CV, limits, update time and structure members
- Anti-reset windup and bumpless transfer
Rockwell Automation — Output limiting, integral freeze and manual-mode transfer behavior
- IEC 61131-3
PLCopen — Language and function-block context; not a universal PID interface
Continue with the practical guide
Platform-Specific Implementation
Siemens (TIA Portal)
Use PID_Compact (S7-1200/1500) or FB 41 CONT_C (S7-300/400). Built-in autotuning available. Must run in cyclic OB (e.g., OB30).
Allen-Bradley (Studio 5000)
Use PID or PIDE (Enhanced PID) instruction in Studio 5000. Supports autotuning. Run in periodic task.
CODESYS
Use PID or PID_FIXCYCLE from OSCAT or vendor library. Configure in cyclic task with fixed interval.
Common Applications
- Temperature control (ovens, HVAC)
- Pressure regulation
- Flow rate control
- Tank level control
- Motor speed regulation
- pH control
Common Mistakes to Avoid
- Calling PID from main program (variable scan time)
- Not running PID in a timed interrupt/task
- Setting integral time to 0 (division by zero)
- Tuning proportional gain too high (oscillation)
- Forgetting to implement anti-windup
Frequently Asked Questions
What is PID (Proportional-Integral-Derivative Controller) in PLC programming?
Closed-loop feedback controller using proportional, integral, and derivative terms. The PID (Proportional-Integral-Derivative) function block is the most widely used feedback controller in industrial automation. It continuously calculates an error value as the difference between a setpoint (SP) and process variable (PV), then applies proportional, integral, and derivative correction to produce a control output (CV).
What are common applications of PID (Proportional-Integral-Derivative Controller)?
PID (Proportional-Integral-Derivative Controller) is commonly used for: Temperature control (ovens, HVAC), Pressure regulation, Flow rate control, Tank level control, Motor speed regulation, pH control.
How do I use PID (Proportional-Integral-Derivative Controller) in different PLC platforms?
Siemens: Use PID_Compact (S7-1200/1500) or FB 41 CONT_C (S7-300/400). Built-in autotuning available. Must run in cyclic OB (e.g., OB30). Allen-Bradley: Use PID or PIDE (Enhanced PID) instruction in Studio 5000. Supports autotuning. Run in periodic task. CODESYS: Use PID or PID_FIXCYCLE from OSCAT or vendor library. Configure in cyclic task with fixed interval.
Related Function Blocks
PWM (Pulse Width Modulation)
Converts analog percentage to pulsed digital output with proportional duty cycle.
View Reference →RAMP (Ramp Function / Rate Limiter)
Limits rate of change to create smooth transitions between values.
View Reference →LIMIT (Limiter / Clamp)
Clamps a value between minimum and maximum boundaries.
View Reference →