Learn PLCs free
Process ControlAdvancedIEC 61131-3

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

NameTypeDescription
SPREALSetpoint - desired process value
PVREALProcess variable - measured value from sensor
KPREALProportional gain
TITIMEIntegral time (reset time)
TDTIMEDerivative time (rate time)
CYCLETIMESample time / execution cycle
MAN_ONBOOLManual mode enable
MAN_VALREALManual output value

Outputs

NameTypeDescription
CVREALControl variable - output to actuator (0-100%)
ERRORREALCurrent error (SP - PV)
LMN_PREALProportional component
LMN_IREALIntegral component
LMN_DREALDerivative 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.

Closed-loop PID response diagramSP 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.SPPVCVsetpoint stepresponse settles; sample at sample interval Δt
Blue is setpoint, green is process variable and amber is controller output. The response is illustrative; real behavior depends on the process, tuning, limits and execution interval.

State table

MomentInputInternal stateOutputEngineering meaning
Manual commissioningMode = MAN; operator sets CVSP/PV tracking policy activeCV follows manual valueVerify scaling, direction and actuator movement before closing the loop.
Setpoint changeSP changes; error = SP − PVP responds; I begins accumulatingCV changes within limitsThe controller starts driving the process toward the new target.
Approaching targetError magnitude decreasesI removes residual error; D may damp rateCV moves toward sustaining valueTrend each term if the vendor block exposes it; do not tune from PV alone.
Output saturatedDemand exceeds actuator limitAnti-windup should constrain integralCV = configured MIN/MAXA saturated actuator cannot deliver the requested control action; diagnose capacity before increasing gains.
Steady operationPV near SPTerms balance process loadCV supplies sustaining demandAssess 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.

PlatformInstructionWhat maps cleanlyCaveat to verify
Siemens S7-1200/1500PID_CompactClosed-loop SP/PV control with automatic, manual and tuning modesMode transitions, input scaling, cycle time and PID_Compact version must match the selected CPU and cyclic-interrupt configuration.
Rockwell LogixPID in Ladder/ST; PIDE in supported function-block environmentsRegulates CV from SP/PV with configurable gains, limits and manual behaviorPID and PIDE use different structures and algorithm options. Verify independent/dependent gains, update time, scaling and derivative settings.
CODESYS and other IEC systemsVendor or library PID blockUsually exposes SP/PV, gains, cycle time, limits and mode controlPID 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

  1. 1Verify SP, PV and CV scaling and engineering units end to end.
  2. 2Bump the actuator in manual and confirm control direction and field feedback.
  3. 3Measure the real task interval and match the PID update-time configuration.
  4. 4Trend SP, PV, CV, mode, limits and available P/I/D terms on one time axis.
  5. 5Test output saturation, sensor failure and manual/auto transfer.
  6. 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.

Platform-Specific Implementation

S

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).

AB

Allen-Bradley (Studio 5000)

Use PID or PIDE (Enhanced PID) instruction in Studio 5000. Supports autotuning. Run in periodic task.

C

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.

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →