What a loop is (and isn't)
Suppose you want a motor to spin at exactly 3,000 rpm. The open-loop way is to look up how much voltage usually gives 3,000 rpm, apply it, and hope. It works until the load changes, the magnets warm up, or the supply sags — and then the speed drifts and nothing notices.
The closed-loop way is to measure the actual speed, subtract it from 3,000 rpm, and let that difference — the error — decide the voltage. If the motor slows under load, the error grows and the controller automatically pushes harder. Nobody recomputed anything; the loop self-corrects.
Feedback turns "how well do you know the plant?" into "how fast can you measure and react?" — but the price is that an over-eager loop can chase its own tail and oscillate. Everything below is about buying speed without losing stability.
Anatomy of a real loop
Textbook loops have three blocks. Real loops have at least six, and the extra ones are where the trouble lives. The diagram below shows where the real world injects itself: a load disturbance d entering at the plant input (load torque, supply sag, a hill), and measurement noise n entering at the sensor (quantization, EMI, resolver ripple).
The vocabulary, in plain words
| Term | Plain meaning | In a motor drive |
|---|---|---|
| Setpoint r | What you want | Torque / current command from the driver's pedal |
| Error e | How wrong you currently are | i*q − iq,measured |
| Controller C | The recipe: error in, effort out | PI current regulator in the ISR |
| Actuator | The muscle (always limited) | Inverter — voltage clamps at the DC-link hexagon |
| Plant P | The physics you don't fully control | Stator R-L dynamics, back-EMF, mechanics |
| Sensor H | The eyes (delayed, noisy, quantized) | Current shunts + ADC, resolver/encoder |
| Bandwidth | How fast the loop can usefully respond | Current loop ≈ 1–3 kHz; speed loop ≈ 50–200 Hz |
The loop gain L(s) — one curve that decides everything
Walk once around the loop and multiply what you pass through: controller × plant × sensor. That product is the loop transfer function:
Almost every property of the closed loop can be read off the frequency response of this single curve. Loop engineering is often literally called loop shaping: you bend |L(jω)| into the right profile.
- Where |L| is large (low frequencies): the loop dominates the physics. Errors and disturbances are squashed by a factor of roughly |L|. You want lots of gain here — an integrator gives you infinite gain at DC, which is why steady-state error vanishes.
- Crossover frequency ωc (where |L| = 1, i.e., 0 dB): the speed of your loop. Rise time ≈ 1.5/ωc to 2/ωc. Pushing ωc up makes everything snappier.
- Where |L| is small (high frequencies): the loop gives up, on purpose. Sensor noise and unmodeled resonances live here; you want the loop deaf to them.
Margins: how close to the cliff you're standing
A loop goes unstable when the signal coming back around arrives as large as it left and exactly inverted — then the loop feeds itself. Margins measure your distance from that condition:
- Phase margin (PM): at crossover, how many degrees of extra phase lag you can absorb before the returning signal is fully inverted. Plain words: how much extra delay the loop can tolerate. Rules of thumb: PM > 60° = calm, 45° = brisk with mild overshoot, < 30° = ringing, 0° = oscillator.
- Gain margin (GM): how much you could multiply the gain before instability. Plain words: how much the plant gain can grow (hot magnets, light load, aging) before the loop sings. Aim for GM ≥ 2× (6 dB).
A pure time delay Td costs phase linearly with frequency: φ = −ω·Td (radians), with no change in gain. Every sample period, ADC conversion, PWM update, filter, and bus hop eats phase margin at your crossover. This is why "just filter the noise harder" so often destabilizes a loop: the filter's lag spends the phase budget you were living on.
Lab A — Crossover & margin explorer
Below is a classic loop: an integrator (for zero steady-state error) plus two lags (actuator + sensor dynamics): L(s) = K / [ s (0.5s+1)(0.1s+1) ]. Drag the gain. Watch the crossover slide right (faster loop), the phase margin shrink, and the step response start to ring. Around K ≈ 12 the gain margin hits 0 dB and the loop becomes a sine-wave generator.
One knob, three consequences
Speed and stability are the same knob viewed from two sides. K = 2 is calm but lazy; K = 7 is fast but rings; K = 12 oscillates forever. A loop engineer doesn't ask "what gain?" — they ask "what crossover frequency does the application need, and do I have the phase budget to afford it?"
Sensitivity & the waterbed effect
Two transfer functions summarize what the closed loop does to the outside world, and they are locked together:
- |S| small = disturbances rejected, modeling errors forgiven. You get this where |L| is large.
- |T| small = sensor noise ignored, unmodeled high-frequency dynamics not excited. You get this where |L| is small.
- Because S + T = 1 at every frequency, you can never have both small at once. You allocate frequencies: S small below crossover, T small above it.
Worse, for most real plants Bode's integral says the area of log|S| below 0 dB must be balanced by area above it: push the sensitivity down at low frequency and it pops up somewhere in the mid band — like pressing on a waterbed. That bump (peak of |S|, written Ms) is your fragility. Keeping Ms ≤ 1.6–2.0 is a standard, very practical robustness spec. Lab A plots |S| live so you can watch the bed squirm:
PID in plain words — and a sandbox to break it
Over 90% of industrial loops use PID or a subset of it. Each term answers a different question about the error:
| Term | Question it answers | Plain-words behavior | Too much of it |
|---|---|---|---|
| P — proportional | How wrong am I now? | Push in proportion to the error. The workhorse. | Ringing; never quite reaches target alone |
| I — integral | How wrong have I been lately? | Keep nudging while any error persists → zero steady-state error | Sluggish recovery, windup, slow oscillation |
| D — derivative | Which way is the error heading? | Brake early when approaching the target → damping | Amplifies sensor noise; chatters the actuator |
The lab below runs a live plant — two lags plus a transport delay, P(s) = 2·e^(−0.1s) / [(s+1)(0.3s+1)] — with a setpoint step at t = 0.5 s and a load disturbance kicking in at t = 8 s. Tune it. Then enable actuator saturation and watch integral windup ruin your day — and anti-windup fix it.
Tune the loop, then survive the disturbance
Experiments worth running
- Kill Ki (last preset): the output parks below the setpoint forever. Only the integrator can hold against a constant load with zero error.
- Aggressive preset + saturation ON + anti-windup OFF: the integrator keeps charging while the actuator is pinned; when the output finally arrives, the stored "debt" blows it far past the target. Flip anti-windup back on and compare. This single bug has bent real robot arms.
- Raise Kd slowly from 0 at high Kp: watch ringing die — derivative is damping. Then imagine each wiggle of u multiplied onto a noisy sensor; that's why D is always filtered, and often simply omitted in current loops.
Cascade loops — loops inside loops
Real systems rarely use one loop. They nest them: a fast inner loop tames the messy fast physics and presents a clean, simple "virtual plant" to a slower outer loop. The canonical example is field-oriented control of a PM machine:
- The separation rule: make each inner loop 5–10× faster (in bandwidth) than the loop wrapped around it. Then the outer loop can treat the inner one as a unity gain block, and you can tune them one at a time, inside-out.
- Why bother: the inner loop linearizes and protects. Current limiting lives in the inner loop, so the outer loop physically cannot overcurrent the machine no matter how badly it's tuned.
- Failure smell: if inner and outer bandwidths creep within ~3× of each other, they start fighting — you'll see beat-like oscillations that no single-loop retune fixes. Slow the outer loop or speed the inner one.
Practical notes from the trenches
- Sample fast enough, then stop. Rule of thumb: sample at 10–30× the intended closed-loop bandwidth. Each sample period costs ≈ ωc·Ts·(180/π)·1.5 degrees of phase (sampler + ZOH + compute latency). A 100 Hz loop at 1 kHz sampling has already spent ~27° of its budget before you wrote a line of control law.
- Know your delay budget. Add up: ADC conversion + ISR latency + PWM update (often 1.5 Ts total in digital drives) + filter group delays + any bus hops. If total delay × ωc > ~0.5 rad, the crossover you want is not affordable.
- Always implement anti-windup wherever an integrator can meet a limit — actuator saturation, rate limits, mode switches. Clamping (conditional integration) or back-calculation both work; shipping without either is a latent defect, not a tuning choice.
- Derivative on measurement, through a filter. Differentiating the error makes the controller kick on every setpoint step ("derivative kick"); differentiating the raw sensor amplifies noise by ω. Use d(−yf)/dt with a filter pole 5–10× above crossover.
- Bumpless everything. Manual→auto transfer, gain scheduling steps, and mode changes must initialize the integrator so u is continuous. Loops rarely die in steady state; they die at transitions.
- Identify before you tune. A 10-minute step or relay test that gives you gain, dominant time constant, and dead time beats an afternoon of knob-twiddling. SIMC/lambda tuning then gives near-optimal PI gains from those three numbers.
- Feedforward is free performance. Anything you can predict (commanded trajectory, measured load, back-EMF, cross-coupling ω·L·i in dq frames) should be fed forward; feedback then only cleans up the residual. Decoupling feedforward is why dq current loops can be tuned as two independent first-order plants.
- Filters are loop components. Every notch and low-pass you add to "clean the signal" is inside the loop and pays phase. Place sensor filters with the same care as controller poles — and re-check margins after.
- Respect the unstable-pole / RHP-zero speed limits. Non-minimum-phase zeros cap your achievable bandwidth (ωc ≲ z/2); unstable poles set a floor (ωc ≳ 2p). No tuning cleverness moves these walls — only redesigning the plant or sensing does.
- Log the loop, not just the output. Record r, y, u, and e together. Saturation, quantization, and windup are invisible in y alone but obvious in u.
A loop engineering workflow
The order matters. Most loop debugging pain comes from doing step 6 before steps 1–5.
References & further reading
- K. J. Åström & R. M. Murray, Feedback Systems: An Introduction for Scientists and Engineers, 2nd ed., Princeton University Press, 2021. Freely available online — the best plain-language treatment of loop shaping, sensitivity, and fundamental limits. fbswiki.org
- K. J. Åström & T. Hägglund, Advanced PID Control, ISA, 2006. The definitive practical PID reference: anti-windup, filtering, bumpless transfer, relay autotuning.
- S. Skogestad, "Simple analytic rules for model reduction and PID controller tuning" (SIMC), Journal of Process Control, 13(4), 2003. Three plant numbers in, near-optimal PI/PID gains out.
- S. Skogestad & I. Postlethwaite, Multivariable Feedback Control: Analysis and Design, 2nd ed., Wiley, 2005. Loop shaping, S/T trade-offs, and robustness done rigorously.
- G. F. Franklin, J. D. Powell & A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson, 2019. The standard undergraduate path: Bode design, margins, digital implementation.
- J. C. Doyle, B. A. Francis & A. R. Tannenbaum, Feedback Control Theory, Macmillan, 1992 (free online). Short, sharp treatment of S+T=1, Bode integrals, and why the waterbed cannot be drained.
- H. W. Bode, Network Analysis and Feedback Amplifier Design, Van Nostrand, 1945. Where gain/phase margins and the integral constraints were born — telephone amplifiers, not motors, but the same loops.
- R. D. Lorenz, T. A. Lipo & D. W. Novotny, "Motion control with induction motors," Proceedings of the IEEE, 82(8), 1994 — and any modern FOC text (e.g., Mohan, Advanced Electric Drives) for the cascade current/speed architecture of §07.
- G. Ellis, Control System Design Guide, 4th ed., Elsevier, 2012. The practitioner's bench book: delays, filters in the loop, resonance, and servo commissioning checklists.