---
title: "Motor controller: the H-bridge and PWM"
heading: Driving a DC motor in both directions from one supply with an H-bridge, pulse-width modulation as an adjustable average voltage, the winding's inductance smoothing the current, ripple against switching frequency and inductance, braking, dead time and the losses in the switches
eyebrow: D13 · Lesson 8 · Motor controller
xp: 40
---

::: hook
A motor controller has to deliver any voltage from full reverse to full forward, efficiently, from a single battery. Four transistors arranged as an **H-bridge** can connect each end of the motor to either supply rail, and switching them thousands of times a second with a chosen **duty cycle** produces any average voltage in between, the same trick as the buck converter (D2). The motor's own winding inductance smooths the current, so the motor sees a steady push while the transistors are only ever fully on or fully off, wasting little power.
:::

::: play
- One side of an H-bridge switching a motor winding (1 Ω, inductance L) between 0 and 24 V at 50% duty, against the motor's back-EMF E: a 12 V average.
- The current settles at (12 − E)/1 Ω on average, rising while the switch is on and falling while it's off. That sawtooth is the **ripple**, largest at 50% duty.
- Raise the switching frequency or the inductance and the ripple shrinks in proportion. Turn E up toward 12 V (the motor speeding up) and the average current falls toward zero.
:::

```sim circuit
V1 sw 0 square 0 24 20k Hz  @ 0,0 down
R1 sw a 1                   @ 0,0 right
L1 a b 1m                   @ 2,0 right
V2 b 0 10                   @ 4,0 down
slider: L1 100u..5m log
slider: V1.f 2k..50k log
slider: V2.amp 0..12
scope: v(sw), i(L1)
time: 0..8m s
meter: i(L1)
```

::: predict
## A 24 V bridge switches a 1 mH winding at 20 kHz and 50% duty. How big is the current's peak-to-peak ripple?

- [ ] 1.2 A
- [x] 0.3 A
- [ ] 0.6 A
- [ ] 0.03 A

::: reveal
During the on-time of 25 µs the winding sees 24 − 12 = 12 V (the 12 V average being what the back-EMF and resistance take), so the current rises by 12 V × 25 µs/1 mH = 0.3 A, then falls by the same amount during the off-time. In general the ripple is $VD(1 - D)/(Lf)$, largest at D = 0.5.
:::
:::

::: nameit
## The H-bridge

Four switches, two per side. Turning on the top left and bottom right drives current one way through the motor; the other diagonal drives it the other way. Turning on both bottom switches shorts the motor's terminals, which **brakes** it with its own back-EMF. Turning on both switches on one side shorts the supply: **shoot-through**, which a few hundred nanoseconds of **dead time** between one switch turning off and the other turning on prevents. The top switches need a gate voltage above the supply, usually from a bootstrap capacitor.

## PWM as an average

Switching one side at duty D between 0 and V, with the other side held low, gives an average $DV$, so the motor behaves as if driven by an adjustable DC supply. Switching above about 20 kHz keeps the whine out of the audible range.

## Ripple

The winding's inductance limits how fast the current can change. With the average voltage across the winding near zero in the steady state,

$$\Delta I_{pp} = \frac{VD(1 - D)}{Lf}$$

At most $V/(4Lf)$, at D = 0.5. Ripple heats the winding and the switches without making torque, so it sets the minimum switching frequency for a given motor.

## Losses

Each conducting switch dissipates $I^2R_{on}$, and two conduct at a time; each transition costs roughly $\frac{1}{2}VIt_{sw}$ in switching loss (S11). Higher switching frequency means less ripple but more switching loss.
:::

::: example
## What average current does the bridge above drive into a motor whose back-EMF is 10 V, and what do the switches dissipate if each has 20 mΩ on-resistance?

::: solution
1. **Average voltage across the winding.**
   $$24 \times 0.5 - 10 = 2\ \text{V}$$
2. **Current.**
   $$\frac{2\ \text{V}}{1\ \Omega} = 2\ \text{A}$$
3. **Switch loss.** Two switches conduct at a time:
   $$\begin{aligned} P &= 2 \times 2^2 \times 0.02 \\ &= 0.16\ \text{W} \end{aligned}$$
   plus switching losses.
4. **At full load, say 8 A.**
   $$\begin{aligned} P &= 2 \times 64 \times 0.02 \\ &= 2.6\ \text{W} \end{aligned}$$
   which needs some copper or a small heat sink.

**Answer:** 2 A, and the switches dissipate 0.16 W plus switching losses (2.6 W at 8 A).
:::
:::

::: example
## A motor has only 100 µH of winding inductance. What switching frequency keeps the ripple below 1 A peak to peak at 24 V?

::: solution
1. **Worst-case ripple.** It is $V/(4Lf)$, which must stay at or below 1 A:
   $$\begin{aligned} f &\ge \frac{24}{4 \times 100\ \mu\text{H} \times 1\ \text{A}} \\ &= 60\ \text{kHz} \end{aligned}$$
2. **Low-inductance motors.** Low-inductance motors, such as small coreless ones, need high switching frequencies or extra series inductance.

**Answer:** at least 60 kHz.
:::
:::

::: check
given: V = 12 | 24 | 48; D = 0.25 | 0.75 | 0.9; L = 0.5 | 1 | 2; f = 10 | 20 | 40
answer: V*D*(1 - D)/(L*1e-3*f*1e3)
unit: A
tolerance: 0.5%

