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

Flow Control Loop (PID-Based) — Control Design

Shared by TSIMEREZIVO Team · 4 Oct 2026 · 43 views

# Generic Module: Flow Control Loop (PID-Based) **Version**: 1.0 **Complexity**: Medium-High **Industries**: Water, Chemical Processing, Pharmaceuticals, Food & Beverage, Pulp & Paper **Sensor**: Orifice plate, turbine meter, or coriolis meter **Actuator**: Proportional control valve or pump VFD --- ## 📋 Overview Maintain constant flow rate via proportional valve position or pump speed modulation. Independent of downstream pressure variations. **Use When:** - ✅ Constant flow demand (batch filling, continuous processes) - ✅ Flow ±2% accuracy required - ✅ Downstream pressure varies unpredictably - ✅ Proportional valve or VFD available **Do NOT Use When:** - ❌ Pressure regulation prime requirement (use Pressure Control template) - ❌ On/off flow OK (use simpler check valve) - ❌ Only fixed-displacement pump available (no speed control) --- ## 🎯 Control Philosophy ``` Flow_Error = Flow_Setpoint - Flow_Actual Output = (Kp × Error) + (Ki × ∫Error) + (Kd × dError/dt) Flow_Setpoint = 100 m³/h (constant, operator set) If downstream blockage occurs (pressure ↑): - Current stays constant → flow drops - Error becomes negative (actual < setpoint) - Proportional increases valve opening - Flow recovers to setpoint (pump pressure rises to overcome blockage) Integral term prevents hunting (accumulation of small errors) Derivative term dampens overshoot ``` **Why PID for Flow?** - ✅ Decouples flow from pressure dynamics - ✅ Adapts to changing system resistance - ✅ Smooth transitions (no valve chatter) - ✅ Energy efficient (only moves valve when needed) --- ## 🏗️ Control Logic (Pseudocode) ```pascal PROGRAM Flow_PID_Control VAR (* ─── FLOW MEASUREMENT ─── *) Flow_Raw : INT; (* 0-4095, from flow transmitter *) Flow_Actual : REAL; (* m³/h or GPM *) Flow_Setpoint : REAL := 100.0; (* m³/h, operator input *) Flow_Min_Sensor : REAL := 0.0; (* 0% signal = 0 flow *) Flow_Max_Sensor : REAL := 200.0; (* 100% signal = 200 m³/h max *) (* ─── PRESSURE FEEDBACK (Optional, for diagnostics) ─── *) Pump_Pressure : REAL; (* bar, pump discharge *) Downstream_Pressure : REAL; (* bar, after control valve *) (* ─── PID PARAMETERS (tuned field) ─── *) Kp : REAL := 0.5; (* Proportional gain *) Ki : REAL := 0.02; (* Integral gain *) Kd : REAL := 0.05; (* Derivative gain *) Integral_Limit : REAL := 50.0; (* Anti-windup clamp *) Deadband : REAL := 0.5; (* Ignore errors < ±0.5 m³/h *) (* ─── PID STATE VARIABLES ─── *) Error : REAL := 0.0; Error_Previous : REAL := 0.0; Error_Integral : REAL := 0.0; Error_Derivative : REAL := 0.0; (* ─── OUTPUT COMMAND ─── *) PID_Output : REAL := 0.0; (* 0-100% valve/pump *) Output_Limited : REAL := 0.0; (* Clamped 0-100% *) (* ─── CONTROL MODE & SAFETY ─── *) Control_Mode : INT := 0; (* 0=Off, 1=Manual, 2=Auto *) Flow_Low_Alarm : REAL := 10.0; (* Threshold: alarm if < 10 m³/h *) Flow_High_Alarm : REAL := 180.0; (* Threshold: alarm if > 180 m³/h *) (* ─── STATUS ─── *) Pump_Running : BOOL := FALSE; Flow_Alarm_Low : BOOL := FALSE; Flow_Alarm_High : BOOL := FALSE; Valve_Stuck : BOOL := FALSE; (* Output 100% but flow static *) PID_Integral_Saturated : BOOL := FALSE; (* ─── DIAGNOSTICS & TRENDING ─── *) Flow_Stability_Counter : INT := 0; Flow_Error_Max : REAL := 0.0; END_VAR (* ═════════════════════════════════════════════════════════════ *) (* 1. FLOW MEASUREMENT CONVERSION *) (* ═════════════════════════════════════════════════════════════ *) (* Convert 0-4095 raw (4-20mA transducer) to flow units *) (* Typical: 4mA = 0 m³/h, 20mA = 200 m³/h *) Flow_Actual := (Flow_Raw / 4095.0) * (Flow_Max_Sensor - Flow_Min_Sensor) + Flow_Min_Sensor; (* Catch stuck transmitter (if flow exactly 0 for >60 sec, likely stuck sensor) *) IF Flow_Actual = 0.0 AND Pump_Running THEN (* Possible sensor fault, but continue control *) END_IF; (* ═════════════════════════════════════════════════════════════ *) (* 2. ALARM CONDITIONS *) (* ═════════════════════════════════════════════════════════════ *) Flow_Alarm_Low := (Flow_Actual < Flow_Low_Alarm); Flow_Alarm_High := (Flow_Actual > Flow_High_Alarm); (* Valve stuck detection: output 100% but flow static for >30 sec *) IF Output_Limited > 95.0 AND (Flow_Actual < (Flow_Setpoint - 20.0)) THEN Valve_Stuck := TRUE; (* Alert: valve may be jammed or blocked *) ELSE Valve_Stuck := FALSE; END_IF; (* ═════════════════════════════════════════════════════════════ *) (* 3. PID CALCULATION *) (* ═════════════════════════════════════════════════════════════ *) IF Control_Mode = 2 AND Pump_Running THEN (* AUTO mode, pump enabled *) (* Error: how much flow is needed *) Error := Flow_Setpoint - Flow_Actual; (* Deadband: don't correct tiny deviations *) IF ABS(Error) < Deadband THEN Error := 0.0; END_IF; (* ─── PROPORTIONAL TERM ─── *) Proportional_Term := Kp * Error; (* ─── INTEGRAL TERM ─── *) (* Integral accumulates error over time. If error persists (e.g., setpoint 100 but actual stuck at 95), integral grows, eventually commanding enough output to overcome obstacle. *) 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)); PID_Integral_Saturated := TRUE; ELSE PID_Integral_Saturated := FALSE; END_IF; Integral_Term := Ki * Error_Integral; (* ─── DERIVATIVE TERM ─── *) (* Rate of change dampening. If flow is dropping fast, this increases output to recover. If flow is rising fast, this reduces output to prevent overshoot. *) Error_Derivative := (Error - Error_Previous) / SCAN_TIME_SEC; Derivative_Term := Kd * Error_Derivative; Error_Previous := Error; (* ─── COMBINE ALL THREE ─── *) PID_Output := Proportional_Term + Integral_Term + Derivative_Term; (* Track maximum error for tuning analysis *) Flow_Error_Max := MAX(Flow_Error_Max, ABS(Error)); ELSIF Control_Mode = 1 AND Pump_Running THEN (* MANUAL mode *) (* Operator directly sets valve/pump position *) (* PID_Output overridden by manual slider *) ELSE (* Control off or pump stopped *) PID_Output := 0.0; END_IF; (* ═════════════════════════════════════════════════════════════ *) (* 4. OUTPUT LIMITING & COMMAND GENERATION *) (* ═════════════════════════════════════════════════════════════ *) (* Clamp output 0-100% *) Output_Limited := MAX(0.0, MIN(100.0, PID_Output)); (* Write to proportional control valve *) WRITE_ANALOG_OUTPUT(AO_CONTROL_VALVE, Output_Limited); (* OR if using pump speed instead: *) (* WRITE_ANALOG_OUTPUT(AO_VFD_SPEED, Output_Limited); *) (* ═════════════════════════════════════════════════════════════ *) (* 5. DIAGNOSTICS & TRENDING *) (* ═════════════════════════════════════════════════════════════ *) (* Measure stability: if error stays <2% for 300 sec, flow is stable *) IF ABS(Error) < 2.0 THEN Flow_Stability_Counter := Flow_Stability_Counter + 1; IF Flow_Stability_Counter > 300 THEN (* 300 scans = 30 sec @ 100ms *) Flow_Is_Stable := TRUE; END_IF; ELSE Flow_Stability_Counter := 0; Flow_Is_Stable := FALSE; END_IF; (* Log every 10 seconds *) IF (SCAN_COUNT MOD 10) = 0 THEN LOG_FLOW_TREND := [ Timestamp: NOW(), Flow_SP: Flow_Setpoint, Flow_PV: Flow_Actual, Error: Error, Output%: Output_Limited, Pump_Pressure_Update: Pump_Pressure, Downstream_Pressure: Downstream_Pressure, P_Term: Proportional_Term, I_Sum: Error_Integral, D_Term: Derivative_Term ]; END_IF; END_PROGRAM ``` --- ## 🏷️ Tag List | Tag | Type | I/O | Range | Description | |-----|------|-----|-------|-------------| | `FLOW_01_ACTUAL` | REAL | Feedback | 0-200 m³/h | Measured flow rate | | `FLOW_01_SETPOINT` | REAL | Param | 0-200 m³/h | Desired flow rate | | `FLOW_01_ERROR` | REAL | Status | -200…200 m³/h | Setpoint - Actual | | `FLOW_01_VALVE_CMD` | REAL | Output | 0-100 % | Control valve modulation | | `FLOW_01_KP` | REAL | Param | 0-5 | Proportional gain | | `FLOW_01_KI` | REAL | Param | 0-0.5 | Integral gain | | `FLOW_01_KD` | REAL | Param | 0-1 | Derivative gain | | `FLOW_01_MODE` | INT | Cmd | 0/1/2 | 0=Off, 1=Manual, 2=Auto | | `FLOW_01_DEADBAND` | REAL | Param | 0-10 m³/h | Error threshold | | `FLOW_01_LOW_ALARM` | REAL | Alarm | 0-200 | Low flow threshold | | `FLOW_01_HIGH_ALARM` | REAL | Alarm | 0-200 | High flow threshold | | `FLOW_01_ALRM_LOW` | BOOL | Alarm | - | Flow < low limit | | `FLOW_01_ALRM_HIGH` | BOOL | Alarm | - | Flow > high limit | | `FLOW_01_INTEGRAL_SAT` | BOOL | Status | - | Integral term saturated | | `FLOW_01_VALVE_STUCK` | BOOL | Alarm | - | Valve stuck-open (high output, low flow) | | `FLOW_01_PUMP_PRESS` | REAL | Feedback | 0-100 bar | Pump discharge pressure | | `FLOW_01_LOAD_PRESS` | REAL | Feedback | 0-100 bar | Pressure after control valve | | `FLOW_01_PRESSURE_DROP` | REAL | Status | 0-100 bar | Pump_Pressure - Load_Pressure | | `FLOW_01_STABLE` | BOOL | Status | - | Error <2% for 30 sec | | `FLOW_01_ERROR_MAX` | REAL | Metrics | 0-200 | Peak error since startup | --- ## 🚨 Alarm & Trip Matrix | Alarm | Condition | Severity | Auto-Reset | |-------|-----------|----------|-----------| | **Low Flow Alarm** | Flow < Low threshold | Warning | Auto | | **High Flow Alarm** | Flow > High threshold | Warning | Auto | | **Valve Stuck (Blocked)** | Output 100%, flow < SP-20 | Critical | Manual (check line) | | **Zero Flow Detected** | Flow = 0 while pump running | Critical | Manual (prime system) | | **Meter Fault** | Signal stuck (same value 60 sec) | Warning | Check transducer | | **Integral Saturated** | Error accumulated > limit | Info | Auto | | **Pump Cavitation** | Rapid pressure oscillation | Warning | Check suction | | **Downstream Blockage** | Pressure jump, flow static | Warning | Manual clear | --- ## 📺 HMI Layout ``` ┌──────────────────────────────────────────┐ │ FLOW RATE CONTROL - LOOP #1 │ ├──────────────────────────────────────────┤ │ │ │ Setpoint: 100.0 m³/h ⚙️ [Editable] │ │ │ │ ┌──────────────────────────────────┐ │ │ │ Actual: 99.8 m³/h │ │ │ │ [██████████░░░░░░░░░░░ 99.8] │ │ │ │ Target ↑ 100.0 m³/h │ │ │ │ Error: -0.2 m³/h (Stable) │ │ │ └──────────────────────────────────┘ │ │ │ │ Status: REGULATING [●●● Stable] │ │ Control Valve: 48% [████████░░░░░░│ │ │ Stability Time: 12m 45s (steady) │ │ │ │ System Pressures: │ │ Pump: 42.3 bar │ │ After Valve: 28.5 bar │ │ Pressure Drop: 13.8 bar │ │ │ │ ┌─────────────────────────────────┐ │ │ │ PID Tuning (Advanced) │ │ │ │ Kp: 0.50 Ki: 0.02 │ │ │ │ Kd: 0.05 Deadband: 0.5 m³/h │ │ │ │ [AutoTune] [Reset Error Max] │ │ │ └─────────────────────────────────┘ │ │ │ │ Alarm Thresholds: │ │ Low: 10 m³/h │ │ High: 180 m³/h │ │ │ │ Mode: [Off] [Manual ⊙] [Auto ◉] │ │ │ └──────────────────────────────────────────┘ ``` --- ## 🔧 Configuration Parameters ```json { "flow_sensor_type": "orifice_plate", "flow_units": "m3_per_hour", "flow_sensor_min": 0.0, "flow_sensor_max": 200.0, "flow_setpoint": 100.0, "alarm_low_m3_h": 10.0, "alarm_high_m3_h": 180.0, "deadband_m3_h": 0.5, "kp_proportional": 0.5, "ki_integral": 0.02, "kd_derivative": 0.05, "integral_anti_windup_limit": 50.0, "control_valve_type": "proportional_directional", "control_valve_response_ms": 300, "actuator_type": "control_valve_or_vfd_pump", "pump_max_pressure": 100.0, "system_design_flow": 150.0, "system_design_pressure": 50.0, "tuning_method": "ziegler_nichols", "scan_time_ms": 100 } ``` --- ## 📝 Implementation Checklist ### Before Deployment - [ ] **Flow meter calibrated** (certificate from NIST lab, ±2% accuracy minimum) - [ ] **Meter zero-flow verified** (0 flow = 4mA exactly) - [ ] **Control valve tested** (0-100% blade position smooth, no stick points) - [ ] **Pump pressure adequate** (for max setpoint + 10% safety margin) - [ ] **Suction priming confirmed** (foot valve holds, no air leaks) - [ ] **Downstream piping cleared** (full bore, no unexpected blockages) ### During Commissioning 1. **Manual valve test** (Control_Mode = MANUAL): - Valve 0% → 25% → 50% → 75% → 100% - Flow should increase smoothly - Record flow at each percentage 2. **Auto mode startup** (Control_Mode = AUTO): - Start at Flow_Setpoint = 50 m³/h (conservative) - System should settle within 60 seconds - Observe oscillation amplitude (should be ±3% max) - No valve chattering (opening/closing rapidly) 3. **Setpoint step test**: - Hold at 50 m³/h for 5 minutes (verify stability) - Step setpoint to 100 m³/h - Measure response time (<60 sec) - Measure overshoot (<5%) - Return to 50 m³/h, verify smooth ramp-down 4. **Downstream blockage simulation**: - Close downstream isolation valve 50% - Flow should stay constant at setpoint - Pump pressure will rise (control valve opens to compensate) - Re-open valve, verify system recovers 5. **Low flow (cavitation) test**: - Reduce setpoint to 10 m³/h - Monitor suction pressure (should stay >30 kPa) - If suction drops <10 kPa, cavitation risk --- ## 📊 Expected Performance | Metric | Target | Achievable | |--------|--------|-----------| | **Steady-state error** | ±2% | ±0.5-2% | | **Settling time** | 60 sec | 30-90 sec | | **Overshoot** | <5% | 2-7% | | **Oscillation** | <±3% peak | ±1-3% | | **Response to load change** | <30 sec | 15-45 sec | | **Valve response time** | <300 ms | 200-400 ms | | **Accuracy at partial flow** | ±2% | ±1-3% at 10-100% range | --- ## 🔄 Advanced Variations ### Ratio Control (Master/Slave) Link two flow loops: Setpoint_B = 0.5 × Setpoint_A → Used in chemical mixing (e.g., A:B = 2:1 mass ratio) ### Load-Compensated Control Measure system pressure drop, feed-forward to adjust valve opening → Faster response than pure PID feedback ### Cascade Flow Control Inner loop: Valve proportional pressure feedback Outer loop: Flow rate error feedback → Eliminates valve hysteresis effects ### Energy Optimization If flow at setpoint requires only 30% valve opening, close valve and reduce pump speed 30% (saves energy, reduces heat). --- **Production-ready flow rate regulation for chemical, water, and process systems.**

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