Temperature control of an oven
About this lesson
One whole design, start to finish: measure an oven with a bump test, read its gain, dead time and time constant, tune a PID with the Ziegler-Nichols reaction-curve rule, then meet the problems real hardware adds. A heater that cannot cool and integrator windup turn a textbook design into a 262 °C overshoot; one extra line of Python fixes it.
Hold an oven at 180 °C
The job: bring an oven from 20 °C to 180 °C and keep it there. Our only handle is a heater that gives 0 to 2.5 kW. It can heat but never cool. A thermocouple, the sensor, reads the temperature.
setpoint 180 °C oven now 20 °C (room temperature) heater 0 to 2.5 kW, heats only sensor thermocouple inside the oven The design, in order: 1. measure a model of the oven 2. tune a controller from the model 3. fix the problems the real parts add
Read the lesson step by step
Hold an oven at 180 °C
The job: bring an oven from 20 °C to 180 °C and keep it there. Our only handle is a heater that gives 0 to 2.5 kW. It can heat but never cool. A thermocouple, the sensor, reads the temperature.
setpoint 180 °C oven now 20 °C (room temperature) heater 0 to 2.5 kW, heats only sensor thermocouple inside the oven The design, in order: 1. measure a model of the oven 2. tune a controller from the model 3. fix the problems the real parts addThe bump test
We have no equation for the oven, so we measure one. With no controller, we fix the heater at 1 kW and record the temperature for an hour. This open-loop experiment is called a bump test or step test.
heater fixed 1 kW from t = 0 oven at 16 min 89.5 °C oven at 60 min 127.8 °C (still creeping up) The curve is the oven's step response: what any model we fit must reproduce.Read three numbers
Gain K: 1 kW would end 110 °C up, so K = 110 °C/kW. Dead time θ: nothing moves for 1 minute. Time constant τ: 63 % of the rise comes 15 minutes after that. Model: G(s) = 110e^(−s)/(15s + 1).
gain K = 110 °C per kW (final rise / power) dead time θ = 1 min (flat start) time const τ = 15 min (63.2 % point at θ + τ = 16 min: 20 + 0.632 × 110 = 89.5 °C) 110 e^(−1·s) G(s) = ───────────── 15s + 1 The hour stops short of the final 130 °C. By θ + 4τ the curve is 98 % of the way there, so the final value is read where it levels off. held at 180 °C needs (180 − 20) / 110 = 1.45 kWFirst try: a thermostat
Suppose our thermostat just switches: full heat below 178 °C, off above 182 °C. The dead time spoils it. Each switch acts a minute late, so the oven keeps swinging between 167.8 and 189.3 °C.
on below 178 °C, off above 182 °C swing after warm-up 167.8 to 189.3 °C Why so wide: in the 1 min dead time the oven keeps heating at about 7.7 °C/min and cools at about 10.7 °C/min, long after the switch has flipped.Tune a PID from the model
Ziegler and Nichols turned the bump-test numbers into PID settings: Kp = 1.2τ/(Kθ) = 0.164 kW per °C, Ti = 2θ = 2 min, Td = 0.5θ = 0.5 min. The rule is a known starting point, not a final answer.
Ziegler-Nichols, reaction-curve method (PID) Kp = 1.2 τ / (K θ) = 1.2 × 15 / (110 × 1) = 0.164 kW/°C Ti = 2 θ = 2 min Td = 0.5 θ = 0.5 min A PID adds three terms: P reacts to the error now, I to the error added up over time, D to how fast the temperature is changing. Kp is the gain, Ti the integral time, Td the derivative time. The lesson "The PID controller" teaches them. power = Kp (e + ∫e dt / Ti − Td dT/dt) The D term uses the measured temperature, not the error, so a setpoint jump gives no kick.Run it: a huge overshoot
Start from cold. The oven reaches 180 °C after 14.1 minutes, then keeps climbing to 262.6 °C at 33.1 minutes. Any cake inside is ruined. The model was right and the rule is standard, so what went wrong?
import math K, TAU, LAG, DT = 110, 15, 100, 0.01 # °C/kW, min, steps of dead time, min a = math.exp(-DT / TAU) def oven(temp, power_then): # one 0.6 s step target = 20 + K * power_then return target + (temp - target) * a Kp, Ti, Td = 1.2 * TAU / (K * 1), 2.0, 0.5 # Ziegler-Nichols temp, last, I, queue, peak = 20.0, 20.0, 0.0, [0.0] * LAG, 0.0 for n in range(4001): # 40 min e, dT = 180 - temp, (temp - last) / DT I += e * DT power = min(max(Kp * (e + I / Ti - Td * dT), 0), 2.5) queue.append(power); last = temp temp = oven(temp, queue.pop(0)); peak = max(peak, last) print(round(peak, 1)) # 262.6Integrator windup
All through the warm-up the PID asked for far more than 2.5 kW, so the heater sat at its limit. The integral kept adding up error anyway. At 180 °C it alone still asks for 86.5 kW. That is integrator windup.
at t = 14.1 min the oven first reaches 180 °C error 0 °C integral Kp·I/Ti = 86.5 kW heater stays at 2.5 kW until 32.1 min The integral piled up error during the warm-up that the heater could not act on. It must unwind before the heater eases off.An oven cannot cool
Too hot, the best the heater can do is switch off; it cannot pull heat out. It sits at 0 kW for 10.8 minutes while the oven loses heat through its walls, and is back under 185 °C only at 39.1 minutes.
peak 262.6 °C at 33.1 min heater off from 32.4 min, for 10.8 min under 185 °C at 39.1 min A one-sided actuator: overshoot costs time, because the only way down is the oven's own heat loss.Fix: clamp the integral
Same gains, one new line: add to the integral only while the heater is not at a limit. Now the warm-up peaks at 182.1 °C and stays within 1 °C of 180 °C after 17.4 minutes.
import math K, TAU, LAG, DT = 110, 15, 100, 0.01 # °C/kW, min, steps of dead time, min a = math.exp(-DT / TAU) def oven(temp, power_then): # one 0.6 s step target = 20 + K * power_then return target + (temp - target) * a Kp, Ti, Td = 1.2 * TAU / (K * 1), 2.0, 0.5 # Ziegler-Nichols temp, last, I, queue, peak = 20.0, 20.0, 0.0, [0.0] * LAG, 0.0 for n in range(4001): # 40 min e, dT = 180 - temp, (temp - last) / DT u = Kp * (e + I / Ti - Td * dT) power = min(max(u, 0), 2.5) if u == power: I += e * DT # clamp queue.append(power); last = temp temp = oven(temp, queue.pop(0)); peak = max(peak, last) print(round(peak, 1)) # 182.1Someone opens the door
At 40 minutes the door opens for one minute and lets out heat, modelled as 2 kW. The oven dips to 165.8 °C. The PID goes to full power and is back within 1 °C 6.1 minutes after opening.
door open t = 40 to 41 min, losing 2 kW lowest 165.8 °C within 1 °C 6.1 min after opening The integral then settles back to the 1.45 kW that holds 180 °C: no steady error, for any loss the heater can still make up.
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01In a bump test the heater steps from 0 to 1 kW. The oven does nothing for 1 minute, then heads for 130 °C from 20 °C, passing 89.5 °C at 16 minutes. What are K, θ and τ?
The gain is the change in output over the change in input: (130 − 20) / 1 = 110 °C/kW. The dead time is the flat start, 1 minute. The 63.2 % point comes at θ + τ = 16 minutes, so τ = 15 minutes.
02Why does the on/off thermostat keep swinging about 10 °C either side of the setpoint, even with a ±2 °C switching band?
For one minute after each switch nothing changes, so the oven carries on at several °C per minute. That is why it swings between 167.8 and 189.3 °C.
03During the warm-up the PID asks for far more than the heater's 2.5 kW. What is integrator windup?
The integral cannot tell that its requests are being ignored. At 180 °C it alone still asks for 86.5 kW, so the heater stays on until 32.1 minutes and the oven reaches 262.6 °C.
04Why is an overshoot worse for an oven than for a loop that can push both ways?
The actuator is one-sided. Here the heater sits at 0 kW for 10.8 minutes, and the oven is only back under 185 °C at 39.1 minutes.
05Which one-line change cures the windup in this lesson?
With the same gains, clamping stops the integral piling up during the warm-up. The peak falls from 262.6 °C to 182.1 °C, and the loop still recovers from the door opening.
Glossary
- PID controller
- A controller whose power is the sum of three terms: Proportional (the error now), Integral (the error added up over time) and Derivative (how fast the temperature is changing). The lesson The PID controller teaches it.
- Kp, Ti, Td
- The PID settings: Kp is the proportional gain, Ti the integral time (smaller means a stronger I term) and Td the derivative time.
- Bump test (step test)
- An open-loop experiment: step the actuator to a fixed value and record the output. The curve gives the plant's model.
- Dead time (θ)
- A pure delay: how long after the input changes before the output starts to move. Here 1 minute.
- First order plus dead time
- The model G(s) = K e^(−θs) / (τs + 1): a gain, a delay and one time constant. A common fit for thermal processes.
- Ziegler-Nichols reaction-curve method
- A 1942 rule that turns K, θ and τ from a bump test into PID settings: Kp = 1.2τ/(Kθ), Ti = 2θ, Td = 0.5θ.
- Saturation
- The actuator hitting its limit. This heater cannot go below 0 kW or above 2.5 kW.
- Integrator windup
- The integral term growing while the actuator is saturated, so it keeps the actuator at its limit long after the error has changed sign.
- Clamping (conditional integration)
- An anti-windup cure: stop adding to the integral while the actuator is at a limit.
- Disturbance
- An outside change that moves the output, here the door letting heat out.
Notes and sources
- The oven is a first-order model with a dead time and illustrative numbers: 110 °C per kW, a 15-minute time constant and a 1-minute delay, at 20 °C ambient. Every curve and number in the figure is computed from it.
- The Python on the steps is plain Python 3. It updates the controller every 0.6 s, delays the heater power by one minute in a list, and moves the oven forward with the exact solution of its equation between updates, just as the figure does.
- Ziegler and Nichols published two methods in 1942. This lesson uses the first, read from the open-loop step response; the lesson on Ziegler-Nichols tuning uses the second, from the gain that makes a loop oscillate. Both aim at a quarter-decay response, which is lively for an oven.
- A real oven element is usually switched by a relay or a solid-state relay. A controller that asks for 1.45 kW gets it on average: the element is on for a share of each short cycle (time-proportioning). The oven's slow response smooths the pulses.
- Clamping is one cure for windup; back-calculation is another. The lesson on actuator limits and integrator windup compares them.
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley
- K. Ogata, Modern Control Engineering, 5th ed., Pearson (§4-5 thermal systems; ch. 8, §8-2 Ziegler-Nichols rules)
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 4 PID; ch. 9 nonlinear systems)
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
- Python Control Systems Library (python-control) documentation
Quiz Unlocks after the last step.