DC Motor Control: PWM, Drivers, and Encoders Explained
Complete guide to controlling DC motors with PWM: selecting the right H-bridge driver, sizing the MOSFET, and closing the loop with an encoder.
Introduction
DC motor control appears simple: vary the voltage, vary the speed. But real systems must handle inrush current, back-EMF, thermal limits, and position accuracy. This guide walks through each layer of the control stack.
---
The DC Motor Model
A brushed DC motor can be modelled as a voltage source (back-EMF) in series with a resistor (armature resistance) and inductor (armature inductance):
where (back-EMF proportional to speed) and torque .
At steady state:
Use the DC Motor Speed calculator to explore this relationship interactively.
---
PWM Fundamentals
PWM (Pulse-Width Modulation) controls motor voltage by rapidly switching the supply on and off:
where is duty cycle (0–100%). At 75% duty cycle with 12V supply, = 9V.
PWM frequency choice involves trade-offs:
| Frequency | Pros | Cons |
|---|---|---|
| 1–5 kHz | Low switching losses | Audible whine |
| 20–50 kHz | Silent, efficient | Higher switching losses |
| > 100 kHz | Very fast response | EMI issues, high switching loss |
Use the PWM Duty Cycle calculator to calculate effective voltage and estimate stall current.
---
H-Bridge Drivers
To drive a motor bidirectionally, you need an H-bridge: four switches arranged so you can apply voltage in either direction.
Discrete vs. Integrated
Integrated drivers (DRV8833, TB6612, L298N) are easiest. They handle dead-time, thermal shutdown, and over-current protection internally. Discrete MOSFETs give higher efficiency and allow driving higher currents, but require gate drivers, bootstrap circuits, and careful layout.MOSFET Selection
The critical specs for H-bridge MOSFETs:
1. V_DS — must exceed supply voltage with margin: 2. I_D — must exceed peak (inrush) current: 3. R_{DS(on)} — lower is better (less conduction loss) 4. Q_g — gate charge, determines switching speed and loss
Conduction loss per MOSFET:
Use the H-Bridge Selection calculator to calculate peak current and minimum MOSFET ratings, and the Motor Driver Power calculator to estimate total losses.
---
Inrush and Starting Current
At startup, the motor is stationary (ω = 0), so back-EMF = 0. The initial current is:
For a motor with = 0.5Ω on 12V, inrush = 24A — even if rated current is only 2A. This is a 12× inrush multiplier.
Mitigation strategies:- Ramp up the PWM duty cycle (soft-start)
- Use a current-limiting controller (DRV8434 has built-in current chopping)
- Size the H-bridge for the inrush current, not the rated current
Encoders for Closed-Loop Control
Open-loop PWM speed control is sufficient for fans and pumps. For position control or precise speed regulation, you need feedback from an encoder.
Types of Encoders
- Optical incremental (AB quadrature): Counts pulses as the shaft rotates. Most common, 100–10,000 PPR.
- Magnetic (Hall effect): Robust to contamination. Used in industrial motors.
- Absolute: Outputs absolute position; no homing required.
Quadrature Decoding
Two channels A and B, 90° out of phase. By detecting all rising and falling edges of both channels, you get 4× resolution:
A 1000 PPR encoder gives 4000 counts per revolution = 0.09° resolution.
Use the Encoder Resolution calculator to calculate CPR, angular resolution, and maximum pulse frequency for your counter.
---
PID Speed Control
Once you have encoder feedback, you can close the loop with a PID controller:
where .
Ziegler-Nichols Tuning
A practical starting point using the open-loop step response:
1. Apply a step input and measure the process gain , dead time , and time constant 2. Apply Ziegler-Nichols formulas: - - -
Use the PID Tuning calculator to calculate gains from your measured step response.
---
Thermal Management
Motors generate heat in the windings () and the driver (). Sustained overload causes thermal derating and eventual failure.
Calculate operating temperature:Copper winding resistance rises with temperature (TCR ≈ 0.39%/°C), so hot resistance increases and torque decreases — check your motor's thermal derating curve.
---
Summary
1. Model the motor: Use to predict speed and current 2. Select the driver: Size for inrush current (5–10× rated), not just rated current 3. Choose PWM frequency: 20–25 kHz for silence + efficiency 4. Add feedback: Quadrature encoder gives 4× resolution 5. Tune PID: Start with Ziegler-Nichols, refine empirically 6. Check thermal: Motor and driver temperature at max load