This part is for members
Membership opens soon. Leave your email and we'll tell you the day it does. Founding members get the launch price.
Keep watching the free partsCurrent sampling 2: from ADC count to amps
The board build (episode 6's bench, with the ADC registers as bench variables) runs the real bsp_get_phase_current() and CurrentCalibrationStep(). At 1197.4 ms U's JDR1 holds 32990: one count is 1.2589 mA (2 mΩ shunt, op-amp gain 20, 16 bits over 3.3 V), minus the zero 32791 gives 199 counts, 0.2505 A; below the zero, an (int32_t) cast makes it negative. The zero is the average of 1024 readings at 0 V on the first enable. Then four real runs: a zero at 36100 fails on the first reading; one glitch voids the whole calibration, yet the same glitch 50 µs later is never seen; after a failure, clearing the error and enabling again recalibrates but never switches the PWM back on (a servohub bug); a joint pushed with 0.05 N·m while it calibrates gets a wrong zero, so holding still the driver reads 0 A while 0.65 A flows in the motor.