LIC-101  Tank Level PID · gauge-sims

t = 0 s RUN ×10 all sims
PV level
–m
SP
–m
Error SP−PV
–m
CO output
–%
Valve pos.
–%
Fin
–L/s
Fout drain
–L/s
Fdist
–L/s
P / I / D
–
Mass-bal. err
–
PV level (m)SP (m)
CO output (%)valve position (%)
FinFoutFdist (L/s)
LAHH — OVERFLOW
LALL — TANK EMPTY
CO SATURATED

Model, equations & assumptions (SI units)

Process

A · dh/dt = F_in − F_out − F_dist (volume balance, constant density) F_in = Cv_max · v / 100 (linear valve, constant supply pressure) τ_v · dv/dt = u − v (first-order actuator lag; v = u if lag off) F_out = k · √h (gravity drain, Torricelli, free discharge) 0 ≤ h ≤ H (level clamped; clipped volume = overflow / unmet draw)
SymbolMeaningValueUnit
Atank cross-section0.5m²
Htank height2.0m
Cv_maxinflow at 100 % valve0.010 (10 L/s)m³/s
kdrain coefficient0.005m^2.5/s
τ_vvalve/actuator lag5 (adjustable)s
F_distdisturbance outflow (negative = extra inflow)sliderm³/s (shown in L/s)
u, vcontroller output, valve position0–100%

Linearised about h₀: process gain K = (Cv_max/100)·2√h₀/k ≈ 0.04 m/% and time constant τ = 2A√h₀/k ≈ 200 s at h₀ = 1 m. The tank self-regulates: with the valve fixed, level settles where Cv_max·v/100 = k√h + F_dist. At full valve with no disturbance the steady state would be h = (Cv_max/k)² = 4 m > H, so the tank can overflow.

PID controller (ISA/standard form)

e = SP − PV (reverse action: more level ⇒ less inflow; this is correct for level on inflow) e = PV − SP (direct action — wrong here, the loop runs away; try it) Positional: u_k = Kp·e_k + I_k + D_k, I_{k+1} = I_k + Kp·Ts/Ti·e_k (+ anti-windup term) Derivative on measurement, filtered: PV_f ← PV_f + Ts/(Tf+Ts)·(PV − PV_f), Tf = Td/10 D_k = −s·Kp·Td·(PV_f,k − PV_f,k−1)/Ts (s = +1 reverse, −1 direct) Velocity: Δu_k = Kp·(e_k − e_k−1) + Kp·Ts/Ti·e_k + (D_k − D_k−1), u_k = clamp(u_k−1 + Δu_k) Output clamp: 0 ≤ u ≤ 100 % Anti-windup (positional): back-calculation I += Kp·Ts/Ti·e + Ts/Tt·(u_clamped − u_unclamped), Tt = Ti (or √(Ti·Td)) conditional integration: skip the integral update when it would push further into saturation velocity form: inherently windup-free (the clamped output is the state)

Units: Kp in %/m (percent output per metre of level error), Ti and Td in seconds, Ti = 0 disables integral action. The controller is sampled every Ts and its output is held constant between samples (zero-order hold). The plant is integrated with fixed-step RK4 at Δt = 0.05 s; sim speed only changes how many steps run per animation frame, so results are identical at any speed or frame rate.

Auto/Manual, bumpless: in MANUAL the operator sets the output; the controller keeps tracking (I = u − P − D) so switching back to AUTO starts from the same output with no bump. Switching to MANUAL holds the last automatic output.

Default tuning, from IMC/lambda rules for the linearised first-order process (Ti ≈ τ, Kp = τ/(K·λ) with λ ≈ 50 s): Kp = 100 %/m, Ti = 200 s, Td = 0 s, Ts = 0.5 s. A +0.25 m SP step settles (±2 % band) in about 2.7 min with <1 % overshoot. Raise Kp or cut Ti to see overshoot and oscillation; use a big SP step (e.g. 1 → 1.9 m) with anti-windup "None" to see integral windup.

Assumptions

Incompressible liquid, constant density, perfectly mixed, vertical cylindrical tank with constant area; free gravity discharge (no downstream back-pressure); valve inherent characteristic linear and installed at constant ΔP; ideal level transmitter (no noise or lag); no dead time beyond the sampling and the valve lag. Hobby/learning model — not a design tool.