ClassA Motor

How do I control a BLDC motor with a microcontroller: PWM speed, direction and brake inputs

A microcontroller drives a BLDC motor through a three-phase inverter. Learn how PWM sets speed, how direction and brake are implemented, dead time, and current protection.

Updated 2026-11-28

The short answer

A microcontroller drives a BLDC motor with a three-phase inverter made of six power transistors, usually MOSFETs, controlled by a gate driver. The microcontroller switches the phases in a sequence that follows the rotor position, given by Hall sensors or estimated from back-EMF. Speed comes from the PWM duty cycle, direction from reversing the commutation sequence, and braking from shorting the phases through the low-side transistors or by holding them at a controlled state. Gate timing, dead time and current sensing cause most failures.

Signals the microcontroller needs

  • Inputs: a PWM or analog speed command, a direction input, a brake input, an enable input, and, for a Hall-sensor motor, three Hall inputs.
  • Outputs: six gate signals (three high-side and three low-side), usually through a gate driver that provides enough current to charge the MOSFET gates.
  • Use a gate driver with bootstrap or isolated supplies for the high-side transistors. Do not drive MOSFET gates directly from a microcontroller pin.
  • Logic is often 3.3 V. Make sure the gate driver and any Hall or sensor inputs accept that level, or add level shifting.

PWM frequency, duty and dead time

  • Choose a PWM frequency of roughly 16 to 20 kHz. It is above hearing range, so the motor is quieter, and it still keeps switching losses acceptable.
  • Worked example: a timer clocked at 72 MHz with a 20 kHz PWM has a period of 72,000,000 / 20,000 = 3600 counts. A 60 percent duty cycle means 2160 counts high.
  • Dead time: insert a short gap of about 0.5 to 1 microsecond, as set by the datasheet, between switching the high-side off and the low-side on. Without it, both transistors in one leg conduct at once and short the supply.
  • Duty ramp: change the duty cycle gradually. A step change causes current spikes and mechanical shock.

Direction and braking

  • Direction: reverse the commutation table, or swap two phases in the drive logic. Do this only at standstill or at very low speed, not while the motor is spinning fast.
  • Brake by shorting: turning on all three low-side transistors shorts the windings, and the braking torque rises with speed. At high speed the current is large, so limit it or use this method only for low speed.
  • Brake by regeneration: stop switching and let the energy return to the DC bus. This needs a bus that can absorb energy, such as a braking resistor or a bus capacitor with headroom.
  • Make brake and enable inputs fail-safe: a floating input must not release the brake or start the motor. Use pull-up or pull-down resistors and check the logic on power-up.

Current sensing and protection

  • Use a low-value shunt resistor in the DC bus or the phase legs, or Hall-effect current sensors on the phases.
  • Sample the current at the centre of the PWM on-time, so the ADC reads when the switching noise has settled.
  • Use hardware overcurrent cutoff, typically a comparator that shuts all gates within about a microsecond, and keep the software limit as a slower backup.

Common mistakes

  • No dead time, which causes shoot-through and destroyed MOSFETs.
  • Wrong Hall polarity or the wrong state table, so the motor vibrates, runs rough or runs backward.
  • Floating gate inputs or a missing gate-driver supply during power-up.
  • Braking by shorting at high speed, which produces large currents and can trip the drive.
  • Audible whine from a PWM frequency in the audible band, or noise from a poor ground layout.

Synchronous speed, slip and VFD speed

nₛ = 120·f / p · s = (nₛ − n) / nₛ

Synchronous speed1,500rpm
Slip2.67%
Speed at VFD frequency, rated torque1,010rpm

V/f control keeps slip in rpm roughly constant at the same torque, so speed = 120·f/p − rated slip. At light load the motor runs closer to synchronous speed. Above base frequency torque falls (field weakening).

Sourcing a motor or production equipment from China? We can find and contact the right factories for you in Chinese. Ask on WhatsApp →