With the control tick and CAN working, the next piece of the pan tracker was the motor: a goBILDA 5203 gearmotor (26.9:1, with an encoder) driven by a Pololu VNH5019 carrier. The STM32H723 sends PWM, reads the encoder and current sense, and monitors the driver’s fault line. I hadn’t touched motors since university, so it’s been a fun time in the lab!
Background H-bridge Four switches around the motor. Turning on different pairs drives it forward or backward. The VNH5019 is a single-chip H-bridge with current sense and a fault output. PWM duty The fraction of each PWM period the bridge drives the motor, which sets the average voltage. Here the period is 50 µs (20 kHz). Quadrature encoder Two square waves, A and B, a quarter cycle apart. Which one leads gives the direction. Counting every edge on both (x4) gives the position. Coast vs. brake Coast leaves the motor leads floating, so it spins down on friction alone. Brake ties both leads to the same rail, so the motor’s own back-EMF drives a current that slows it down. Deadband The smallest duty that gets the motor moving from rest. Open drain A pin that can only pull low. Something else pulls it high, so either side can pull the line down. Setup PWM: TIM1 CH1 at 20 kHz (PSC 0, ARR 12999 on the 260 MHz timer clock), so 13,000 duty steps. The VNH5019 does its own bridge timing, so no complementary output. Encoder: TIM4 in encoder mode on PD12/PD13, x4, with the input filter on both channels. Direction: INA/INB on two GPIOs. EN/DIAG: open drain on PE13. The driver pulls it low on a fault, so if the firmware has it released but the pin reads low, that’s a fault. Current sense: ADC3 on PF4, through 1 kΩ and 100 nF (about a 1.6 kHz corner) to smooth the 20 kHz ripple. motor.c drives it open loop: a motor CLI command with percent duty and a run deadline (1 s default, 5 s max), and a fault interrupt on EN/DIAG that latches until motor clear and puts the supervisor in FAULT.
...