---
title: Cascade control
heading: Loops inside loops: why an inner loop helps, bandwidth separation and the outer loop's phase margin, tuning from the inside out, and the current, speed and position loops of a motor drive
eyebrow: S9 · Lesson 20 · Cascade control
xp: 50
---

::: hook
Almost every motor drive runs three loops, one inside another: a current loop that makes the motor's torque follow a command, a speed loop that commands the current, and a position loop that commands the speed. Process plants do the same with a flow loop under a temperature or level loop. A single loop from voltage to position could in principle do the job, so why nest them? Because each inner loop deals with its own disturbances and nonlinearities before the outer loop ever sees them, and gives the outer loop a simpler plant to control.
:::

::: play
- The curve is the outer loop's phase margin when it crosses over at $\omega_o$ around an integrating plant, with the inner closed loop acting as a lag of bandwidth $\omega_i$: $90° - \tan^{-1}(\omega_o/\omega_i)$.
- With the inner loop five times faster the outer loop keeps 78.7° of margin; at equal bandwidths only 45°.
- That's the reason for the usual rule: make each inner loop 4 to 10 times faster than the loop around it.
:::

```sim plot
view: graph
x: r = 0.5..20 log
y: P = 0..90
plot: 90 - atan(1/r)*180/pi | label: outer phase margin, degrees, against ωi/ωo
```

::: predict
## A servo drive's current loop has a 1 kHz bandwidth. About how fast can its speed loop sensibly be made?

- [ ] 1 kHz as well
- [x] 100 to 250 Hz
- [ ] 10 kHz
- [ ] 1 Hz

::: reveal
The speed loop sees the current loop as a lag; to keep that lag from eating its phase margin it should cross over 4 to 10 times lower, so 100 to 250 Hz. Typical drives run current loops at 1 to 3 kHz, speed loops at 100 to 300 Hz and position loops at 10 to 50 Hz: each a factor of several below the one inside it.
:::
:::

::: nameit
## The structure

An outer controller $C_o$ acts on the main variable's error and produces the setpoint of an inner loop, whose controller $C_i$ drives the actuator and measures an intermediate variable closer to it. The inner loop is designed first; the outer loop then treats the closed inner loop $T_i$ as part of its plant.

## What the inner loop buys

- **Disturbance rejection.** A disturbance entering inside the inner loop (a supply-voltage change in a motor's current loop, a pressure upset in a valve's flow loop) is attenuated by $S_i$ before it reaches the outer variable, and by $S_o$ after: at frequencies below the inner crossover, $|S_i| \approx \omega/\omega_i$.
- **Linearization.** Friction in a valve, or a motor's back-EMF in the current loop, is hidden by the inner loop's gain, so the outer loop sees $T_i \approx 1$ instead of the raw actuator.
- **Limits.** Clamping the inner setpoint limits the intermediate variable: a current limit protects a motor however hard the speed loop demands.

## Bandwidth separation

If the inner loop behaves like $T_i = 1/(s/\omega_i + 1)$ and the outer plant is an integrator, the outer loop $L_o = K/(s(s/\omega_i + 1))$ crossing over at $\omega_o$ has phase margin
$$\text{PM} = 90° - \tan^{-1}\frac{\omega_o}{\omega_i}$$
A ratio $\omega_i/\omega_o$ of 4 to 10 costs the outer loop only 6 to 14° and lets it be designed as if the inner loop were perfect.

## The motor drive

With torque constant $K_t$ and inertia J, the speed responds to current as $K_t/(Js)$, so a proportional speed gain $K_\omega$ (amperes per rad/s) crosses over at $\omega_s \approx K_\omega K_t/J$. A position loop with gain $K_p$ (rad/s of speed command per rad of error) crosses over at about $K_p$, and while following a ramp at speed v it lags by $v/K_p$, which velocity feedforward (lesson 19) removes.
:::

::: example
## A servo motor has $K_t$ = 0.05 N·m/A and J = 10⁻⁴ kg·m², under a current loop with 1 kHz bandwidth. Set a proportional speed gain for a 100 Hz crossover, and find the speed loop's phase margin.

::: solution
1. **Speed plant.**
   $$\frac{K_t}{Js} = \frac{500}{s}$$
2. **Gain for a 100 Hz crossover.**
   $$\begin{aligned} \omega_c &= 2\pi \times 100 \\ &= 628\ \text{rad/s} \\ K_\omega &= 628/500 \\ &= 1.26\ \text{A per rad/s} \end{aligned}$$
   It's 1.263 exactly, once the current loop's small lag is included.
3. **Phase margin.**
   $$\begin{aligned} \text{PM} &= 90° - \tan^{-1}(100/1000) \\ &= 84.3° \end{aligned}$$
   The current loop is fast enough to be almost invisible to the speed loop.

