School/□ Systems Engineer/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?
About 40 min · 3 goals · Checked by automated tests
1.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.
2.Predict
Sampling period 0.5 s, plant τ = 1 s, K = 1. Which gain is unstable?
Guess first. Being wrong here is how the surprise works.
3.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?
Loading the interactive…
Can't use the interactive? Read a description instead
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.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
τ = 1 s, K = 1, sampling period T = 0.5 s. What is the largest stable Kp? (Two decimal places.)
5.Watch
→ 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.
22 min 22 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
6.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
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.
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.
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.
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.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
A digital P controller samples a first-order plant (τ = 0.5 s, K = 0.5) every T = 2 s and holds its output between samples. Above what gain Kp does the loop become unstable?
Practice 3 · a fresh version every time
You simulate a P-controlled loop τ·dy/dt + y = K·Kp·(r − y) with explicit Euler. τ = 0.2 s, K = 2, Kp = 4. Above what time step dt (in seconds) does the simulation become unstable?
Practice 4
Your digital P loop oscillates. Which change is most likely to fix it without slowing the response?
Practice 5
The per-sample multiplier p = −0.6. How does the error behave?
8.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').
9.Reflect
Concepts: Stability, overshoot and delay · Real-time computing on robots · Proportional control