The Single-Phase H-Bridge Inverter: Square Wave and PWM
A DC-DC converter only ever pushes current one way. An inverter has to make the load voltage change sign: an alternating voltage for a UPS or a solar inverter, or a reversible voltage for a DC motor that must run both ways and brake. Four switches arranged like the letter H do it. Turning on one diagonal pair puts across the load, the other diagonal , and the two lower switches together . How you sequence the switches decides the quality of the output: a crude square wave with large low-order harmonics, or pulse-width modulation (PWM) whose harmonics sit near the switching frequency, where a little inductance removes them. This lesson builds the H-bridge, compares square-wave, bipolar and unipolar PWM by FFT, and drives a small DC motor with it in SPICE and in the netlist lab.
The circuit
Each leg (S1/S2, S3/S4) is a half-bridge switching cell (The Switching Cell). Its output node is tied to either rail, never both: S1 and S2 on together short the DC bus (shoot-through), so the drivers insert a dead time between them. During the dead time the antiparallel diodes carry the inductive load current. The inverter harmonics lesson works out what that does to the output voltage. The load voltage is , so the bridge can produce , and .
Three ways to switch
Square wave. S1+S4 for half a period, S2+S3 for the other half. The Fourier series of a square wave has only odd harmonics:
The amplitude can only be changed through , unless the two legs are phase-shifted by an angle: the quasi-square wave has zero-voltage notches of width , and . With the third harmonic disappears.
Bipolar sine-triangle PWM. A sinusoidal reference is compared with a triangle carrier of frequency . Where the reference is higher, S1+S4 conduct, otherwise S2+S3. The output is always , and in the linear range its fundamental is:
The harmonics form sidebands around , , …; the largest sits at and is of the order of itself ( peak at ).
Unipolar PWM. Leg A compares and leg B compares with the same carrier. The output steps in one half-cycle and in the other. The fundamental is the same , but the harmonics at cancel and the first sidebands sit around . The load sees twice the effective switching frequency with half the voltage step, so the ripple current is roughly a quarter. Above (overmodulation) the fundamental grows more slowly and low-order harmonics return, up to the square-wave limit .
Worked example
Given: , , load in series with , PWM with and (carrier , kept low so the harmonics are easy to see).
Find: the fundamental output voltage and current for square wave and PWM, and the current of the largest PWM harmonic, bipolar and unipolar.
Solve:
The code finds the bipolar harmonic at to be peak, so . The unipolar one at is , and gives .
Check: the voltage THD of PWM is worse than that of a square wave, but the current THD is much better. The inductance divides every harmonic by , and PWM has pushed the harmonics up in frequency. The current is what the load feels.
import numpy as np
Vdc, f1, mf, ma = 24.0, 50.0, 21, 0.8 # 21 carrier periods per fundamental period
R, L = 4.0, 20e-3 # RL load
N = mf * 2000 # samples in one fundamental period
t = np.arange(N) / (N * f1)
ref = ma * np.sin(2 * np.pi * f1 * t)
tri = 2 * np.abs(2 * ((mf * f1 * t + 0.25) % 1.0) - 1) - 1 # triangle carrier, -1..1
waves = {
"square": Vdc * np.sign(np.sin(2 * np.pi * f1 * t) + 1e-12),
"bipolar PWM": np.where(ref > tri, Vdc, -Vdc),
"unipolar PWM": Vdc * ((ref > tri).astype(float) - (-ref > tri).astype(float)),
}
def analyse(v):
V = np.abs(np.fft.rfft(v)) * 2 / N # peak amplitude of harmonic n (index n)
n = np.arange(len(V))
thd_v = np.sqrt(np.sum(V[2:] ** 2)) / V[1]
I = V[1:] / np.abs(R + 1j * 2 * np.pi * f1 * n[1:] * L)
thd_i = np.sqrt(np.sum(I[1:] ** 2)) / I[0]
big = [int(k) for k in np.argsort(V[2:])[::-1][:2] + 2]
return V, thd_v, thd_i, big
for name, v in waves.items():
V, thd_v, thd_i, big = analyse(v)
print(f"{name:13s} V1 = {V[1]:5.2f} V peak ({V[1]/np.sqrt(2):5.2f} V rms), "
f"THD_v = {100*thd_v:5.1f} %, THD_i = {100*thd_i:5.2f} %, "
f"largest n = {big[0]}, {big[1]} ({V[big[0]]:.1f}, {V[big[1]]:.1f} V)")
print(f"theory: square 4 Vdc/pi = {4*Vdc/np.pi:.2f} V, PWM ma Vdc = {ma*Vdc:.2f} V")square V1 = 30.56 V peak (21.61 V rms), THD_v = 48.3 %, THD_i = 14.08 %, largest n = 3, 5 (10.2, 6.1 V)
bipolar PWM V1 = 19.20 V peak (13.58 V rms), THD_v = 145.8 %, THD_i = 6.49 %, largest n = 21, 43 (19.6, 7.5 V)
unipolar PWM V1 = 19.20 V peak (13.58 V rms), THD_v = 76.7 %, THD_i = 1.79 %, largest n = 43, 41 (7.5, 7.5 V)
theory: square 4 Vdc/pi = 30.56 V, PWM ma Vdc = 19.20 V
Interactive: a DC motor on the H-bridge
The same bridge drives a DC motor. With bipolar PWM at duty cycle (fraction of the period with S1+S4 on), the mean voltage is , from to . At the motor sees zero mean voltage but the full ripple. The lab's netlist has no switches, so the bridge output is modelled as a PULSE source switching between and at with : an ideal bridge without dead time. The motor is its armature resistance , inductance and an back-EMF source standing for a constant speed (DC Motors). The mean voltage is , so the mean current is .
The current starts at zero and climbs with . By it swings between (at the start of each period) and (at the end of the on-time, ), a ripple of around the mean. Raise the back-EMF to (the motor speeds up until ) and the mean current falls to zero while the ripple stays.
Cross-check in ngspice: four switches and dead time
Now the real bridge: four switches with body diodes. Diagonal S1+S4 is on for , then of dead time, diagonal S2+S3 for , and another .
cat > hbridge.cir <<'EOF'
* H-bridge, bipolar PWM 20 kHz (D = 0.75), 24 V, DC motor: R 2 ohm, L 1 mH, back-EMF 8 V, 200 ns dead time
.model SW SW(Ron=0.03 Roff=1meg Vt=2.5 Vh=0)
.model DB D(Is=1n N=1.5 Rs=0.02 Cjo=200p)
VDC vdc 0 24
VG14 g14 0 PULSE(0 5 0 10n 10n 37.3u 50u)
VG23 g23 0 PULSE(0 5 37.5u 10n 10n 12.3u 50u)
S1 vdc a g14 0 SW
S4 b 0 g14 0 SW
S3 vdc b g23 0 SW
S2 a 0 g23 0 SW
D1 a vdc DB
D2 0 a DB
D3 b vdc DB
D4 0 b DB
RM a m 2
LM m e 1m
VEM e b 8
.control
tran 10n 6m 0 10n
let vab = v(a)-v(b)
meas tran vab_avg avg vab from=5m to=6m
meas tran i_avg avg i(LM) from=5m to=6m
meas tran i_pp pp i(LM) from=5.95m to=6m
let pin = -v(vdc)*i(VDC)
meas tran pin_avg avg pin from=5m to=6m
.endc
.end
EOF
ngspice -b hbridge.cir 2>&1 | grep -E '^(vab_avg|i_avg|i_pp|pin_avg) +='vab_avg = 1.169529e+01 from= 5.000000e-03 to= 6.000000e-03
i_avg = 1.847600e+00 from= 5.000000e-03 to= 6.000000e-03
i_pp = 4.548802e-01 from= 5.950000e-03 to= 6.000000e-03
pin_avg = 2.187339e+01 from= 5.000000e-03 to= 6.000000e-03
The mean bridge voltage is , not , and the current , not . During each dead time the positive motor current freewheels through D2 and D3, which puts across the motor for per period. Over a period that alone costs , and the switch and diode drops take the rest. The ripple, , is close to the lab's , within 4 %.
Guided lab: a small H-bridge and a DC motor
Hand calculation. For your motor's and (measure with the rotor held, with an LCR meter), the supply and the PWM frequency: for to and the current ripple .
Simulation. Enter your values in the netlist lab, and in the deck change the dead time to to see the mean voltage drop.
What you would measure. A MOSFET H-bridge module (or a motor-driver IC board) from a bench supply at , current limit at about the motor's rated current, a small brushed DC motor clamped to the bench, PWM from a microcontroller or function generator at . With a current probe (or a shunt and a differential measurement), expect a triangular ripple of the calculated size, within about 20 % because varies with rotor position and current. Sweep from 0.5 upward: the motor stays still at , then runs faster as rises. Below 0.5 it reverses.
Hazards and safe setup. At most , current-limited. Clamp the motor and keep fingers and loose clothing away from the shaft. Reversing a spinning motor (jumping from to ) briefly doubles the voltage across its armature and returns its kinetic energy to the supply, which a bench supply cannot absorb: the bus voltage rises. Ramp the duty cycle slowly, and put a large capacitor or a TVS across the bus. The MOSFETs and motor get hot. Bridges driving motors on the mains are calculation and simulation only.
Pitfalls
- Shoot-through. Two switches of one leg on together short the bus. Always use dead time and check it at the gate pins.
- Judging PWM by voltage THD. The current THD (or the load's response) is what matters.
- Forgetting the regenerative energy when a motor brakes. It flows back into the bus capacitor.
- Choosing even in bipolar PWM, or not synchronised to the fundamental at low : even harmonics and subharmonics appear. With in the hundreds this no longer matters.
Practice
- A square-wave H-bridge runs from . Find the rms fundamental and the peak 5th harmonic.
- Which quasi-square angle removes the 5th harmonic?
- Bipolar PWM at from : mean motor voltage?
Answer
- ; peak.
- at , so .
- : the motor runs in reverse.
Test yourself
What is the rms fundamental of a square wave?
In the linear range of sine-triangle PWM, the peak fundamental of the H-bridge output is…
- always
Compared with bipolar PWM at the same carrier frequency, unipolar PWM…
- has a larger fundamental
- moves the first harmonic cluster to about and halves the voltage steps, so the ripple current is much smaller
- needs only two switches
- eliminates the need for dead time
An H-bridge with bipolar PWM has . The motor's mean voltage is…
- zero, but with the full ripple current
Why does dead time lower the mean output voltage when the load current is positive (from a to b)?
- The gate driver consumes power
- During the dead time the current freewheels through the diodes that connect a to the negative rail and b to the positive rail, so
- The motor stops
- The capacitor discharges