DC motor and H-bridge: direction and speed control
Four switches change the current direction and PWM adjusts the average voltage. Including brake, coast and current-decay modes.
H-bridge
The motor sits in the middle with four switches (Q1 to Q4) arranged in an H shape.
| Switches on | Motor |
|---|---|
| Q1 + Q4 | Forward |
| Q2 + Q3 | Reverse |
| Q3 + Q4 (both low) | Short-circuit brake |
| All off | Coast (free rotation) |
| Q1 + Q3 (same side) | Supply short: forbidden |
PWM speed control
Switch the forward state on and off with PWM and the motor inductance averages the current, so the motor sees an average voltage ≈ duty × Vdc. A PWM frequency above the audible band, 16 to 25 kHz, is common. Too low and the motor whines; too high and switching losses grow.
Current path during the off-time (decay mode)
- Slow decay: the current circulates through the two low switches → small current ripple, suited to speed control
- Fast decay: the opposite switches return the current to the supply → current falls quickly, faster current-control response
Driver ICs
L298N (bipolar, high loss), DRV8871/TB6612 (MOSFET, efficient). Large currents use a gate driver + external MOSFETs. The DC motor 3D simulation in the lab shows the current flow for each switch combination.
The four-switch combinations
| Q1 (top left) | Q2 (bottom left) | Q3 (top right) | Q4 (bottom right) | Result |
|---|---|---|---|---|
| On | Off | Off | On | Forward (current: left → right) |
| Off | On | On | Off | Reverse |
| Off | On | Off | On | Brake (both motor terminals shorted to ground) |
| Off | Off | Off | Off | Freewheel (turns on inertia) |
| On | On | - | - | Forbidden: supply short |
If the upper and lower switches on the same side are on together, supply and ground are joined directly and the MOSFETs burn in an instant. This is called shoot-through.
Speed by PWM
Switch fast enough and the motor responds to the average voltage.
average voltage ≈ supply voltage × duty
12 V, 60% duty → about 7.2 V
The PWM frequency is usually set around 20 kHz. That is outside what people can hear (below about 20 kHz), so there is no noise, and the current ripple is small enough. Going higher increases switching losses.
Where the current goes during the off-time
A motor is a coil, so its current cannot stop suddenly. The current needs a path during the PWM off-time too, and the characteristics depend on which path you give it.
| Method | Handling the off-time | Characteristics |
|---|---|---|
| Slow decay | Turn on both low switches so the current circulates | Small current ripple, smooth at low speed. Widely used |
| Fast decay | Apply voltage in the opposite direction | Current falls quickly. Good for hard deceleration |
Dead time
A MOSFET keeps conducting for tens to hundreds of ns after it is told to turn off. If you turn on the lower switch the moment you turn off the upper one, the two overlap in between. So you turn one off, wait briefly, and then turn the other on. The complementary outputs and dead-time insertion of an advanced timer, or a gate driver chip, do this for you.
Current calculation and starting current
current = (applied voltage − back-EMF) / winding resistance
standstill: back-EMF 0 → 12 V / 1 Ω = 12 A
rated speed: back-EMF 10 V → (12 − 10) / 1 Ω = 2 A
Apply full voltage to a stopped motor and several times the rated current flows. Raise the duty gradually, or measure the current and limit it. Reversing direction while turning adds the applied voltage and the back-EMF, making the current even larger, so stop first and then reverse.
Braking and the supply voltage rising
When a motor is decelerated hard it becomes a generator and current flows back towards the supply. A battery absorbs it, but a bench supply or a supply behind a diode cannot, and the voltage rises. Fit a large capacitor so the capacitor voltage does not exceed the MOSFET rating, or burn the energy in a braking resistor.
Choosing a driver chip
- Do the continuous and peak currents withstand the motor's starting current?
- Does it include overcurrent, overtemperature and undervoltage protection?
- Does the input scheme (direction + PWM, or IN1/IN2) fit your code?
- Is there a current-sense output?
Problems that come up in practice
- Motor power and MCU power taken from the same line, so the MCU resets at start-up
- No noise-suppression capacitor at the motor terminals, so communication breaks
- Thin ground wiring, so the reference potential shifts when large currents flow
- PWM pins float during reset and the motor twitches (pull-down resistors)