Field fix / guideDesign DocumentVendor-agnostic (IEC 61131-3)Generic Modulesindustrial-automation

Temperature PID Control Loop — Control Design

Shared by TSIMEREZIVO Team · 4 Oct 2026 · 48 views

# Generic Module: Temperature PID Control Loop **Version**: 1.0 **Complexity**: High **Industries**: Chemical, Food & Beverage, Pharmaceutical, Pulp & Paper, Plastics **PLC Languages**: ST, FBD **Sensor**: RTD (PT100), Thermocouple (K-type), or Resistance TE --- ## 📋 Overview Precision temperature regulation via proportional-integral-derivative (PID) feedback control. Applies 0-100% output modulation to heating or cooling element based on error between setpoint and actual temperature. **Use When:** - ✅ Continuous heating/cooling demand (reactor jacket, oven, heat exchanger) - ✅ Precision temperature hold ±1-5°C required (±0.5% of setpoint) - ✅ Slow process dynamics (time constant > 30 seconds) - ✅ Non-linear load (e.g., changing coolant flow) **Do NOT Use When:** - ❌ On/Off bang-bang control sufficient (use Tank Level template) - ❌ Ultra-fast response required (<5 sec, use cascade control) - ❌ Multiple competing constraints (e.g., simultaneous heat + cool, see advanced variations) --- ## 🎯 Control Philosophy **Three-Term PID Feedback Loop** ``` Error = Setpoint - Temperature_Actual Output = (Kp × Error) [Proportional] + (Ki × ∫Error dt) [Integral - eliminates offset] + (Kd × dError/dt) [Derivative - damping] Proportional (Kp): Fast response, prevents large deviations Integral (Ki): Eliminates steady-state error (offset) Derivative (Kd): Dampens oscillation, prevents overshoot ``` **Why PID Works:** - Proportional alone → oscillates (hunts for setpoint) - Adding Integral → steady error goes to zero - Adding Derivative → smooth settling (no overshoot) --- ## 🏗️ Control Logic (Pseudocode) ```pascal PROGRAM Temperature_PID_Control VAR (* PID Gains (must be tuned per process) *) Kp : REAL := 0.05; (* Proportional: 1/200 *) Ki : REAL := 0.001; (* Integral: 1/1000 *) Kd : REAL := 0.02; (* Derivative: 1/50 *) (* Sensor Input *) Temperature_Raw : INT; (* 0-4095 from AI module *) Temperature_Actual : REAL; (* °C, scaled from raw *) (* Setpoint & Limits *) Temperature_Setpoint : REAL := 80.0; (* °C *) Temperature_Max : REAL := 120.0; (* Safety limit *) Temperature_Min : REAL := 10.0; (* Cryogenic protection *) (* PID State Variables *) Error : REAL := 0.0; Error_Previous : REAL := 0.0; Error_Integral : REAL := 0.0; (* Accumulated error *) Error_Derivative : REAL := 0.0; (* Output *) PID_Output : REAL := 0.0; (* 0-100% *) Output_Limited : REAL := 0.0; (* Clamped to 0-100% *) (* Tuning Aids *) Integral_Limit : REAL := 50.0; (* Anti-windup: limit integral to ±50% *) Deadband : REAL := 0.2; (* Ignore errors < ±0.2°C *) (* Diagnostics *) PID_Mode : INT := 0; (* 0=Off, 1=Manual, 2=Auto *) Sensor_Fault : BOOL := FALSE; Integral_Windup_Active : BOOL := FALSE; Overshoot_Max : REAL := 0.0; (* Track peak overshoot *) Settle_Time_Sec : REAL := 0.0; (* Time to reach ±1° of SP *) (* Safety *) High_Temp_Alarm : BOOL := FALSE; Low_Temp_Alarm : BOOL := FALSE; END_VAR (* ─────────────────────────────────────────────────────── *) (* 1. SENSOR READING & CONVERSION *) (* ─────────────────────────────────────────────────────── *) (* Read analog input (0-4095 = 0-150°C typical) *) Temperature_Raw := ANALOG_INPUT(AI_01); (* Convert to °C: formula depends on sensor *) (* RTD PT100: R(T) = 100 * (1 + 0.00385 * T) *) (* Direct mapping: Raw_to_Celsius = (Raw / 4095.0) * 150.0 *) Temperature_Actual := (Temperature_Raw / 4095.0) * 150.0; (* Sensor fault detection (e.g., signal out of expected range) *) IF Temperature_Actual < -50.0 OR Temperature_Actual > 200.0 THEN Sensor_Fault := TRUE; PID_Mode := 0; (* Disable PID on fault *) ELSE Sensor_Fault := FALSE; END_IF; (* ─────────────────────────────────────────────────────── *) (* 2. SAFETY ALARMS *) (* ─────────────────────────────────────────────────────── *) High_Temp_Alarm := (Temperature_Actual > Temperature_Max); Low_Temp_Alarm := (Temperature_Actual < Temperature_Min); IF High_Temp_Alarm THEN PID_Output := 0.0; (* Kill heating *) (* Optional: activate cooling *) END_IF; IF Low_Temp_Alarm THEN PID_Output := 100.0; (* Maximum heating *) END_IF; (* ─────────────────────────────────────────────────────– *) (* 3. PID CALCULATION (Core Algorithm) *) (* ─────────────────────────────────────────────────────── *) IF PID_Mode = 2 THEN (* Auto mode only *) (* Error: how far from setpoint *) Error := Temperature_Setpoint - Temperature_Actual; (* Apply deadband to eliminate chattering *) IF ABS(Error) < Deadband THEN Error := 0.0; END_IF; (* ───────────────────────────────────────── *) (* PROPORTIONAL TERM *) (* ───────────────────────────────────────── *) Proportional_Term := Kp * Error; (* ───────────────────────────────────────── *) (* INTEGRAL TERM (Running sum of error) *) (* ───────────────────────────────────────── *) Error_Integral := Error_Integral + (Error * SCAN_TIME_SEC); (* Anti-windup: prevent integral from growing unbounded *) IF ABS(Error_Integral) > Integral_Limit THEN Error_Integral := MAX(-Integral_Limit, MIN(Integral_Limit, Error_Integral)); Integral_Windup_Active := TRUE; ELSE Integral_Windup_Active := FALSE; END_IF; Integral_Term := Ki * Error_Integral; (* ───────────────────────────────────────── *) (* DERIVATIVE TERM (Rate of change dampening) *) (* ───────────────────────────────────────── *) Error_Derivative := (Error - Error_Previous) / SCAN_TIME_SEC; Derivative_Term := Kd * Error_Derivative; (* ───────────────────────────────────────── *) (* COMBINE ALL THREE TERMS *) (* ───────────────────────────────────────── *) PID_Output := Proportional_Term + Integral_Term + Derivative_Term; (* Store for next iteration *) Error_Previous := Error; ELSIF PID_Mode = 1 THEN (* Manual mode *) (* User directly controls output via manual input *) (* PID_Output set externally, no calculation *) END_IF; (* ─────────────────────────────────────────────────────– *) (* 4. OUTPUT LIMITING (0-100% bounds) *) /* ─────────────────────────────────────────────────────– *) Output_Limited := MAX(0.0, MIN(100.0, PID_Output)); (* Track overshoot for process tuning *) IF Temperature_Actual > (Temperature_Setpoint + 5.0) THEN Overshoot_Max := MAX(Overshoot_Max, Temperature_Actual - Temperature_Setpoint); END_IF; (* ─────────────────────────────────────────────────────– *) (* 5. ACTUATOR COMMAND (PWM or Analog Output) *) /* ─────────────────────────────────────────────────────– */ (* Method 1: PWM to contactor (switching heater on/off at ~10 Hz) *) IF PID_Mode = 2 THEN PWM_Duty_Cycle := Output_Limited / 100.0; ELSE PWM_Duty_Cycle := 0.0; END_IF; WRITE_PWM(PWM_01, PWM_Duty_Cycle); (* Method 2: Analog output to modulating valve *) WRITE_ANALOG_OUTPUT(AO_01, Output_Limited); (* ─────────────────────────────────────────────────────– *) (* 6. DIAGNOSTICS & TELEMETRY *) /* ─────────────────────────────────────────────────────– */ (* Measure settling time (time to reach ±1°C of setpoint) *) IF ABS(Temperature_Actual - Temperature_Setpoint) <= 1.0 THEN Settled := TRUE; ELSE Settle_Time_Sec := Settle_Time_Sec + SCAN_TIME_SEC; END_IF; (* Log performance metrics *) ERROR_LOG := [ Timestamp: NOW(), Setpoint: Temperature_Setpoint, Actual: Temperature_Actual, Error: Temperature_Actual - Temperature_Setpoint, Output%: Output_Limited, PIDTerms: [Kp*Error, Ki*∫Error, Kd*dError/dt] ]; END_PROGRAM ``` --- ## 🏷️ Tag List | Tag | Type | I/O | Range | Description | |-----|------|-----|-------|-------------| | `TEMP_01_ACTUAL` | REAL | Feedback | -50…150 °C | Process temperature | | `TEMP_01_SETPOINT` | REAL | Param | -50…150 °C | Desired temperature | | `TEMP_01_ERROR` | REAL | Status | -150…150 °C | Setpoint - Actual | | `TEMP_01_PID_OUTPUT` | REAL | Status | 0-100 % | Raw PID output (unbounded) | | `TEMP_01_PID_LIMITED` | REAL | Output | 0-100 % | Clamped PID output | | `TEMP_01_HEATER_CMD` | REAL | Output | 0-100 % | Heater power (PWM or analog) | | `TEMP_01_KP` | REAL | Param | 0-1 | Proportional gain | | `TEMP_01_KI` | REAL | Param | 0-0.1 | Integral gain | | `TEMP_01_KD` | REAL | Param | 0-0.5 | Derivative gain | | `TEMP_01_MAX_LIMIT` | REAL | Param | 0…200 °C | High-temp safety cutoff | | `TEMP_01_MIN_LIMIT` | REAL | Param | -100…100 °C | Low-temp safety limit | | `TEMP_01_MODE` | INT | Cmd | 0/1/2 | 0=Off, 1=Manual, 2=Auto | | `TEMP_01_INTEGRAL_SUM` | REAL | Status | - | Accumulated error (for tuning debug) | | `TEMP_01_INTEGRAL_WINDUP` | BOOL | Alarm | - | Integral clamped (indicates saturation) | | `TEMP_01_SENSOR_FAULT` | BOOL | Alarm | - | Sensor out-of-range | | `TEMP_01_OVERSHOOT_MAX` | REAL | Status | 0…100 °C | Peak overshoot from setpoint | | `TEMP_01_SETTLE_TIME` | REAL | Metrics | 0…999 sec | Time to ±1°C of setpoint | | `TEMP_01_POWER_CONSUMED` | REAL | Status | 0…100 kW | Heater power draw | | `TEMP_01_DEADBAND` | REAL | Param | 0-5 °C | Error threshold for action | --- ## 🚨 Alarm & Trip Matrix | Alarm | Condition | Severity | Auto-Reset | |-------|-----------|----------|-----------| | **High Temperature** | Actual > Max Limit | Critical | Manual | | **Low Temperature** | Actual < Min Limit | Critical | Manual | | **Sensor Fault** | Raw signal out of range | Critical | Manual (check wiring) | | **Integral Windup** | Integral term saturated | Warning | Auto | | **PID Not Settling** | Still >±5°C after 5min | Warning | Manual tune | | **Overshoot Excessive** | Peak overshoot >20°C | Warning | Manual tune | | **Heater Not Responding** | Output 100%, temp static | Critical | Manual (check equipment) | | **Coolant Flow Missing** | Temp rising despite 0% output | Warning | Check flow valve | | **Temperature Drift** | Slow creep over hours | Info | Monitor (aging equipment) | --- ## 📺 HMI Layout ``` ┌──────────────────────────────────────────┐ │ TEMPERATURE CONTROL - BATCH REACTOR │ ├──────────────────────────────────────────┤ │ │ │ Setpoint: 85.0°C ⚙️ [Editable] │ │ │ │ ┌────────────────────────────────┐ │ │ │ Current: 82.4°C │ │ │ │ [████████░░░░░░░ 82.4 °C] │ │ │ │ Target ↑ 85.0°C │ │ │ └────────────────────────────────┘ │ │ │ │ Error: -2.6°C (cooling down) │ │ Status: HEATING [🔥 stabilizing...] │ │ Heater Output: 65% [██████░░░░] │ │ │ │ Performance Metrics: │ │ Time to Setpoint: 4m 32s │ │ Overshoot: 3.2°C (3.8%) │ │ Oscillation: Damped │ │ │ │ ┌────────────────────────────────┐ │ │ │ PID Tuning (Advanced) │ │ │ │ Kp: 0.050 Ki: 0.001 │ │ │ │ Kd: 0.020 Deadband: 0.2°C │ │ │ │ │ │ │ │ [Auto-Tune] [Load Preset] │ │ │ └────────────────────────────────┘ │ │ │ │ Mode: [Off] [Manual ⊙] [Auto ◉] │ │ Actions: [Hold at Temp] [Ramp 2°/min] │ │ │ └──────────────────────────────────────────┘ ``` --- ## 🔧 Configuration Parameters ```json { "tuning_method": "Ziegler-Nichols", "process_time_constant_sec": 120.0, "estimated_dead_time_sec": 15.0, "kp_proportional": 0.050, "ki_integral": 0.001, "kd_derivative": 0.020, "integral_anti_windup_limit": 50.0, "deadband_celsius": 0.2, "setpoint_max_celsius": 150.0, "setpoint_min_celsius": -10.0, "safety_max_celsius": 120.0, "safety_min_celsius": 0.0, "sensor_type": "RTD_PT100", "sensor_range_celsius": "[-50, 150]", "heater_type": "electric_resistance", "heater_max_power_kw": 25.0, "heat_exchanger_area_m2": 5.0, "process_mass_kg": 500.0, "process_cp_kj_kg_k": 2.5, "tuning_log": "filename" } ``` --- ## 📝 Implementation Checklist ### Before Deployment - [ ] **Sensor calibrated** (PT100 against ice bath + hot well) - [ ] **Sensor wiring** (shielded 3-wire RTD or thermocouple) - [ ] **AI module** (0-4095 @ 0-150°C range verified with multimeter) - [ ] **Heater functional** (manual on/off test at 50% output) - [ ] **Cooling available** (if needed, valve opens correctly) - [ ] **Process mass estimated** (for tuning calculations) - [ ] **Time constant measured** (step test: how long to 63% response) ### During Commissioning 1. **Manual mode test**: - Set mode to Manual - Ramp heater output 0% → 25% → 50% → 100% - Verify smooth temperature rise - Record rise rate (°C/min) - Safety: set max alarm well below boiling/decomposition 2. **Auto mode tuning** (start conservative): - Set Kp=0.01, Ki=0.0001, Kd=0 - Setpoint: room temp + 20°C - Observe slow response (P-only control) - Increase Kp to 0.05 (faster) - Add minimal Ki (eliminates offset) - Verify no overshoot >5°C - Add Kd to dampen oscillation 3. **Setpoint step test**: - Hold at 80°C - Step to 85°C - Measure: rise time, overshoot, settling time - Record for process validation 4. **Safety test**: - Setpoint 150°C - Verify max alarm cuts heater at 120°C - Cool and reset - Repeat --- ## 📊 Expected Performance | Metric | Target | Achievable | |--------|--------|-----------| | **Steady-State Error** | Zero | ±0.1°C (with integral term) | | **Settling Time** | 90 sec | 60-180 sec (depends on time constant) | | **Overshoot** | <5% | ±2-7°C | | **Response Time (±1°)** | 2× time constant | 4 minutes typical | | **Oscillation** | Damped (no hunting) | <1°C peak-to-peak | --- ## 🔄 Tuning Procedures ### Method 1: Ziegler-Nichols (Field) 1. Set Ki=0, Kd=0 2. Increase Kp until sustainable oscillation (Kp_critical) 3. Measure oscillation period (T_period) 4. Set: - Kp = 0.6 × Kp_critical - Ki = Kp / (2 × T_period) - Kd = Kp × T_period / 8 ### Method 2: Process Model (Theoretical) For process with time constant τ and dead time θ: ``` Kp = (1.2 × τ) / (θ × Kp_process) Ki = Kp / (2 × θ) Kd = Kp × θ / 3 ``` ### Method 3: Auto-Tuning (Smart) PLC algorithm: 1. Step setpoint 2. Measure response curve 3. Calculate process parameters 4. Auto-calculate optimal Kp, Ki, Kd 5. Apply new gains --- ## 🔄 Advanced Variations ### Cascade Control (for faster response) Inner loop: VFD speed control (coolant pump) Outer loop: Temperature setpoint → Combines PID (temp) + open-loop (flow) ### Ramp-to-Setpoint Instead of step change, ramp setpoint at 1°C/min to prevent thermal shock. ### Load Feedforward If inlet coolant temperature drops, pre-command heater before PID sees error. ### Dual Heating/Cooling Heating: 0-50% output range Cooling: 50-100% output range → Hot/cold valve control on single output --- **Production-grade temperature regulation for chemical, food, and pharmaceutical processes.**

More like this

Rate, comment, and get full access

Members can download files, rate contributions, and discuss fixes with the engineers who posted them — free.

Join the library