TExcelTAD
Home › Power Electronics & Motor Drives › The Single-Phase H-Bridge Inverter: Square Wave and PWM

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 +Vdc+V_{dc} across the load, the other diagonal −Vdc-V_{dc}, and the two lower switches together 00. 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

+ Vdc24 V S1S2 S3S4 ab R 4 Ohm L 20 mH i +-vab every switch has an antiparallel (body) diode; never S1 with S2, or S3 with S4

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 vab=va−vbv_{ab} = v_a - v_b, so the bridge can produce +Vdc+V_{dc}, 00 and −Vdc-V_{dc}.

Three ways to switch

Square wave. S1+S4 for half a period, S2+S3 for the other half. The Fourier series of a ±Vdc\pm V_{dc} square wave has only odd harmonics:

vab(t)=∑n=1,3,5,…4Vdcnπsin⁡(nωt),V1,rms=22πVdc=0.900 Vdc,THD=48.3 %v_{ab}(t) = \sum_{n = 1,3,5,\dots} \frac{4V_{dc}}{n\pi} \sin(n\omega t), \qquad V_{1,\text{rms}} = \frac{2\sqrt{2}}{\pi} V_{dc} = 0.900\,V_{dc}, \qquad \text{THD} = 48.3\ \%

The amplitude can only be changed through VdcV_{dc}, unless the two legs are phase-shifted by an angle: the quasi-square wave has zero-voltage notches of width 2α2\alpha, and Vn=4Vdcnπcos⁡(nα)V_n = \frac{4V_{dc}}{n\pi}\cos(n\alpha). With α=30∘\alpha = 30^\circ the third harmonic disappears.

Bipolar sine-triangle PWM. A sinusoidal reference masin⁡ωtm_a \sin\omega t is compared with a triangle carrier of frequency fc=mff1f_c = m_f f_1. Where the reference is higher, S1+S4 conduct, otherwise S2+S3. The output is always ±Vdc\pm V_{dc}, and in the linear range ma≤1m_a \le 1 its fundamental is:

V1,peak=maVdcV_{1,\text{peak}} = m_a V_{dc}

The harmonics form sidebands around mfm_f, 2mf2m_f, …; the largest sits at n=mfn = m_f and is of the order of VdcV_{dc} itself (0.82 Vdc0.82\,V_{dc} peak at ma=0.8m_a = 0.8).

Unipolar PWM. Leg A compares +masin⁡ωt+m_a \sin\omega t and leg B compares −masin⁡ωt-m_a \sin\omega t with the same carrier. The output steps 0↔+Vdc0 \leftrightarrow +V_{dc} in one half-cycle and 0↔−Vdc0 \leftrightarrow -V_{dc} in the other. The fundamental is the same maVdcm_a V_{dc}, but the harmonics at mfm_f cancel and the first sidebands sit around 2mf2m_f. The load sees twice the effective switching frequency with half the voltage step, so the ripple current is roughly a quarter. Above ma=1m_a = 1 (overmodulation) the fundamental grows more slowly and low-order harmonics return, up to the square-wave limit 4Vdc/π4V_{dc}/\pi.

Worked example