## A {V} V bridge switches a {L} mH winding at {f} kHz and duty {D}. What's the peak-to-peak current ripple?

::: right
Right. $VD(1 - D)/(Lf)$ = {answer} A.
:::

::: misses
- [V*D/(L*1e-3*f*1e3)] The current rises only by the difference between the supply and the average voltage: include the (1 − D).
- [V/(4*L*1e-3*f*1e3)] That's the worst case, at 50% duty.
- [any] Not yet. Voltage across the winding during the on-time, times the on-time, over L.
:::
:::

::: check
given: D = 0.5 | 0.75 | 0.9; E = 6 | 10; R = 0.5 | 1 | 2
answer: (24*D - E)/R
unit: A
tolerance: 0.5%

## A 24 V bridge drives a motor at duty {D}. The motor's back-EMF is {E} V and its winding resistance {R} Ω. What's the average current?

::: right
Right. $(DV - E)/R$ = {answer} A.
:::

::: misses
- [(24 - E)/R] The bridge delivers $DV$ on average.
- [any] Not yet. Average voltage minus the back-EMF, over the resistance.
:::
:::

::: check
given: V = 12 | 24 | 48; L = 0.1 | 0.5 | 2; I = 0.5 | 1 | 2
answer: V/(4*L*1e-3*I)/1000
unit: kHz
tolerance: 0.5%

## A {V} V bridge drives a {L} mH winding. What's the lowest switching frequency that keeps the worst-case ripple within {I} A peak to peak?

::: right
Right. $f \ge V/(4L\Delta I)$ = {answer} kHz.
:::

::: misses
- [V/(L*1e-3*I)/1000] The worst case is at 50% duty, a quarter of $V/(Lf)$.
- [any] Not yet. Solve the worst-case ripple for f.
:::
:::

::: check
kind: parts
given: V = 12 | 24 | 48; D = 0.2 | 0.5 | 0.7; L = 0.5 | 1 | 4; f = 20 | 40

## An H-bridge switches {V} V at {f} kHz with duty {D} into a motor winding of {L} mH.

::: part
answer: V*D*(1 - D)/(L*1e-3*f*1e3)
unit: A
tolerance: 0.5%

### What is the peak-to-peak ripple current?

::: misses
- [V*D/(L*1e-3*f*1e3)] The back-EMF cancels part of the drive: include $(1 - D)$.
- [any] Not yet. $\Delta I = VD(1 - D)/(Lf)$.
:::
:::

::: part
answer: V*0.25/(L*1e-3*f*1e3)
unit: A
tolerance: 0.5%

### What is the largest ripple at any duty?

::: misses
- [V/(L*1e-3*f*1e3)] $D(1 - D)$ peaks at ¼.
- [any] Not yet. At $D$ = ½.
:::
:::

::: right
Right. Raising the PWM frequency or the inductance shrinks the ripple; switching losses rise with frequency.
:::
:::

::: check
given: I = 2 | 5 | 10; R = 10 | 30 | 100
answer: I^2*2*R*1e-3
unit: W
tolerance: 0.5%

## An H-bridge carries {I} A through two MOSFETs in series, each with {R} mΩ on-resistance. What conduction loss does that cause?

::: right
Right. $I^2 \times 2R_{on}$ = {answer}: the current always passes through two switches.
:::

::: misses
- [I^2*R*1e-3] The current flows through two switches, high side and low side.
- [any] Not yet. $I^2 \cdot 2R_{on}$.
:::
:::

::: check
given: td = 50 | 200 | 500; f = 10 | 20 | 50
answer: 2*td*1e-9*f*1e3*100
tolerance: 0.5%

## An H-bridge leg has {td} ns of dead time at each of its two transitions per period, at {f} kHz. During dead time the output follows the load current's diode instead of the command. Up to what percentage of the period is the duty in error?

::: right
Right. Two dead times per period: $2t_df$ = {answer}%. Drives compensate for it, especially at low output voltage where it matters most.
:::

::: misses
- [td*1e-9*f*1e3*100] There are two transitions, so two dead times, per period.
- [any] Not yet. $2t_d \times f$.
:::
:::

::: explain
## Why can a motor be driven by a voltage that's switching fully on and off, without jerking with every pulse?

::: model
The motor's winding has inductance, which resists changes in current, so when the bridge switches between the supply and zero the current only rises and falls slightly during each short pulse instead of following the voltage. Switching thousands of times a second makes the pulses far shorter than the winding's L/R time constant, so the current stays close to the value set by the average voltage, with a small ripple. The rotor responds to the torque from that current, and its inertia smooths it further, so it turns as if driven by a steady DC voltage equal to the duty cycle times the supply.
:::
:::

::: practice

::: check
given: V = 5 | 400; D = 0.1 | 0.6; L = 0.05 | 10; f = 5 | 100
answer: V*D*(1 - D)/(L*1e-3*f*1e3)
unit: A
tolerance: 0.5%

## Ripple: {V} V, D = {D}, {L} mH, {f} kHz?

::: misses
- [any] $VD(1 - D)/(Lf)$.
:::
:::

::: check
given: V = 6 | 600; L = 0.02 | 5; I = 0.1 | 5
answer: V/(4*L*1e-3*I)/1000
unit: kHz
tolerance: 0.5%

## Minimum frequency: {V} V, {L} mH, {I} A ripple?

::: misses
- [any] $V/(4L\Delta I)$.
:::
:::
:::
