RFrftools.io
MotorFebruary 27, 202611 min read

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):

Vsupply=IaRa+LadIadt+VemfV_{supply} = I_a R_a + L_a \frac{dI_a}{dt} + V_{emf}

where Vemf=KeωV_{emf} = K_e \cdot \omega (back-EMF proportional to speed) and torque T=KtIaT = K_t \cdot I_a.

At steady state:

ω=VsupplyIaRaKe\omega = \frac{V_{supply} - I_a R_a}{K_e}

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:

Veff=D×VsupplyV_{eff} = D \times V_{supply}

where DD is duty cycle (0–100%). At 75% duty cycle with 12V supply, VeffV_{eff} = 9V.

PWM frequency choice involves trade-offs:

FrequencyProsCons
1–5 kHzLow switching lossesAudible whine
20–50 kHzSilent, efficientHigher switching losses
> 100 kHzVery fast responseEMI issues, high switching loss
Rule of thumb: Use 20–25 kHz for most brushed DC motor applications. This is above the audible range and keeps switching losses manageable.

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: VDS1.5×VsupplyV_{DS} \geq 1.5 \times V_{supply} 2. I_D — must exceed peak (inrush) current: ID1.5×IinrushI_D \geq 1.5 \times I_{inrush} 3. R_{DS(on)} — lower is better (less conduction loss) 4. Q_g — gate charge, determines switching speed and loss

Conduction loss per MOSFET: Pcond=I2×RDS(on)×DP_{cond} = I^2 \times R_{DS(on)} \times D

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:

Iinrush=VsupplyRaI_{inrush} = \frac{V_{supply}}{R_a}

For a motor with RaR_a = 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:

CPR=4×PPR\text{CPR} = 4 \times \text{PPR}

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:

u(t)=Kpe(t)+Kie(t)dt+Kdde(t)dtu(t) = K_p e(t) + K_i \int e(t)\,dt + K_d \frac{de(t)}{dt}

where e(t)=ωsetpointωmeasurede(t) = \omega_{setpoint} - \omega_{measured}.

Ziegler-Nichols Tuning

A practical starting point using the open-loop step response:

1. Apply a step input and measure the process gain KK, dead time LL, and time constant τ\tau 2. Apply Ziegler-Nichols formulas: - Kp=1.2τ/(KL)K_p = 1.2\tau / (K \cdot L) - Ki=Kp/(2L)K_i = K_p / (2L) - Kd=Kp×0.5LK_d = K_p \times 0.5L

Use the PID Tuning calculator to calculate gains from your measured step response.

---

Thermal Management

Motors generate heat in the windings (P=I2RaP = I^2 R_a) and the driver (P=I2RDS(on)P = I^2 R_{DS(on)}). Sustained overload causes thermal derating and eventual failure.

Calculate operating temperature:
Tmotor=Tambient+Ploss×RθT_{motor} = T_{ambient} + P_{loss} \times R_{\theta}

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 V=IR+KeωV = IR + K_e\omega 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