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

D3 · Lesson 8 · Digital control

Controllers that run as code on a microcontroller, sampling and the zero-order hold, the half-sample delay a hold adds, PID written as a difference equation, mapping poles from s to z, and a sampled loop that goes unstable when its gain times its sample period exceeds two

Nearly every controller built today is a few lines of code in a loop: read the sensor through an ADC, compute the control law, write the result to a PWM or DAC, wait for the next tick. The continuous-time ideas of the earlier lessons carry over almost unchanged as long as the loop runs fast enough. When it doesn't, sampling shows up as a delay, and delay, as lesson 7 showed, eats phase margin. A sampled loop can go unstable at a gain the continuous design would have tolerated forever.

  • A sampled loop around an integrating plant (for example, a motor's speed driven by a current command), with proportional gain K and sample period T: y[k+1]=y[k]+KT(r−y[k]).
  • The closed-loop pole is at z=1−KT. For KT < 1 the output creeps up smoothly; KT = 1 reaches the setpoint in one sample (deadbeat); between 1 and 2 it overshoots and alternates; above 2 it diverges.
  • The continuous version of this loop is stable at any gain: the instability comes entirely from sampling.

Predict

A sampled proportional loop around an integrator runs every 10 ms. Above what gain K does it go unstable?

Name it

Sampling and the hold

The controller sees the measurement only every T seconds, and a zero-order hold (the DAC or PWM register) keeps each output constant until the next update. On average the hold delays the signal by half a sample, costing phase

Δϕ≈ωT2 rad

at frequency ω. A common rule is to sample 10 to 30 times faster than the closed-loop bandwidth, which keeps that loss at the crossover to a few degrees.

From s to z

A continuous pole at s maps to a discrete pole at z=esT. The left half of the s-plane maps inside the unit circle, so a discrete system is stable when every pole has |z| < 1 (C9's z-plane).

PID as code

Approximating the integral by a running sum and the derivative by a difference gives

u[k]=Kpe[k]+KiT∑i≤ke[i]+KdT(e[k]−e[k−1])

In practice the derivative is filtered, the integrator is clamped when the output saturates (anti-windup), and the loop runs from a timer interrupt so that T is steady (C12).

Worked example

A loop crosses over at 50 rad/s and is sampled every 2 ms. How much phase does the hold cost? Where does a continuous pole at s = −10 land?

Show the solution
  1. Phase cost of the hold. ωT/2=50×0.002/2=0.05rad or 2.9°, a small price.
  2. Mapping the pole. With T = 2 ms: z=e−10×0.002=0.980 close to 1, since the pole's time constant (100 ms) is fifty samples long.

Answer the hold costs 2.9° of phase, and the pole lands at z = 0.980.

Worked example

The integrator loop runs with K = 50 s⁻¹ and T = 10 ms. Where's its pole, and how does it respond to a step?

Show the solution
  1. The pole. KT=50×0.01=0.5 so z = 0.5.
  2. Step response. Each sample halves the remaining error. After four samples (40 ms) it has reached 1−0.54=94% of the step.

Answer the pole is at z = 0.5, and the output reaches 94% of the step after four samples (40 ms).

Worked example

Map a continuous pole at s = −100 with T = 10 ms, exactly and by the Tustin (bilinear) approximation.

Show the solution
  1. Exact mapping. z=esT=e−1=0.368
  2. Tustin. z=1+sT/21−sT/2=1−0.51+0.5=0.333
  3. Compare. The two agree for slow poles and drift apart as |s|T grows. Tustin keeps every stable pole inside the unit circle, which is why it's used to convert continuous designs.

Answer z = 0.368 exactly, and 0.333 by Tustin.

Check

A loop crosses over at 100 rad/s and is sampled every 0.5 ms. About how much phase does the zero-order hold cost at crossover?

Check

A continuous pole at s = −10 s⁻¹ is sampled every 1 ms. Where does it land in the z-plane?

Check

A sampled proportional loop around an integrator runs every 5 ms. Above what gain does it go unstable?

Check

A loop needs a closed-loop bandwidth of 20 Hz, and you want to sample 10 times faster than that. What sample rate do you need?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A continuous pole at s = −50 is sampled every 1 ms.

(a)

Where does it map exactly?

(b)

Where does Tustin put it?

Check

A loop crossing over at 50 rad/s is sampled every 1 ms.

(a)

How much phase does the zero-order hold cost?

(b)

How many times the crossover is the sample rate (in rad/s)?

Explain why

Why can sampling make a feedback loop unstable when the continuous version wasn't?

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.