The sampled control loop: ADC, computer, DAC
About this lesson
A real controller is a program running on a clock. Follow one tick of a computer-controlled motor: the ADC takes a snapshot of the speed and rounds it to a number, a few lines of Python decide a voltage, and the DAC holds that voltage flat until the next tick. Then let it run, write the exact tick-to-tick model of the motor, and see why the same rule that settles calmly at 10 ms rings at 80 ms and goes unstable beyond 102 ms.
A motor in a smooth world
Our plant is a small DC motor spinning at 1000 rpm, and we want 1500 rpm. Its speed changes smoothly at every instant. A tachometer, a speed sensor, turns it into a voltage: 1 V per 1000 rpm. A computer cannot read that directly.
plant DC motor, speed 1000 rpm now
goal 1500 rpm
sensor tachometer, 1 V per 1000 rpm
1000 rpm → 1.000 V
motor model 200 ms time constant,
100 rpm per volt when settled
The speed is an analog signal: it has a
value at every instant. A computer only
handles numbers, one at a time.Read the lesson step by step
A motor in a smooth world
Our plant is a small DC motor spinning at 1000 rpm, and we want 1500 rpm. Its speed changes smoothly at every instant. A tachometer, a speed sensor, turns it into a voltage: 1 V per 1000 rpm. A computer cannot read that directly.
plant DC motor, speed 1000 rpm now goal 1500 rpm sensor tachometer, 1 V per 1000 rpm 1000 rpm → 1.000 V motor model 200 ms time constant, 100 rpm per volt when settled The speed is an analog signal: it has a value at every instant. A computer only handles numbers, one at a time.A clock sets the beat
A clock ticks every T = 10 ms. T is the sample period; 100 ticks per second is the sample rate. Each tick starts one round of the loop. Between ticks the computer learns nothing new about the motor.
sample period T = 10 ms sample rate 1 / T = 100 per second tick k happens at t = k · T k = 0 t = 0 ms k = 1 t = 10 ms k = 2 t = 20 ms ... Every value the computer uses gets a tick number: speed[k], volts[k].ADC: snapshot and round
On a tick the ADC (analog-to-digital converter) takes a snapshot of the sensor voltage and rounds it down to one of 1024 levels (10 bits). One level is 2.93 rpm, so 1000 rpm becomes code 341.
ADC 10 bits = 2^10 = 1024 levels over 0 to 3 V one level = 3 V / 1024 = 2.93 mV = 2.93 rpm sample 1.000 V code floor(1.000 / 3 × 1024) = 341 Sampling picks the instants; quantising (rounding to a level) picks the value. Both lose a little.The computer runs the rule
The computer turns code 341 back into 999.0 rpm and finds the error, 501.0 rpm. Its rule: 15 V, enough to hold 1500 rpm, plus 0.04 V for every rpm of error. That asks for 35.04 V.
speed = 341 * 3000 / 1024 = 999.0 rpm error = 1500 - 999.0 = 501.0 rpm volts = 15 + 0.04 * 501.0 = 35.04 V 15 V feedforward: 1500 / 100 rpm per V 0.04 V per rpm of error (proportional) loop gain 100 × 0.04 = 4DAC: a number becomes volts
The computer writes the result to the DAC (digital-to-analog converter). A 12-bit DAC with its amplifier makes 0 to 48 V in 4096 steps, so it receives code 2990 and puts out 35.04 V to the motor.
DAC 12 bits = 4096 levels over 0 to 48 V one level = 11.7 mV code round(35.04 / 48 × 4096) = 2990 out 2990 × 11.72 mV = 35.04 V We assume the computing takes almost no time compared with T.Hold until the next tick
The DAC keeps 35.04 V perfectly flat for the whole 10 ms. Holding each value for one period is a zero-order hold. The motor speeds up on its own curve, reaching 1122 rpm. The computer is blind until the next tick.
zero-order hold (ZOH) volts(t) = volts[k] for kT ≤ t < (k+1)T during tick 0: volts held at 35.04 V the motor heads for 100 × 35.04 = 3504 rpm after 10 ms it is at 1122 rpm The voltage the motor sees is a staircase.Tick after tick
Sample, compute, hold, repeat. The steps of voltage shrink as the error shrinks. After 13 ticks (130 ms) the speed stays within 1% of 1500 rpm. The dots on the plot are the only speeds the computer ever saw.
import math TAU, K, T = 0.2, 100, 0.01 # s, rpm per V, s a = math.exp(-T / TAU) speed = 1000.0 for k in range(13): code = int(speed / 1000 / 3.0 * 1024) # ADC meas = code * 3000 / 1024 volts = 15 + 0.04 * (1500 - meas) volts = round(volts / 48 * 4096) * 48 / 4096 # DAC speed = K * volts + (speed - K * volts) * a # hold print(round(speed)) # 1488An exact model at the ticks
Because the voltage is flat between ticks, the motor can be solved exactly from tick to tick: speed[k+1] = a·speed[k] + (1 − a)·100·volts[k], with a = e^(−T/τ) = 0.951. τ, the motor's time constant, is 0.2 s. This is the ZOH equivalent.
motor τ · d(speed)/dt = 100 · volts − speed held volts solve over one period T: speed[k+1] = a · speed[k] + (1 − a) · 100 · volts[k] a = e^(−T/τ) = e^(−0.01/0.2) = 0.951 In state-space form A_d = e^(AT), B_d = A⁻¹(A_d − I)B. In python-control: control.sample_system(sys, 0.01, method="zoh")The loop as one number
Put the rule into that equation (ignore the rounding) and the error obeys error[k+1] = z·error[k], with z = a − 4(1 − a) = 0.756. Each tick keeps 75.6% of the error. |z| < 1 means the error dies away.
volts[k] = 15 + 0.04 · (1500 − speed[k]) error[k+1] = (a − 4(1 − a)) · error[k] = z · error[k] T = 10 ms a = 0.951 z = 0.756 z is the closed-loop pole in the z-plane. Inside the unit circle (|z| < 1): stable. Positive z: the error shrinks without changing sign.Sample too slowly
Same rule, but the clock ticks every 80 ms. Now a = 0.670 and z = −0.648: the error flips sign every tick. The 35 V held for 80 ms throws the speed to 1825 rpm, then the voltage drops to 1.99 V. It rings.
T = 80 ms a = 0.670 z = −0.648 negative z: the error changes sign every tick (overshoot, undershoot ...) |z| = 0.648: it still shrinks, slowly import math TAU, K, T = 0.2, 100, 0.08 # s, rpm per V, s a = math.exp(-T / TAU) speed = 1000.0 for k in range(1): code = int(speed / 1000 / 3.0 * 1024) # ADC meas = code * 3000 / 1024 volts = 15 + 0.04 * (1500 - meas) volts = round(volts / 48 * 4096) * 48 / 4096 # DAC speed = K * volts + (speed - K * volts) * a # hold print(round(speed)) # 1825How fast is fast enough?
z reaches −1 when T = τ·ln(5/3) = 102 ms; any slower and the loop is unstable. Run continuously, this rule could never ring. Sampling adds a delay, so tick several times faster than the loop responds: here 10 ms against 40 ms.
|z| < 1 ⇔ a − 4(1 − a) > −1 ⇔ a > 3/5 ⇔ T < τ · ln(5/3) = 102 ms continuous rule: pole s = −(1 + 4)/τ = −25 per second time constant 40 ms T = 10 ms z = 0.756 calm T = 80 ms z = −0.648 rings T > 102 ms |z| > 1 unstable
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A 10-bit ADC measures 0 to 3.0 V. The input is 1.500 V. Which code does it give, if it rounds down?
10 bits give 2^10 = 1024 levels, so the code is floor(1.500 / 3.0 × 1024) = floor(512) = 512. 1024 itself is out of range: the codes run from 0 to 1023.
02What does the zero-order hold do?
A zero-order hold holds each value for one whole sample period, so the plant sees a staircase. That flat stretch is what lets us solve the plant exactly from tick to tick.
03In this loop z = a − 4(1 − a), with a = e^(−T/τ) and τ = 0.2 s. z reaches −1 at a = 3/5. What is the slowest safe sample period T?
a − 4(1 − a) = −1 gives 5a = 3, so a = 3/5. Then e^(−T/0.2) = 0.6 gives T = 0.2 · ln(5/3) = 102 ms. Any longer and |z| > 1, so the loop is unstable; 80 ms is still stable but rings.
04With the 80 ms clock the closed-loop pole is z = −0.648. What does the speed do?
A negative z flips the sign of the error every tick, so the speed swings above and below the goal. Because |z| is less than 1, each swing is smaller than the last.
05The same proportional rule never rings when it runs continuously, but it can go unstable when sampled. Why?
The held voltage was decided from a snapshot up to one period old. If T is long compared with how fast the loop responds, the correction arrives late and overshoots; here the loop becomes unstable once T is longer than 102 ms.
Glossary
- Sample period (T)
- The time between two ticks of the controller's clock. Its inverse, 1/T, is the sample rate.
- ADC (analog-to-digital converter)
- Takes a snapshot of a voltage and turns it into a whole number (a code). An n-bit ADC has 2^n levels.
- Quantization
- Rounding a measured value to one of a fixed set of levels. Each level of our 10-bit ADC is 2.93 rpm wide.
- DAC (digital-to-analog converter)
- Turns a number back into a voltage.
- Zero-order hold (ZOH)
- Holding each output value constant for one whole sample period, so the plant sees a staircase.
- ZOH equivalent
- The exact discrete model of a continuous plant driven through a zero-order hold: A_d = e^(AT), B_d = A⁻¹(A_d − I)B.
- Closed-loop pole (z)
- The number that multiplies the error each tick in a first-order sampled loop. |z| < 1, inside the unit circle, means stable.
Notes and sources
- The motor is a first-order model with illustrative numbers: 100 rpm per volt when settled and a 200 ms time constant. Every curve and number in the figure is simulated tick by tick from that model, including the ADC's rounding down and the DAC's rounding.
- The Python on the steps is plain Python 3 with the math module. Between ticks it moves the motor with the exact solution of its equation, because the voltage is held constant, just as the figure does.
- Real loops also lose a little time computing between the snapshot and the new voltage, and usually put an anti-alias filter (a low-pass filter) before the ADC. Both add delay, which pushes the stability limit to even shorter sample periods. This lesson treats the computing time as zero.
- The z-plane and the unit circle come from the Signals lesson "The Z-transform and its region of convergence"; the ADC's levels from "Quantization and bit depth". "Discretising a controller: Euler versus Tustin" turns a continuous controller into code.
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 8, Digital control)
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley (DC motor model; digital control chapter)
- K. Ogata, Modern Control Engineering, 5th ed., Pearson (first-order models; state-space analysis)
- python-control: control.sample_system (method 'zoh' is the default)
- python-control: StateSpace.sample (zoh, bilinear/tustin, euler, backward_diff, gbt)
- SciPy: scipy.signal.cont2discrete (zero-order hold by default)
- Discretization of linear state-space models (ZOH: A_d = e^(AT), B_d = A⁻¹(A_d − I)B)
- Zero-order hold
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
Quiz Unlocks after the last step.