**Answer:** $K_\omega$ = 1.26 A per rad/s (1.263 with the current loop's lag), with an 84.3° phase margin.
:::
:::

::: example
## A temperature loop crosses over at 0.01 rad/s around a heat exchanger, and the steam valve gets its own flow loop crossing at 1 rad/s. How much does the flow loop attenuate a steam-pressure upset, compared with the temperature loop alone?

::: solution
1. **The flow loop's sensitivity.** Below the outer crossover,
   $$|S_i| = \frac{\omega}{\sqrt{\omega^2 + \omega_i^2}}$$
2. **At 0.01 rad/s.**
   $$|S_i| \approx 0.01$$
   That's 40 dB of extra attenuation, on top of whatever the temperature loop provides.
3. **What that means.** The upset is corrected in a few seconds at the valve, long before the slow exchanger shows it; without the flow loop the temperature loop would only react after the exchanger's lag let the upset through.

**Answer:** the flow loop adds about 40 dB of attenuation at 0.01 rad/s, on top of the temperature loop's.
:::
:::

::: example
## A position loop with gain $K_p$ = 2π × 10 s⁻¹ commands that speed loop. How far behind does it fall when the target moves at 100 rad/s?

::: solution
1. **Loop type.** A proportional position loop around the (nearly ideal) speed loop is type 1, with velocity constant
   $$K_p = 62.8\ \text{s}^{-1}$$
2. **Following error.**
   $$\begin{aligned} e &= v/K_p \\ &= 100/62.8 \\ &= 1.59\ \text{rad} \end{aligned}$$
   a quarter of a turn.
3. **Remove it with feedforward.** Feeding the target's speed forward to the speed loop's setpoint removes almost all of it, leaving the position loop to correct only what the speed loop misses.

**Answer:** it falls 1.59 rad behind, a quarter of a turn.
:::
:::

::: check
kind: parts
given: K = 0.02 | 0.05 | 0.2; J = 1e-5 | 1e-4 | 1e-3; f = 50 | 100 | 300

## A motor with $K_t$ = {K} N·m/A and J = {J} kg·m² has a fast current loop; its speed loop should cross over at {f} Hz.

::: part
answer: 2*pi*f*J/K
unit: A/(rad/s)
tolerance: 0.5%

### What proportional speed gain, in amperes per rad/s, does that need, ignoring the current loop's lag?

::: misses
- [f*J/K] Use ω = 2πf.
- [any] $K_\omega = \omega_sJ/K_t$.
:::
:::
:::

::: check
kind: parts
given: r = 2 | 4 | 8 | 15

## An outer loop around an integrating plant crosses over {r} times below the bandwidth of the first-order inner loop it commands.

::: part
answer: 90 - atan(1/r)*180/pi
unit: °
tolerance: 0.5%

### What phase margin does it have?

::: misses
- [90 - atan(r)*180/pi] The lag's phase at $\omega_o$ is $\tan^{-1}(\omega_o/\omega_i) = \tan^{-1}(1/r)$.
- [any] $90° - \tan^{-1}(\omega_o/\omega_i)$.
:::
:::

::: part
answer: atan(1/r)*180/pi
unit: °
tolerance: 0.5%

### How much margin does the inner loop's lag cost?

::: misses
- [any] $\tan^{-1}(1/r)$.
:::
:::
:::

::: check
kind: parts
given: P = 60 | 70 | 80; w = 10 | 100 | 600

## An outer loop must cross over at {w} rad/s around an integrating plant with at least {P}° of phase margin.

::: part
answer: w/tan((90 - P)*pi/180)
unit: rad/s
tolerance: 0.5%

### How fast must the inner loop be?

::: misses
- [any] Solve $90° - \tan^{-1}(\omega_o/\omega_i) = \text{PM}$.
:::
:::
:::

::: check
kind: parts
given: o = 0.01 | 0.1 | 1; r = 10 | 30 | 100

## An inner loop crosses over {r} times faster than the outer loop's {o} rad/s crossover.

::: part
answer: 20*log(1/sqrt(1 + r^2))
unit: dB
tolerance: 0.5%

### How much does the inner loop attenuate a disturbance entering it, at the outer crossover?

::: misses
- [any] $|S_i| = \omega_o/\sqrt{\omega_o^2 + \omega_i^2}$.
:::
:::
:::

::: check
kind: parts
given: f = 2 | 10 | 30; v = 10 | 100 | 500

## A proportional position loop crosses over at {f} Hz around a fast speed loop, following a target moving at {v} rad/s.

::: part
answer: v/(2*pi*f)
unit: rad
tolerance: 0.5%

### What is the following error?

::: misses
- [v/f] The gain is $2\pi f$ in s⁻¹.
- [any] $v/K_p$.
:::
:::
:::

::: check
kind: parts
given: K = 0.03 | 0.1; J = 1e-4 | 1e-3; I = 2 | 10; w = 100 | 500

## A speed loop's current command is clamped at {I} A; the motor has $K_t$ = {K} N·m/A and J = {J} kg·m², and is commanded from rest to {w} rad/s.

::: part
answer: K*I/J
unit: rad/s^2
tolerance: 0.5%

### What is the largest acceleration?

::: misses
- [any] $K_tI_\max/J$.
:::
:::

::: part
answer: w*J/(K*I)*1000
unit: ms
tolerance: 0.5%

### How long does the speed take to get there at least?

::: misses
- [any] Speed change over maximum acceleration.
:::
:::
:::

::: check
kind: choice

## Why are cascade loops tuned from the inside out?

- [ ] The inner loop is always the slowest
- [x] The outer loop's plant includes the closed inner loop, so the inner loop's dynamics must be fixed before the outer controller can be designed around them; retuning the inner loop later changes the outer loop's plant
- [ ] The outer loop has no effect on the inner one
- [ ] Inner loops never saturate

::: misses
- [1] It's the fastest.
- [3] The outer loop sets the inner setpoint, but the inner loop's dynamics don't depend on the outer controller.
- [4] Inner loops are often where limits are applied.
:::
:::

::: check
kind: derivation
vars: o = 0.01..1000, r = 2..50, K = 0.01..1, J = 0.00001..0.01

## An outer loop crosses over at o around an integrating plant; the inner loop is r times faster; separately, a motor has $K_t$ = K and inertia J.

::: step
answer: 90 - atan(1/r)*180/pi

### What phase margin does the outer loop have, in degrees?
:::

::: step
answer: o/sqrt(o^2 + (r*o)^2)

### What is the inner loop's |S| at the outer crossover?
:::

::: step
answer: o*J/K

### What speed gain makes the motor's speed loop cross over at o?
:::

::: right
Right. A fast inner loop costs the outer loop little phase and buys it a large reduction of inner disturbances.
:::
:::

::: check
kind: python

## Write `speed_overshoot(K, Kt, J, wi, T, dt)`: simulate a unit speed step for a motor ($\dot\omega = K_ti/J$) whose current follows its command through a first-order loop ($\dot i = \omega_i(i_\text{ref} - i)$), with proportional speed control $i_\text{ref} = K(1 - \omega)$; forward Euler, return the overshoot as a fraction.

```python starter
def speed_overshoot(K, Kt, J, wi, T, dt):
    return 0.0
```

```python solution
def speed_overshoot(K, Kt, J, wi, T, dt):
    w = i = 0.0
    peak = 0.0
    for _ in range(int(T / dt)):
        iref = K * (1.0 - w)
        i, w = i + dt * wi * (iref - i), w + dt * Kt * i / J
        peak = max(peak, w)
    return peak - 1.0
```

```python tests
import math
Kt, J = 0.05, 1e-4
for ratio in (1.0, 2.0):
    wo = 2 * math.pi * 100
    wi = ratio * wo
    K = wo * J / Kt
    zeta = 0.5 * math.sqrt(wi / (K * Kt / J))
    want = math.exp(-math.pi * zeta / math.sqrt(1 - zeta * zeta))
    assert abs(speed_overshoot(K, Kt, J, wi, 0.05, 1e-6) - want) < 2e-3, f"Inner loop {ratio} times faster: overshoot {want:.3f}."
```

::: right
Right. The two loops together form a second-order system with $\zeta = \frac12\sqrt{\omega_i/\omega_o}$: an inner loop only as fast as the outer one leaves ζ = 0.5.
:::
:::

::: explain
## What does a cascade structure gain over a single loop from the actuator straight to the main variable?

::: model
The inner loop measures a variable close to the actuator, so it can correct disturbances that enter there, such as supply variations or pressure upsets, quickly and before they spread through the slower part of the plant. Its high gain also hides the actuator's nonlinearities and gives the outer loop a simple, nearly ideal plant. Limits placed on the inner setpoint protect the equipment, like a current limit on a motor. The price is that the inner loop must be several times faster than the outer one, so the outer loop's bandwidth is capped by how fast the inner loop can be made, and both loops have to be tuned in order.
:::
:::

::: practice
::: check
given: K = 0.05 | 0.1; J = 1e-4 | 5e-4; f = 50 | 200
answer: 2*pi*f*J/K
tolerance: 0.5%

## Speed gain for {f} Hz, $K_t$ = {K}, J = {J}?

::: misses
- [any] $2\pi fJ/K_t$.
:::
:::

::: check
given: r = 3 | 6 | 12
answer: 90 - atan(1/r)*180/pi
unit: °
tolerance: 0.5%

## Outer phase margin with the inner loop {r} times faster?

::: misses
- [any] $90° - \tan^{-1}(1/r)$.
:::
:::

::: check
given: f = 5 | 20; v = 50 | 300
answer: v/(2*pi*f)
unit: rad
tolerance: 0.5%

## Following error at {v} rad/s with a {f} Hz position loop?

::: misses
- [any] $v/(2\pi f)$.
:::
:::
:::
