My Nucleo's clock was 0.43% fast

Finally got some time to chase the loose thread on timing issues, and the motor bringup resurfaced the issue. Quick recap from the jitter post: the 1 kHz control tick on my pan tracker met its p99 target, but the Saleae and the DWT cycle counter didn’t agree, and the tick rate moved between captures (+2,398 ppm in one, +2,895 ppm in the next). My guess was the board clock, and it went on the todo list. ...

November 18, 2026

Motor bring-up: coast vs. brake

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. ...

November 17, 2026

Control loop jitter on the STM32H723

I plan to run the motor loop on my pan tracker at 1 kHz on a NUCLEO-H723ZG under FreeRTOS. The Jetson will do the vision and send setpoints over CAN, and the STM32 will close the loop. The PID will use a fixed sample period, so I set a target for the tick itself: period jitter p99 under 2 µs. An interrupt on this chip should fire within a microsecond every time, making 2 µs a reasonable target. Anything slower means something is getting in its way, like: interrupts being masked, code running from slow flash, or a bad clock. The motor loop itself wouldn’t notice until tens of microseconds, so this target is conservative and could serve as a health check of sorts. ...

November 5, 2026