Out of Step

You inherited the drive firmware for a small brushless motor running six-step (trapezoidal) commutation. A brushless motor only makes torque when the bridge energizes the voltage vector that leads the rotor, so every 100 microseconds the loop reads the rotor's electrical sector (0 through 5), looks up the phase-sign pattern to drive in a six-entry commutation table, scales it by a duty the speed loop eases toward the commanded speed, and writes the three phase modulations.

A colleague handed it over as working, and on the bench it looks close: commanded to speed, the shaft spins up and holds very nearly the right rate. But it runs rough. The torque is uneven, the drive judders through part of every revolution, and the phase currents sit higher than the modest load should ever demand. It behaves the same no matter where the rotor happens to be resting when it starts, and no fault is reported.

The commanded speed arrives in an SRAM mailbox at 0x2000FF00 in milli-RPM (6,000,000 mRPM is 6,000 RPM). The rotor's present electrical sector is reported in SECTOR (0 through 5). The bring-up, the SysTick arming, the speed loop, and the reporting are all correct.

Find why the drive runs so rough and circulates so much current, and fix it so it spins up cleanly and smoothly from whatever sector the rotor starts in.

Loading the interactive arena.