imrishabh18/rp2040-motor-controller

Bottom-side mirrored PCB silkscreen logos rendered as embedded SVG graphics, including via-clearance-aware placement and scaling.

Version
1.0.47
License
unset
Stars
5

engineering/pd-voltage-monitor.md

# USB-PD voltage readback and low-voltage alarm

The CH224K requests a fixed USB-PD voltage, but its CFG pins do not tell the
RP2040 what the charger actually delivered. The new INA226AIDGSR (JLCPCB
C49851) measures **raw PWR-USB VBUS**, before the fuse and blocking diode. Its
separate 3.3 V supply comes from the DATA-USB-powered rail, and its VBUS pin
accepts the PWR supply even if the DATA cable is absent. The INA226's unused
current-sense inputs are joined to VBUS; this board does not add a shunt or
measure charger current. A 100 nF local bypass capacitor is fitted. The chip and bypass are populated on top in the single-sided assembly revision. Only the optional DNP encoder remains on the bottom.

INA226 SDA/SCL share the TMP102's RP2040 I²C1 bus (GPIO26/27). A0 and A1 are
grounded, selecting 7-bit address **0x40**; TMP102 remains at 0x48. No RP2040
ADC channel is moved or reused. Read INA226 bus-voltage register **0x02** and
multiply its unsigned value by **1.25 mV**. The application can select INA226
bus-voltage-only continuous conversion mode (`MODE=110`) since no shunt is
fitted. The 36 V operating limit exceeds
the board's 20 V PD setting; it does not change the USB connector or motor
driver ratings.

## Application behavior

The package deliberately contains no firmware. To make the existing buzzer
signal a supply fault, the RP2040 application must:

1. Keep GPIO22 (motor enable) low before requesting or changing a PD voltage.
2. Set CH224K CFG1/2/3 through GPIO4/5/6, then allow negotiation and VBUS to
   settle. A temporary 5 V state during a voltage change is expected.
3. Sample INA226 at 0x40 on I²C1. Compare measured VBUS with the selected
   setpoint, using an application-defined tolerance and several consecutive
   samples to reject transients. For example, a 12 V request with a ±5%
   voltage window would accept 11.4–12.6 V after settling. A missing sensor
   response is also a fault.
4. Only enable the motor when the voltage is acceptable, the temperature is
   acceptable, and the existing CH224K `PG` gate permits it. On a sustained
   fault, hold GPIO22 low and drive the existing externally driven buzzer from
   GPIO16 with its required waveform. Continue checking while the motor runs,
   and stop it if VBUS falls out of range.

This detects an absent, wrong-voltage, or sagging PWR charger **while DATA USB
also powers the MCU and buzzer**. With only PWR USB connected, this board cannot
beep because the 3.3 V rail is off. Voltage alone cannot prove a charger's
advertised current limit before loading it; that would need PD-profile
readback or a separate input-current measurement. Confirm thresholds, startup
timing, and alarm behavior with the intended charger and motor on a prototype.

Sources: [TI INA226 datasheet](https://www.ti.com/lit/ds/symlink/ina226.pdf),
[JLCPCB INA226AIDGSR C49851](https://jlcpcb.com/partdetail/TexasInstruments-INA226AIDGSR/C49851).