0
0
FreertosHow-ToBeginner · 4 min read

How to Configure PID Loop in PLC: Step-by-Step Guide

To configure a PID loop in a PLC, first define the process variable, setpoint, and output variables, then use the PLC's built-in PID function block with tuned parameters Kp, Ti, and Td. Connect the inputs and outputs properly and tune the parameters to achieve stable control.
📐

Syntax

The basic syntax for a PID loop in a PLC uses a PID function block with inputs for process variable (PV), setpoint (SP), and outputs the control variable (CV). You also provide tuning parameters: proportional gain (Kp), integral time (Ti), and derivative time (Td).

Each PLC brand may have slight variations, but the core parts are:

  • PV: The current measured value.
  • SP: The desired target value.
  • CV: The output to control the process.
  • Kp: How strongly the controller reacts to error.
  • Ti: How fast the controller corrects accumulated error.
  • Td: How the controller reacts to the rate of error change.
structured_text
PID(
  PV := ProcessVariable,
  SP := SetPoint,
  CV => ControlOutput,
  Kp := ProportionalGain,
  Ti := IntegralTime,
  Td := DerivativeTime
);
💻

Example

This example shows a simple PID loop in Structured Text for a PLC controlling temperature. It reads the current temperature, compares it to the setpoint, and outputs a control signal to a heater.

structured_text
PROGRAM PID_Control
VAR
  Temperature : REAL;      // Process Variable
  SetPoint : REAL := 75.0; // Desired temperature
  ControlOutput : REAL;    // Output to heater
  Kp : REAL := 2.0;        // Proportional gain
  Ti : REAL := 5.0;        // Integral time
  Td : REAL := 1.0;        // Derivative time
  PID_Instance : PID;
END_VAR

// Call PID function block
PID_Instance(
  PV := Temperature,
  SP := SetPoint,
  CV => ControlOutput,
  Kp := Kp,
  Ti := Ti,
  Td := Td
);

// ControlOutput now drives the heater
END_PROGRAM
Output
ControlOutput value updates based on Temperature and SetPoint difference, adjusting heater power.
⚠️

Common Pitfalls

  • Not tuning parameters: Using default Kp, Ti, and Td values often causes unstable or slow control.
  • Incorrect variable connections: Mixing up PV, SP, or CV inputs leads to wrong control behavior.
  • Ignoring integral windup: Without limits on integral action, output can saturate causing overshoot.
  • Sampling time mismatch: PID calculations must match the PLC scan or task cycle time.
structured_text
(* Wrong: Swapped PV and SP *)
PID_Instance(
  PV := SetPoint,    // Incorrect
  SP := Temperature, // Incorrect
  CV => ControlOutput,
  Kp := 2.0,
  Ti := 5.0,
  Td := 1.0
);

(* Correct: Proper PV and SP *)
PID_Instance(
  PV := Temperature,
  SP := SetPoint,
  CV => ControlOutput,
  Kp := 2.0,
  Ti := 5.0,
  Td := 1.0
);
📊

Quick Reference

ParameterDescriptionTypical Range
PVProcess Variable (measured value)Depends on sensor
SPSetpoint (target value)Depends on process
CVControl Variable (output)0 to 100% or analog range
KpProportional gain0.1 to 10
TiIntegral time (seconds)1 to 100
TdDerivative time (seconds)0 to 10

Key Takeaways

Always connect PV, SP, and CV correctly to the PID function block inputs and outputs.
Tune Kp, Ti, and Td parameters to match your process for stable control.
Watch out for integral windup by limiting output or integral action.
Match PID calculation timing with your PLC scan cycle for accurate control.
Test your PID loop in simulation or safe conditions before full deployment.