In embedded work, motor control is a recurring application — and a humbling one. Here are some hard-earned notes from the bench using STM32 and ESP32 for motor control. These come from hours of debugging and probing, and they aim to be actionable for anyone tackling something similar.
PWM Configuration
With PWM, precision matters. Both parts offer flexible PWM, but with nuance. The STM32’s advanced-control timers give you high-resolution PWM that keeps motor motion smooth; the ESP32’s LEDC peripheral generates PWM across multiple channels and frequencies, handy for varying speed requirements. Picking a configuration is a balance of resolution, frequency, and power: higher resolution smooths motion but costs power, lower resolution saves power but can introduce audible or mechanical jitter. Tune it to the motor, not the datasheet default.
Current Sensing
Accurate current sensing protects the motor from overcurrent. Parts like the ACS712 family interface cleanly, but placement and filtering decide whether the readings are usable. Put the sensor close to the load path, add a proper low-pass filter to kill switching noise, and calibrate against a known current source so the MCU’s interpretation matches reality.
Debouncing
Mechanical switches — start, stop, direction — generate spurious edges. Without debouncing you get erratic behavior. Hardware debouncing (an RC network) is robust and fast; software debouncing (polling or timed interrupts) is cheap and flexible. In a tight, high-speed loop, lean hardware. In a resource-rich design, software is usually fine.
Brownout Detection
Low-voltage events corrupt state and crash systems. Both parts have built-in brownout detection that resets the MCU below a threshold. Set that threshold a little above the part’s minimum operating voltage — high enough to catch a real sag, low enough to avoid nuisance resets during normal current spikes.
The Datasheet Is Never the Whole Story
Datasheets are essential but incomplete. Thermal behavior under sustained load, real power draw, EMI from switching — those show up on the bench, not on the page. Budget time to measure the things the datasheet glosses over, because the motor will find them for you.
Bottom line: Good motor control is bench work — PWM, sensing, debouncing, and brownout margins all get finalized with a scope in hand, not from the datasheet alone.