Given: Vdc=24 VV_{dc} = 24\ \text{V}, f1=50 Hzf_1 = 50\ \text{Hz}, load R=4 ΩR = 4\ \Omega in series with L=20 mHL = 20\ \text{mH}, PWM with ma=0.8m_a = 0.8 and mf=21m_f = 21 (carrier 1.05 kHz1.05\ \text{kHz}, 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:

square: V1=4⋅24 Vπ=30.56 V peak=21.61 V rmsPWM: V1=0.8⋅24 V=19.20 V peak=13.58 V rms∣Z1∣=∣4+j 2π⋅50⋅0.02∣ Ω=7.448 Ω,I1=13.58 V7.448 Ω=1.823 A rms∣Z21∣=∣4+j 131.9∣ Ω=132.0 Ω\begin{aligned} \text{square: } V_1 &= \frac{4 \cdot 24\ \text{V}}{\pi} = 30.56\ \text{V peak} = 21.61\ \text{V rms} \\ \text{PWM: } V_1 &= 0.8 \cdot 24\ \text{V} = 19.20\ \text{V peak} = 13.58\ \text{V rms} \\ \lvert Z_1 \rvert &= \lvert 4 + j\,2\pi \cdot 50 \cdot 0.02 \rvert\ \Omega = 7.448\ \Omega, \qquad I_1 = \frac{13.58\ \text{V}}{7.448\ \Omega} = 1.823\ \text{A rms} \\ \lvert Z_{21} \rvert &= \lvert 4 + j\,131.9 \rvert\ \Omega = 132.0\ \Omega \end{aligned}

The code finds the bipolar harmonic at n=21n = 21 to be 19.6 V19.6\ \text{V} peak, so I21=19.6/(2⋅132.0)=0.105 A rmsI_{21} = 19.6/(\sqrt{2} \cdot 132.0) = 0.105\ \text{A rms}. The unipolar one at n=43n = 43 is 7.5 V7.5\ \text{V}, and ∣Z43∣=270.2 Ω\lvert Z_{43} \rvert = 270.2\ \Omega gives 0.020 A rms0.020\ \text{A rms}.

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 nωLn\omega L, and PWM has pushed the harmonics up in frequency. The current is what the load feels.

python · try it yourself
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 DD (fraction of the period with S1+S4 on), the mean voltage is vˉab=(2D−1)Vdc\bar v_{ab} = (2D - 1)V_{dc}, from −Vdc-V_{dc} to +Vdc+V_{dc}. At D=0.5D = 0.5 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 −24-24 and +24 V+24\ \text{V} at 20 kHz20\ \text{kHz} with D=0.75D = 0.75: an ideal bridge without dead time. The motor is its armature resistance 2 Ω2\ \Omega, inductance 1 mH1\ \text{mH} and an 8 V8\ \text{V} back-EMF source standing for a constant speed (DC Motors). The mean voltage is 12 V12\ \text{V}, so the mean current is (12−8)/2=2 A(12 - 8)/2 = 2\ \text{A}.

012012345t (ms)AI(LM)at t = 4.987 msV(a)24.0 VV(m)19.6 VV(e)8.00 VI(V1)-2.22 AI(RM)2.22 AI(LM)2.22 AI(VE)2.22 A

The current starts at zero and climbs with τ=L/R=0.5 ms\tau = L/R = 0.5\ \text{ms}. By 5 ms5\ \text{ms} it swings between 1.782 A1.782\ \text{A} (at the start of each period) and 2.220 A2.220\ \text{A} (at the end of the on-time, 4.9875 ms4.9875\ \text{ms}), a ripple of 0.438 A0.438\ \text{A} around the 2 A2\ \text{A} mean. Raise the back-EMF to 12 V12\ \text{V} (the motor speeds up until E=vˉabE = \bar v_{ab}) 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 30 mΩ30\ \text{m}\Omega switches with body diodes. Diagonal S1+S4 is on for 37.3 μs37.3\ \mu\text{s}, then 200 ns200\ \text{ns} of dead time, diagonal S2+S3 for 12.3 μs12.3\ \mu\text{s}, and another 200 ns200\ \text{ns}.

bash · try it yourself
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 11.70 V11.70\ \text{V}, not 1212, and the current 1.85 A1.85\ \text{A}, not 22. During each dead time the positive motor current freewheels through D2 and D3, which puts −Vdc-V_{dc} across the motor for 400 ns400\ \text{ns} per period. Over a 50 μs50\ \mu\text{s} period that alone costs 24 V⋅0.4/50≈0.19 V24\ \text{V} \cdot 0.4/50 \approx 0.19\ \text{V}, and the switch and diode drops take the rest. The ripple, 0.455 A0.455\ \text{A}, is close to the lab's 0.438 A0.438\ \text{A}, within 4 %.

Guided lab: a small H-bridge and a DC motor

Hand calculation. For your motor's RR and LL (measure RR with the rotor held, LL with an LCR meter), the supply and the PWM frequency: vˉab\bar v_{ab} for D=0.5D = 0.5 to 0.90.9 and the current ripple ΔI≈(Vdc−vˉab) D/(Lfsw)\Delta I \approx (V_{dc} - \bar v_{ab})\, D/(L f_{sw}).

Simulation. Enter your values in the netlist lab, and in the deck change the dead time to 1 μs1\ \mu\text{s} 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 12 V12\ \text{V}, current limit at about the motor's rated current, a small brushed 12 V12\ \text{V} DC motor clamped to the bench, PWM from a microcontroller or function generator at 20 kHz20\ \text{kHz}. With a current probe (or a 0.1 Ω0.1\ \Omega shunt and a differential measurement), expect a triangular ripple of the calculated size, within about 20 % because LL varies with rotor position and current. Sweep DD from 0.5 upward: the motor stays still at D=0.5D = 0.5, then runs faster as DD rises. Below 0.5 it reverses.

Hazards and safe setup. At most 24 V24\ \text{V}, current-limited. Clamp the motor and keep fingers and loose clothing away from the shaft. Reversing a spinning motor (jumping from D=0.9D = 0.9 to 0.10.1) 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 mfm_f even in bipolar PWM, or not synchronised to the fundamental at low mfm_f: even harmonics and subharmonics appear. With mfm_f in the hundreds this no longer matters.

Practice

  1. A square-wave H-bridge runs from 48 V48\ \text{V}. Find the rms fundamental and the peak 5th harmonic.
  2. Which quasi-square angle α\alpha removes the 5th harmonic?
  3. Bipolar PWM at D=0.3D = 0.3 from 24 V24\ \text{V}: mean motor voltage?
Answer
  1. V1=0.900⋅48=43.2 V rmsV_1 = 0.900 \cdot 48 = 43.2\ \text{V rms}; V5=4⋅48/(5π)=12.2 VV_5 = 4 \cdot 48/(5\pi) = 12.2\ \text{V} peak.
  2. cos⁡(5α)=0\cos(5\alpha) = 0 at 5α=90∘5\alpha = 90^\circ, so α=18∘\alpha = 18^\circ.
  3. (2⋅0.3−1)⋅24=−9.6 V(2 \cdot 0.3 - 1) \cdot 24 = -9.6\ \text{V}: the motor runs in reverse.

Test yourself

What is the rms fundamental of a ±Vdc\pm V_{dc} square wave?

  1. VdcV_{dc}
  2. 0.707 Vdc0.707\,V_{dc}
  3. 0.900 Vdc0.900\,V_{dc}
  4. 1.273 Vdc1.273\,V_{dc}

In the linear range of sine-triangle PWM, the peak fundamental of the H-bridge output is…

  1. mfVdcm_f V_{dc}
  2. maVdcm_a V_{dc}
  3. Vdc/maV_{dc}/m_a
  4. 4Vdc/π4V_{dc}/\pi always

Compared with bipolar PWM at the same carrier frequency, unipolar PWM…

  1. has a larger fundamental
  2. moves the first harmonic cluster to about 2mf2m_f and halves the voltage steps, so the ripple current is much smaller
  3. needs only two switches
  4. eliminates the need for dead time

An H-bridge with bipolar PWM has D=0.5D = 0.5. The motor's mean voltage is…

  1. Vdc/2V_{dc}/2
  2. zero, but with the full ripple current
  3. VdcV_{dc}
  4. −Vdc-V_{dc}

Why does dead time lower the mean output voltage when the load current is positive (from a to b)?

  1. The gate driver consumes power
  2. During the dead time the current freewheels through the diodes that connect a to the negative rail and b to the positive rail, so vab=−Vdcv_{ab} = -V_{dc}
  3. The motor stops
  4. The capacitor discharges