Lite / Engineering Complex Systems / Week 15
When a computer makes a stable loop unstable
Proportional control of a heater can't go unstable on paper, however high the gain. Run it on a microcontroller and it oscillates wildly. Who is right?
Why should I care?
Every real controller runs on a computer that samples, computes and holds. Ignoring that turns a guaranteed-stable paper design into an oscillating machine. Knowing the limit tells you how fast your control loop must run.
- Model a sampled P loop on a first-order plant exactly between samples.
- Derive the gain limit K·Kp < (1 + a)/(1 − a), with a = e^(−T/τ), and use it.
- Explain why sampling, delay and big gains together cause discrete-time instability.
Predict
Sampling period 0.5 s, plant τ = 1 s, K = 1. Which gain is unstable?
- Kp = 1
- Kp = 3
- Kp = 6
- None of them
Guess first, then reveal
The limit is about 4.1, so Kp = 6 makes the per-sample multiplier less than −1: each sample overcorrects more than the last.
Discover
With T = 0.5 s, raise Kp until the samples start to grow, and compare with the readout's limit. Then halve T and find the new limit. What is the limit as T gets very small?
What the interactive shows (text version)
The sampled-loop diagram plots the output only at sample times. With a modest gain the samples rise to a level just below the set point. Past the computed gain limit they alternate above and below with growing size. Shortening the sample period raises the limit.
Watch (optional)
Watch for: Listen for what changes when a controller is implemented digitally, and why the sample rate matters.
Why a controller running on a computer behaves differently from the ideal continuous one, including sampling effects on stability.
“Discrete control #1: Introduction and overview” by Brian Douglas (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Sample, compute, hold
A digital controller reads the sensor, computes a command and holds it until the next sample. Between samples the plant evolves open-loop. For a first-order plant this gives an exact recurrence: y[n+1] = a·y[n] + (1 − a)·K·u[n] with a = e^(−T/τ).
Overcorrection
With high gain, the held command pushes so hard that by the next sample the output has shot past the set point. The controller then pushes hard the other way. If each correction overshoots by more than the last error, the loop diverges. That is p = a − (1 − a)KKp < −1.
What helps
Sample faster (a → 1 and the limit grows), reduce the gain, or reduce delay. A common rule: sample 10–20 times per closed-loop time constant. The same mechanism explains why an Euler simulation with too big a step blows up (week 11).
Explain it another way
Intuitive
Steering a car with your eyes closed, opening them only every two seconds. Correct gently and you're fine; correct hard and you zigzag off the road.
Technical
Discrete-time stability requires all poles inside the unit circle, |z| < 1. ZOH discretisation of K/(τs + 1) gives a pole at a = e^(−T/τ); P feedback moves it to a − (1 − a)KKp.
Mathematical
As T → 0, a ≈ 1 − T/τ, so the limit (1 + a)/(1 − a) ≈ 2τ/T → ∞: the continuous loop has no limit. Equivalently KKp·T/τ < 2, the same shape as Euler's dt < 2τ_cl rule.
Applied
Motor current loops run at tens of kHz because the electrical time constant is around a millisecond; temperature loops can run at 1 Hz because τ is minutes.
Derivation: The gain limit of a sampled P loop
Plant τ·dy/dt + y = K·u. The controller samples y[n] every T seconds and holds u[n] = Kp·(r − y[n]) until the next sample.
With u constant over a period, the first-order solution gives exactly y[n+1] = a·y[n] + (1 − a)·K·u[n], with a = e^(−T/τ).
Substitute u[n]: y[n+1] = (a − (1 − a)·K·Kp)·y[n] + (1 − a)·K·Kp·r. The error is multiplied by p = a − (1 − a)·K·Kp each sample.
Stability needs |p| < 1. p < 1 always holds; p > −1 needs K·Kp < (1 + a)/(1 − a).
Example: τ = 1 s, T = 0.5 s, K = 1: a = 0.607, so Kp < 1.607/0.393 = 4.08. Halve T to 0.25 s: a = 0.779, Kp < 8.05.
Worked example 1
A heater has τ = 120 s and K = 0.5 °C per %. The controller runs every 10 s. What is the largest stable Kp?
a = e^(−10/120) = 0.920. Limit KKp < 1.920/0.080 = 24.0, so Kp < 24.0/0.5 = 48 %/°C. Well above any sensible gain, so sampling every 10 s is fine here.
Common mix-ups
If the continuous-time analysis says stable, the digital controller will be too.
✓ Sampling and delay can destabilise a loop the continuous model says is safe. Check the discrete model.More gain always means a faster, better response.
✓ In a sampled loop more gain eventually means overcorrection and instability.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
For the Smart Greenhouse or any heater you model, choose a sample period from the closed-loop time constant, compute the gain limit, and state your safety margin (for example, 'Kp at one third of the limit').
Reflect
Name a loop in a device you own that must run very fast, and one that can run slowly. What sets the difference?
Write your answer on paper or in your own notes. Lite never stores what you write.