S9 · Lesson 41 · Digital control
Sampling a plant with a zero-order hold, mapping poles with z = e^{sT}, choosing the sample rate, converting analog controllers with the Tustin transform and prewarping, writing a discrete PID, and the gain limits sampling introduces
Almost every controller built today is a few lines of code in a microcontroller's timer interrupt: read the ADC, compute, write the PWM. Between samples the controller is blind and its output is frozen, so the loop is part continuous and part discrete. Sampled fast enough, a digital loop behaves like the analog design it came from; sampled too slowly, it loses phase, gain margin and finally stability. This lesson gives the tools for both: exact discrete models of the plant, and conversions of continuous controllers into code.
- A pair of continuous poles at sampled every T: they map to in the z-plane, where stability means inside the unit circle.
- Fast sampling (small T) crowds the poles near z = 1, where all slow continuous dynamics end up. Slow sampling swings them around the circle.
- With ωT = π the poles reach the negative real axis: the sampled system can no longer tell this oscillation from one at a lower frequency (aliasing).
Predict
The motor under proportional speed control is stable for every gain in continuous time. Sampled at 1 kHz with a hold, how large can be?
The sampled plant is , and with the closed-loop pole is . It leaves the unit circle at −1 when = 1.939/1.212 = 1.60. A first-order continuous loop can't go unstable, but the hold's half-sample delay plus a sample of computation make the sampled one able to.
Name it
The sampled plant
A zero-order hold keeps constant over each sample period T. For the exact discrete model is
For : and .
Poles and the sample rate
Each continuous pole maps to : radius , angle . Stable means |z| < 1. A common rule samples 10 to 30 times faster than the closed-loop bandwidth; the hold's delay (lesson 30) costs radians of margin.
From analog designs: the Tustin transform
Replace s by
which maps the left half-plane exactly onto the unit disk, so stable stays stable. It warps frequency: analog ω lands at digital . To place a corner exactly at f, prewarp: design the analog prototype at .
Discrete PI and PID
Tustin applied to gives
the velocity form, which updates the output by increments and makes anti-windup easy (clamp ). Add a filtered difference for the derivative.
Things only digital loops do
A discrete controller can place every closed-loop pole at z = 0: the deadbeat response settles exactly in n samples, at the cost of large actuator swings. And quantization of the ADC and of fixed-point coefficients (lesson 14 of C12) can cause small limit cycles near the setpoint.
Worked example
Discretize the motor speed plant at 1 kHz and convert the PI controller of lesson 15 ( = 0.4, = 16 ms).
Show the solution
- Discretize the plant. so .
- Tustin PI. three multiplies and adds per interrupt.
- Check the sample rate. The closed loop's 2 ms time constant means a bandwidth of 500 rad/s (80 Hz), and 1 kHz is only 12.6 times that, at the low end of the 10-to-30 rule.
- A faster rate. Sampling at 2 kHz or more would track the analog design more closely.
Answer the plant becomes and the controller .
Worked example
Where do the servo poles of lesson 34, , land when sampled at 1 kHz?
Show the solution
- Radius.
- Angle.
- Why so close to z = 1. That's as it should be when sampling is about 125 times faster than the poles' natural frequency (50 rad/s, 8 Hz).
- At 100 Hz. The radius would be 0.705 and the angle 20.5°.
Answer at radius 0.9656 and angle ±2.05°, close to z = 1.
Worked example
A plant is sampled every 5 ms with a hold. What proportional gain puts the closed-loop pole at z = 0, and what does the output settle to?
Show the solution
- Discretize.
- Deadbeat gain. With the closed-loop pole is , which is zero for deadbeat, settling in one sample.
- Where it settles. a 39% error.
- What deadbeat needs. Deadbeat speed needs integral action as well, and its large first move often saturates the actuator.
Answer K = 0.771 puts the pole at z = 0, and the output settles to 0.607r, a 39% error.
Check
A continuous pole with real part −75 s⁻¹ is sampled every 2 ms. What's the radius of the discrete pole?
Check
A plant with τ = 5 ms is sampled every 0.5 ms with a hold. What's Γ, the input coefficient of the discrete model?
Check
The same sampled plant gets . What's the largest stable ?
Check
A PI controller ( = 1, = 2 ms) is converted by Tustin's method at T = 2 ms. What's the coefficient on ?
Check
A Tustin-converted filter sampled at 1 kHz needs its corner at exactly 200 Hz. What corner should the analog prototype have?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
A continuous pole pair with damped frequency 100 rad/s is sampled every 1 ms. At what angle do the discrete poles sit?
Check
A plant with τ = 10 ms is sampled every 1 ms with a hold.
(a)
What is Φ?
(b)
What proportional gain puts the closed-loop pole at z = 0?
(c)
What fraction of a step reference does the output settle to?
Check
A continuous pole at is sampled every T seconds.
Step 1
What is the discrete pole's radius?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is its angle, in radians?
Step 3
What is its real part?
Explain why
Why can a sampled first-order loop go unstable when the continuous one can't?
In continuous time a first-order loop responds to the error instantly, so more gain only makes the correction faster. A sampled loop measures once, then holds its command for a whole period, and its correction is based on information that's one sample old. With high gain, a small error produces a command so large that by the next sample the output has overshot the setpoint by more than the original error, in the other direction. Each sample then flips and grows the error, which is the discrete pole crossing −1. The hold and the sampling act like a delay, and delay is what limits gain.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.