Backspin

You inherited the speed controller for a small brushed DC drive that runs in both directions. The setpoint is signed: a positive value means turn one way at that speed, a negative value means turn the other way. A colleague wrote a tidy fixed-point loop that reads the measured speed every millisecond, eases the PWM duty toward the commanded magnitude, and picks the rotation direction once at start-up from the sign of the setpoint.

On the bench, hooked to a tachometer, it was flawless: it spun up to exactly the commanded speed and held it. It shipped. Then it went into a rig that actually cares which way the shaft turns, and every move came out reversed. Commanded one way, the shaft turns the other, at precisely the right speed. The magnitude was always correct, so nobody had ever caught it.

The commanded setpoint is delivered in an SRAM mailbox at 0x2000FF00. A load torque is applied to the plant independently, and it is not the same from run to run, so the duty that holds a given speed cannot be memorized. Speed is reported in milli-RPM (12,000,000 mRPM is 12,000 RPM), signed by rotation direction: a reverse command should read as a negative speed.

Find why the shaft turns against the commanded direction and fix it so it turns the commanded way at the commanded speed.

Loading the interactive arena.