S941 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 −σ±jω sampled every T: they map to z=e(−σ±jω)T 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 20/(0.016s+1) under proportional speed control is stable for every gain in continuous time. Sampled at 1 kHz with a hold, how large can Kp be?

Name it

The sampled plant

A zero-order hold keeps u constant over each sample period T. For x˙=Ax+Bu the exact discrete model is

xk+1=Φxk+Γuk,Φ=eAT,Γ=∫0TeAτdτB

For K0/(τs+1): Φ=e−T/τ and Γ=K0(1−e−T/τ).

Poles and the sample rate

Each continuous pole maps to z=esT: radius e−σT, angle ωT. 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 ωcT/2 radians of margin.

From analog designs: the Tustin transform

Replace s by

s←2Tz−1z+1

which maps the left half-plane exactly onto the unit disk, so stable stays stable. It warps frequency: analog ω lands at digital 2Ttan−1⁡ωT2. To place a corner exactly at f, prewarp: design the analog prototype at tan⁡(πfT)/(πT).

Discrete PI and PID

Tustin applied to Kp(1+1Tis) gives

uk=uk−1+Kp(1+T2Ti)ek−Kp(1−T2Ti)ek−1

the velocity form, which updates the output by increments and makes anti-windup easy (clamp uk). Add a filtered difference (ek−ek−1)/T 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 (Kp = 0.4, Ti = 16 ms).

Show the solution
  1. Discretize the plant. Φ=e−0.001/0.016=0.9394Γ=20(1−0.9394)=1.212 so yk+1=0.9394yk+1.212uk.
  2. Tustin PI. uk=uk−1+0.4125ek−0.3875ek−1 three multiplies and adds per interrupt.
  3. 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.
  4. A faster rate. Sampling at 2 kHz or more would track the analog design more closely.

Answer the plant becomes yk+1=0.9394yk+1.212uk and the controller uk=uk−1+0.4125ek−0.3875ek−1.

Worked example

Where do the servo poles of lesson 34, −35±j35.7, land when sampled at 1 kHz?

Show the solution
  1. Radius. r=e−35×0.001=0.9656
  2. Angle. θ=35.7×0.001rad=2.05°
  3. 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).
  4. 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 2/(0.01s+1) 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
  1. Discretize. Φ=e−0.5=0.607Γ=2(1−Φ)=0.787
  2. Deadbeat gain. With uk=K(r−yk) the closed-loop pole is Φ−ΓK, which is zero for K=Φ/Γ=0.771 deadbeat, settling in one sample.
  3. Where it settles. y=ΓKr=Φr=0.607r a 39% error.
  4. 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 20/(τs+1) 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 uk=−Kpyk. What's the largest stable Kp?

Check

A PI controller (Kp = 1, Ti = 2 ms) is converted by Tustin's method at T = 2 ms. What's the coefficient on ek?

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 5/(τs+1) 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 −s±jw 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°.

Explain why

Why can a sampled first-order loop go unstable when the continuous one can't?

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.