Field fix / guideDesign DocumentVendor-agnostic (IEC 61131-3)Water / Wastewaterindustrial-automation

Chemical Disinfection & Residual Monitoring — Control Design

Shared by TSIMEREZIVO Team · 4 Oct 2026 · 42 views

# Water/Wastewater Template: Chemical Disinfection & Residual Monitoring ## 1. Overview **Purpose:** Automatically inject chlorine or ozone into treated water to inactivate pathogens (bacteria, viruses, protozoa). Maintain residual disinfectant (0.2–0.5 mg/L free chlorine) throughout distribution system. Continuously monitor residual with sensor feedback; adjust pump speed to hold setpoint. **Industry Standards:** - EPA Drinking Water Standards (DBP — disinfection byproducts limit: 100 µg/L TTHM) - AWWA G300 (Water Utility Management Fundamentals) - NSF/ANSI 61 (Drinking water system components health effects) - NFPA 79 (Electrical installation for hazardous locations — chlorine gas systems) - OSHA 1910.119 (Process Safety Management for chlorine) **Critical Constraints:** - **Free chlorine residual:** maintained 0.2–0.5 mg/L (target 0.3 mg/L) - **Disinfection byproducts (DBP):** chlorine + organic matter → THMs (trihalomethanes); EPA limit 100 µg/L - **Contact time:** residual must stay in pipe for ≥30 minutes at low pipes velocity to kill pathogens (Ct concept: concentration × time) - **Flow variation:** day low = 80 m³/h; day high = 600 m³/h → must adjust chlorine dose 7.5:1 - **Chlorine decay:** first-order kinetic loss ≈ 10–20% per day in distribution pipes (temperature-dependent) - **Ozone:** faster killing (0.5 mg/L effective in <1 min) but doesn't residualize (no protection downstream) → must combine with chlorine - **Safety:** chlorine gas is toxic; requires automated leak detection + scrubber system - **Sensor fouling:** residual probes degrade; require monthly calibration & annual replacement **Relevant Physics:** - **Disinfection kinetics:** $\log (\frac{N}{N_0}) = -k \times C^n \times t$ (Chick-Watson law; N = organism count, k = rate constant) - **Residual decay:** $C(t) = C_0 \times e^{-kt}$ (exponential loss; k ≈ 0.1–0.2 day⁻¹) - **Ct concept:** $Ct = C \times t$ = "disinfection dose" (mg·min/L); for 3-log Giardia kill @ pH 7: Ct ≈ 60 mg·min/L --- ## 2. Control Philosophy **Challenge:** Must maintain precise residual (0.2–0.5 mg/L) despite: - Varying flow (7.5:1 turndown) - Varying water quality (temperature, pH, organic content) - Sensor drift & fouling - Equipment response lag (5–10 minutes from pump change to sensor detection) **Solution: Cascaded Residual + Demand Predictor** ``` LAYER 1 — Residual Feedback (Primary) Input: Chlorine residual sensor (mg/L, amperometric or colorimetric) SP: 0.3 mg/L nominal Output: Chlorine pump demand signal (%, 0–100) PID tuning: conservative to avoid overshoot (DBP formation) LAYER 2 — Demand Feedforward (Predictive) Inputs: Flow rate, water temperature, raw water TOC (Total Org. Carbon) Model: Dose = base_dose + (flow × factor_flow) + (temp × factor_temp) + (TOC × factor_toc) Output: Baseline pump speed; residual PID fine-tunes from here LAYER 3 — Sensor Validation & Fault Detection Check: residual not drifting >10% per week (linear drift → calibration needed) Check: residual lag time expected 5–10 min (not 30 sec = sensor short-circuit) Fallback: if sensor fails, revert to flow-proportional dosing + alert technician LAYER 4 — Safety Interlock Chlorine leak detection (Cl₂ concentration in headspace >2 ppm → activate scrubber) Maximum dose limit (never exceed 3 mg/L, EPA max contaminant level for chlorine) ``` --- ## 3. Control Logic **Pseudocode: Residual Disinfection Control** ```pascal { === CHEMICAL DISINFECTION & RESIDUAL CONTROLLER === } { Chlorine gas or sodium hypochlorite injection with residual feedback } PROCEDURE Residual_Disinfection_Master CONSTANTS RESIDUAL_SP = 0.3 { mg/L, setpoint } RESIDUAL_MIN_SAFE = 0.2 { mg/L, minimum for pathogens } RESIDUAL_MAX_LIMIT = 0.5 { mg/L, above this = over-dosing } RESIDUAL_ALARMING = 0.8 { mg/L, way too high } PID_KP = 5.0 { low gain to avoid overshoot → DBP } PID_KI = 0.08 PID_KD = 0.5 DEAD_BAND_MGL = 0.05 { ±0.05 mg/L } RESPONSE_LAG_SEC = 300 { 5 min expected lag from pump to sensor } SENSOR_DRIFT_LIMIT_PER_WEEK = 0.05 { mg/L per week = calibration needed } SENSOR_FAULT_THRESHOLD = 0.15 { mg/L, unreasonable jump = sensor error } CALIBRATION_INTERVAL_DAYS = 30 { monthly calibration required } CL2_LEAK_LIMIT_PPM = 2.0 { ppm in headspace = activate scrubber } CL2_MAX_DOSE_MGL = 3.0 { EPA max contaminant level } VARIABLES { Measured inputs } residual_sensor_mgl : REAL { mg/L, chlorine residual (0–5 range typical) } residual_filtered : REAL { low-pass filtered } system_flow_m3h : REAL { m³/h, total flow } water_temp_c : REAL { °C, affects chlorine decay } raw_water_toc_mgl : REAL { mg/L, total organic carbon (demand) } water_ph : REAL { pH } chlorine_gas_sensor_ppm : REAL { ppm, air monitor above tank } residual_sensor_age_days : INTEGER { days since last calibration } { PID state } residual_error : REAL residual_error_integral : REAL residual_error_derivative : REAL { Pump control } pump_demand_pct : REAL { 0–100% } pump_speed_vfd_hz : REAL { Hz, scaled to pump curve } pump_dose_rate_mgl_per_min : REAL { predicted mg/L/minute being dosed } pump_actual_flow_lpm : REAL { measured pump output } { Feedforward model } base_dose_mgl : REAL { static dose, adjusted rarely } flow_factor : REAL { dose adjustment per m³/h } temp_factor : REAL { dose adjustment per °C } toc_factor : REAL { dose adjustment per mg/L TOC } feedforward_component : REAL { calculated additive offset } { Diagnostics } residual_history[1..1440] : REAL { last 24 hours (1-minute samples) } residual_trend_mgl_per_day : REAL { drift rate } sensor_fault_detected : BOOLEAN sensor_calib_overdue : BOOLEAN alarms_active : ARRAY[*] OF STRING BEGIN { === SENSOR ACQUISITION & VALIDATION === } residual_sensor_mgl = Read_Residual_Analyzer() { 0–5 mA analog input } { Input sanitization: reject obvious outliers } IF ABS(residual_sensor_mgl - residual_filtered) > SENSOR_FAULT_THRESHOLD THEN sensor_fault_detected = TRUE Log_Alarm("RESIDUAL_SENSOR_FAULT_SPIKE_DETECTED") { Continue with last good value; don't change pump abruptly } residual_sensor_mgl := residual_filtered ELSE sensor_fault_detected = FALSE END IF { Low-pass filter (tau ≈ 2 minutes, accounts for response lag) } alpha = 0.05 residual_filtered = residual_filtered × (1 - alpha) + residual_sensor_mgl × alpha { Sensor age } residual_sensor_age_days = Days_Since_Cal(residual_sensor_calibration_date) IF residual_sensor_age_days > CALIBRATION_INTERVAL_DAYS THEN sensor_calib_overdue = TRUE Log_Warning("RESIDUAL_SENSOR_CALIBRATION_OVERDUE") END IF { Other measurements } system_flow_m3h = Read_System_Flow() water_temp_c = Read_Water_Temperature() raw_water_toc_mgl = Read_Raw_Water_TOC() { optional; if available } water_ph = Read_Water_PH() chlorine_gas_sensor_ppm = Read_CHLORINE_HEADSPACE_CONCENTRATION() { === SENSOR VALIDATION: DRIFT CHECK (Kalman-like) === } { Shift history: add latest reading } SHIFT_LEFT(residual_history[1..1440]) residual_history[1440] := residual_filtered { Calculate drift: linear trend over last 7 days if we have data } IF scan_count > (7 × 24 × 60) THEN { ≥7 days of history } residual_7day_ago = residual_history[1] residual_trend_mgl_per_day = (residual_filtered - residual_7day_ago) / 7 IF ABS(residual_trend_mgl_per_day) > SENSOR_DRIFT_LIMIT_PER_WEEK / 7 THEN Log_Warning("RESIDUAL_SENSOR_DRIFT_DETECTED_CALIBRATION_RECOMMENDED") END IF END IF { === FEEDFORWARD DEMAND MODEL === } { Base calibration-dependent constants (tuned per site) } base_dose_mgl = 0.5 { baseline mg/L to achieve 0.3 residual } flow_factor = 0.0003 { additional mg/L per m³/h } temp_factor = 0.02 { mg/L rise per °C (chlorine decays faster in warm water) } toc_factor = 0.15 { mg/L per mg/L of TOC } { Calculate demand estimate } feedforward_component = base_dose_mgl + (system_flow_m3h × flow_factor) + (water_temp_c × temp_factor) + (raw_water_toc_mgl × toc_factor) { === RESIDUAL FEEDBACK CONTROLLER (PID) === } residual_error = RESIDUAL_SP - residual_filtered { Deadband: within ±deadband, don't change pump } IF ABS(residual_error) < DEAD_BAND_MGL THEN residual_error := 0 END IF { Integral } residual_error_integral = residual_error_integral + residual_error residual_error_integral = LIMIT(residual_error_integral, -10, 10) { anti-windup } { Derivative } residual_error_derivative = residual_error - residual_error_prev { PID } pid_output = (PID_KP × residual_error) + (PID_KI × residual_error_integral) + (PID_KD × residual_error_derivative) { Combine feedforward + feedback } pump_demand_pct = LIMIT(50 + pid_output, 0, 100) { 50% = neutral, ±pedal width = feedback adjustment } { Rate limiter: prevent aggressive pump swings } IF ABS(pump_demand_pct - pump_demand_pct_prev) > 5 THEN pump_demand_pct = pump_demand_pct_prev + SIGN(...) × 5 END IF { Convert demand % to VFD frequency (scaled to pump curve) } pump_speed_vfd_hz = 30 + (pump_demand_pct / 100) × 20 { 30–50 Hz } Write_Chlorine_Pump_VFD(pump_speed_vfd_hz) { Estimate dose rate (for logging) } pump_actual_flow_lpm = Read_Chlorine_Pump_Flow() { optional; feedback } { If unavailable, assume linear relationship: demand % ∝ flow } pump_dose_rate_mgl_per_min = (pump_demand_pct / 100) × 2.0 { empirical scaling } { === SAFETY INTERLOCKS === } CLEAR alarms_active { Chlorine gas leak detection (above tank) } IF chlorine_gas_sensor_ppm > CL2_LEAK_LIMIT_PPM THEN APPEND alarms_active "CHLORINE_GAS_LEAK_ACTIVATE_SCRUBBER" Activate_Chlorine_Scrubber() { caustic soda injection } Shutdown_Chlorine_Pump() { stop injection immediately } Log_Alarm("CHLORINE_LEAK_CRITICAL") END IF { Residual too low (inadequate disinfection) } IF residual_filtered < RESIDUAL_MIN_SAFE THEN APPEND alarms_active "RESIDUAL_INADEQUATE_INCREASE_DOSE" pump_demand_pct = pump_demand_pct + 10 { boost } Log_Warning("RESIDUAL_LOW_" + STR(residual_filtered)) END IF { Residual too high (DBP risk, over-dosing) } IF residual_filtered > RESIDUAL_ALARMING THEN APPEND alarms_active "RESIDUAL_EXCESS_REDUCE_DOSE" pump_demand_pct = MAX(0, pump_demand_pct - 15) { reduce } Log_Warning("RESIDUAL_EXCESSIVE_" + STR(residual_filtered)) END IF { Maximum dose limit } IF pump_dose_rate_mgl_per_min > CL2_MAX_DOSE_MGL THEN APPEND alarms_active "MAXIMUM_DOSE_LIMIT_EXCEEDED" pump_demand_pct = 0 { shut off pump } END IF { Sensor fault: revert to flow-bleed } IF sensor_fault_detected OR sensor_calib_overdue THEN Log_Warning("SENSOR_ISSUE_USING_FLOW_PROPORTIONAL_FALLBACK") pump_demand_pct = (system_flow_m3h / 700) × 100 { simple flow scaling } END IF { === LOGGING & TREND === } IF MOD(scan_count, 60) = 0 THEN { every 1 minute } Log_Process_Data({ timestamp: Get_Timestamp(), residual_mgl: residual_filtered, residual_error_mgl: residual_error, pump_demand_pct: pump_demand_pct, pump_vfd_hz: pump_speed_vfd_hz, flow_m3h: system_flow_m3h, water_temp_c: water_temp_c, toc_mgl: raw_water_toc_mgl, dose_rate_mgl_per_min: pump_dose_rate_mgl_per_min, cl2_gas_ppm: chlorine_gas_sensor_ppm, alarms_count: LEN(alarms_active) }) END IF residual_error_prev := residual_error pump_demand_pct_prev := pump_demand_pct END PROCEDURE ``` --- ## 4. Tag List (Selected) ``` RESIDUAL_CHLORINE_MGL { mg/L, free chlorine measured } RESIDUAL_CHLORINE_SETPOINT { mg/L, target: 0.3 } CHLORINE_PUMP_DEMAND_PCT { % demand } CHLORINE_PUMP_VFD_FREQUENCY_HZ { Hz } CHLORINE_PUMP_DOSE_RATE_MGL_MIN { mg/L per minute being dosed } CHLORINE_GAS_CONCENTRATION_PPM { ppm, headspace monitor } SYSTEM_FLOW_M3H { m³/h, treated water flow } WATER_TEMPERATURE_C { °C } WATER_TOC_MGL { mg/L, total organic carbon (optional) } WATER_PH { pH } RESIDUAL_HISTORY_24H { trend data } RESIDUAL_SENSOR_DRIFT_MGL_DAY { mg/L per day (drift indicator) } RESIDUAL_SENSOR_CALIB_DUE { boolean } CHLORINE_SCRUBBER_ACTIVE { boolean } ``` --- ## 5. Alarm & Trip Matrix | **Condition** | **Severity** | **Action** | |---|---|---| | **Residual < 0.2 mg/L** | 🔴 CRIT | Increase pump 10%; alert ops | | **Residual > 0.8 mg/L** | 🔴 CRIT | Decrease pump 15%; investigate over-dose | | **Chlorine gas >2 ppm** | 🔴 CRIT | Stop pump; activate scrubber; evacuate site | | **Sensor drift >10% / week** | ⚠ WARN | Recommend calibration appointment | | **Sensor calib overdue** | ⚠ WARN | Switch to flow-proportional fallback | --- ## 6. HMI Layout ``` ╔════════════════════════════════════════════════════════════════════╗ ║ CHLORINE DISINFECTION & RESIDUAL MONITORING ║ ╚════════════════════════════════════════════════════════════════════╝ SYSTEM STATUS: [ RUNNING NORMAL ] ✓ Residual maintained ┌─────────────────────────────────────────────────────────────────┐ │ RESIDUAL CONTROL │ │ │ │ Setpoint: 0.30 mg/L │ │ Measured: 0.32 mg/L ✓ (within band) │ │ Error: +0.02 mg/L (PID holding steady) │ │ Status: [ STABLE ] [█████████░░░░░░░░░░░░░░░] │ │ 0.2 0.3 0.5 1.0 mg/L │ │ │ │ Pump Demand: 48% VFD Frequency: 39.6 Hz │ │ Dose Rate: 0.96 mg/L per minute │ │ Pump Flow: 2.4 LPM │ └─────────────────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────────────────┐ │ SYSTEM CONDITIONS │ │ │ │ Treated Flow: 545 m³/h (mid-morning) │ │ Temperature: 21°C ✓ COOL (less chlorine decay) │ │ Water pH: 7.2 ✓ OK (higher pH = slower disinfect) │ │ Raw TOC: 4.2 mg/L (moderate demand) │ │ Feedforward Bias: +0.08 mg/L (temp & TOC adjusted) │ │ │ │ Sensor Age: 18 days ✓ (calib next: 2026-05-13) │ │ Sensor Drift: +0.01 mg/L per day (acceptable) │ └─────────────────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────────────────┐ │ SAFETY MONITORING │ │ │ │ Chlorine Gas Concentration: 0.0 ppm ✓ GOOD │ │ Max Dose Rate (EPA limit): 3.0 mg/L (current: 0.96 OK) │ │ Scrubber Status: STANDBY ✓ READY │ │ │ │ Gas Detector: FUNCTIONING ✓ | Last Test: 2026-04-10 │ └─────────────────────────────────────────────────────────────────┘ 24-HOUR TREND: ┌─────────────────────────────────────────────────────────────────┐ │ Residual (mg/L) Pump Demand (%) Flowrate (m³/h) │ │ 0.8 ┤│ 100 ┤ ╱╲╱╲ 800 ┤ │ │ 0.5 ┼└──────── 75 ┤ ╱ ╲╱╲──── 600 ┼─────┐ │ │ 0.3 ┼ ────███ 50 ┤ 400 ┤ └─── ─── │ │ 0.1 ┤ 25 ┤ 100 ┤ │ │ └───────────── └────────────── └────────────── │ │ 0 12 24 0 12 24 │ │ Steady at ~0.32 mg/L throughout day | Peak flow 600 m³/h │ └─────────────────────────────────────────────────────────────────┘ BUTTONS: [ Calibrate Sensor ] [ Test Scrubber ] [ Fallback Mode ] [ View Detailed Log ] [ Export CSV ] ``` --- ## 7. Configuration **JSON (chlorine_disinfection_config.json)** ```json { "disinfection": { "type": "chlorine_gas_or_hypochlorite", "residual_setpoint_mgl": 0.3, "residual_min_safe": 0.2, "residual_max_alarm": 0.8, "residual_max_epa_limit": 3.0 }, "pid_tuning": { "kp": 5.0, "ki": 0.08, "kd": 0.5, "deadband_mgl": 0.05, "rate_limit_pct": 5 }, "feedforward": { "base_dose_mgl": 0.5, "flow_factor": 0.0003, "temp_factor": 0.02, "toc_factor": 0.15 }, "pump": { "type": "variable_frequency_drive", "frequency_min_hz": 30, "frequency_max_hz": 50, "rated_capacity_lpm": 5.0 }, "sensor": { "type": "amperometric_residual_analyzer", "range_mgl": {"min": 0, "max": 5}, "calibration_interval_days": 30, "response_lag_seconds": 300 }, "safety": { "chlorine_leak_limit_ppm": 2.0, "scrubber_caustic_capacity_liters": 200, "max_dose_mgl": 3.0 } } ``` --- ## 8. Commissioning Checklist - [ ] Chlorine pump sized and calibrated to deliver 0–3 mg/L dose - [ ] Residual analyzer (amperometric) installed, zero & span calibrated - [ ] Gas detector placed in tank headspace; tested monthly - [ ] Scrubber system (caustic soda injection) tested at 2 ppm Cl₂ concentration - [ ] Feedforward model calibrated: collect residual vs. flow data over 24 hours - [ ] PID tuning: set Kp = 5, Ki = 0.08; verify no oscillation ±0.05 mg/L - [ ] Flow-proportional fallback tested: disable sensor, confirm pump responds to flow - [ ] 48-hour steady-state run: residual stable within ±0.05 mg/L at various flows - [ ] Sensor drift calculated over 7 days: should be <0.05 mg/L drift --- **Document Version:** 1.0 **Last Updated:** 2026-04-13 **Status:** Ready for Production **Approval:** Water Quality & Safety Engineering (pending)

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