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

Worked example: Average voltage

Given: 24 V bus, D = 0.6 (unipolar)

Find: V_avg.

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.

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.

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 W

At 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

Applications

Key takeaways

Going further