Motor Drivers: H-Bridges, PWM & Current Control
Power electronics that make motors move. Learn transistor switches (MOSFET, IGBT), the H-bridge and its switching states, PWM (unipolar vs bipolar), average voltage and current ripple, dead-time and shoot-through, freewheeling and braking, current sensing and current-loop control, stepper drivers and microstepping, three-phase BLDC inverters and commutation, losses and thermal design, and protection — with Python for PWM voltage, ripple and losses.
Microcontrollers output milliamps at 3.3 V; motors need amps at 12–600 V in both directions. Motor drivers bridge the gap: transistor switches controlled by pulse-width modulation (PWM) deliver an adjustable average voltage very efficiently, and current sensing closes the fastest control loop in the system.
Understanding the H-bridge and PWM is essential for every mechatronic engineer — from a hobby robot using an L298/DRV8871 to an industrial servo drive with IGBTs.
An analogy
PWM is like controlling a room's brightness by flicking a light switch very fast: on half the time gives half brightness on average. The motor's inductance smooths the current just as your eye averages the flicker.
The H-bridge
Four switches arranged like an 'H' around the motor. Turning on the top-left and bottom-right drives current one way (forward); top-right and bottom-left reverse it. Both low switches on short the motor (dynamic brake); all off lets it coast. Both switches in one leg on at once short the supply (shoot-through) — the worst failure, prevented by dead-time and gate-driver interlocks.
PWM strategies
Sign-magnitude (unipolar) PWM switches one leg with a direction bit — lower ripple and loss. Locked anti-phase (bipolar) PWM switches both legs complementarily — simple, smooth through zero, but higher ripple. PWM frequency trades switching loss against current ripple and audible noise; 16–25 kHz is typical for small motors, 4–16 kHz for large IGBT drives.
Current sensing and control
Shunt resistors (low-side or inline with an amplifier), Hall-effect sensors or MOSFET R_DS sensing measure current. A current (torque) loop with PI control and bandwidth of 1–5 kHz makes the motor behave as a torque source, protects against overcurrent and simplifies outer speed/position loops. Stepper drivers use chopper current regulation and microstepping (sine/cosine phase currents) for smooth motion.
Three-phase inverters, losses and protection
BLDC motors use a three-phase bridge: six-step (trapezoidal) commutation from Hall sensors, or sinusoidal/field-oriented control (FOC) with space-vector PWM from an encoder or sensorless observer. Design considerations: conduction and switching losses, heatsinking (T_j = T_a + P·R_th), bootstrap gate supplies, dead-time distortion compensation, overcurrent/overvoltage/thermal protection, regenerative braking energy (brake chopper), and EMC (snubbers, layout, shielded cables).
Formulas
- Unipolar/sign-magnitude PWM:
V_avg = D·V_bus - Bipolar (locked anti-phase) PWM:
V_avg = (2D − 1)·V_bus - Current ripple (unipolar approx.):
ΔI ≈ (V_bus − V_avg)·D / (f_PWM·L) - Conduction loss:
P_cond = I²·R_DS(on) (per conducting switch) - Switching loss:
P_sw ≈ ½·V·I·(t_on + t_off)·f_PWM - Gate-drive power:
P_gate = Q_g·V_gs·f_PWM (per switch)
Worked example: Average voltage
Given: 24 V bus, D = 0.6 (unipolar)
Find: V_avg.
- 0.6 × 24
Answer: 14.4 V
Worked example: Junction temperature
Given: MOSFET loss 1.5 W, R_th(j-a) 40 °C/W, ambient 40 °C
Find: T_j.
- 40 + 1.5 × 40
Answer: 100 °C (below 150 °C max, OK)
Worked example: Shunt sizing
Given: Max current 10 A, ADC range 3.3 V with gain 20
Find: Shunt resistance.
- V_shunt max = 3.3/20 = 0.165 V
- R = 0.165/10
Answer: 16.5 mΩ → use 15 mΩ (1.5 W peak)
PWM voltage, current ripple and MOSFET losses
# PWM H-bridge motor driver: average voltage, current ripple, MOSFET losses
Vbus, duty, f = 24.0, 0.60, 20e3
R, L, back_emf = 1.2, 1.5e-3, 10.0
V_avg = Vbus * (2 * duty - 1) # bipolar PWM
V_uni = Vbus * duty # unipolar / sign-magnitude PWM
I_avg = (V_uni - back_emf) / R
ripple = (Vbus - V_uni) * duty / (f * L) # peak-to-peak, unipolar approx.
print(f"unipolar: V_avg {V_uni:.1f} V, I_avg {I_avg:.2f} A, ripple {ripple:.2f} A p-p")
print(f"bipolar at same duty: V_avg {V_avg:.1f} V")
Rds, Qg, t_sw = 0.01, 30e-9, 50e-9
P_cond = I_avg**2 * Rds * 2 # two switches conducting (approx.)
P_sw = 0.5 * Vbus * I_avg * t_sw * 2 * f
print(f"conduction loss {P_cond:.3f} W, switching loss {P_sw:.3f} W, gate-drive power {Qg*12*f*4:.3f} W")
# unipolar: V_avg 14.4 V, I_avg 3.67 A, ripple 0.19 A p-p
# bipolar at same duty: V_avg 4.8 V
# conduction loss 0.269 W, switching loss 0.088 W, gate-drive power 0.029 WAt 20 kHz (above hearing) the motor inductance keeps ripple to 0.19 A. Losses are well under 1 W for 88 W delivered, so efficiency exceeds 99% — the reason PWM replaced linear drivers. Bipolar PWM gives zero average at 50% duty (smooth zero crossing) but doubles ripple and losses.
Common mistakes
- Wrong: No dead-time in complementary switching. — Right: Insert dead-time; use drivers with shoot-through protection.
- Wrong: PWM in the audible range. — Right: Use ≥ 16–20 kHz for small motors to avoid whine.
- Wrong: Ignoring regeneration. — Right: Braking returns energy — protect the bus with a chopper or clamp.
Applications
- Robots & AGVs: Brushed/BLDC wheel and joint drivers.
- 3-D printers & CNC: Stepper drivers with microstepping.
- E-bikes & EVs: Three-phase inverters with FOC.
- Automotive: H-bridges for windows, mirrors, throttle bodies.
Key takeaways
- H-bridge: four switches, forward/reverse/brake/coast.
- PWM sets average voltage; inductance smooths current.
- Dead-time prevents shoot-through.
- Current loop = torque control, fastest loop.
Going further
- GaN and SiC switches: Faster switching, higher efficiency and frequency.
- Space-vector PWM: Better bus utilisation in three-phase inverters.
- Sensorless FOC: Back-EMF observers replace position sensors.