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

S9 · Lesson 48 · Digital control lab

Zero-order-hold discretization, the critical gain of a sampled loop with and without a computation delay, Tustin PI coefficients, prewarping and coefficient rounding

Lessons 41 and 42 described what sampling does to a loop: the hold's lag, the computation delay, the Tustin approximation, the trouble with poles near z = 1. In this lab you'll see each effect in numbers by building the pieces of a digital controller: discretize a plant exactly, find by simulation the gain at which a sampled loop goes unstable, write a PI law as a difference equation, design a filter corner that lands where it should after warping, and measure what rounding does to a slow pole.

  • The curves are the closed-loop pole magnitudes of a sampled first-order plant (Φ = 0.607, Γ = 0.787) under proportional control, against the gain Kp.
  • Without delay the pole is Φ−ΓKp, leaving the unit circle at Kp=(1+Φ)/Γ = 2.04.
  • With one sample of computation delay the poles solve z2−Φz+ΓKp=0; once complex, their magnitude is ΓKp, which reaches 1 at Kp=1/Γ = 1.27. One sample of delay costs 38% of the usable gain.

Predict

A PI controller (Kp = 1, Ti = 10 ms) is discretized by Tustin's method at T = 1 ms. With the error held at 1 from the first sample, what does it output at sample 4 (the fifth sample)?

Name it

What the lab computes

  • ZOH discretization of K0/(τs+1): Φ=e−T/τ, Γ=K0(1−Φ).
  • Critical gain of uk=Kp(r−yk) (no delay) or uk=Kp(r−yk−1) (one-sample delay): found by simulating the loop and bisecting on whether the response decays, then compared with (1+Φ)/Γ and 1/Γ.
  • Tustin PI: uk=uk−1+b0ek+b1ek−1 with b0=Kp(1+T/2Ti) and b1=−Kp(1−T/2Ti).
  • Prewarping: Tustin maps an analog frequency ωa to the digital ωd=2Ttan−1⁡ωaT2, so a digital corner fc needs an analog design at fa=fsπtan⁡πfcfs.
  • Rounding: a pole e−T/τ stored to B fractional bits becomes round(2Bz)/2B, with effective time constant −T/ln⁡zq.

Check

Write critical_gain(Phi, Gamma, delay): the gain at which the sampled loop with plant yk+1=Φyk+Γuk and proportional control (on yk, or on yk−1 when delay is True) becomes unstable, by bisection between 0 and 10 on whether |yk| after 2000 steps from y = 1 (zero reference) is below 1.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write tustin_pi(Kp, Ti, T) returning (b0,b1), and run_pi(b0, b1, errors) returning the outputs of uk=uk−1+b0ek+b1ek−1 from rest.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write prewarp(fc, fs): the analog corner that Tustin's method maps to fc at sample rate fs, and tustin_maps(fa, fs): the digital frequency an analog fa lands on.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write quantized_tau(tau, T, bits): round the pole e−T/τ to the nearest multiple of 2−bits and return the time constant it really represents.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a single sample of computation delay lower the gain at which a sampled loop goes unstable so much?