inkfish / lander-control

0 stars 0 forks source link

Bringup: Battery Voltage ADC #7

Closed rgov closed 8 months ago

rgov commented 9 months ago
Function Pin
24V ADC1 (GP27)
48V ADC2 (GP28)
VSYS/3 ADC3 (GP29)
VBUS presence GP24

The board uses voltage dividers to scale the 24V and 48V battery voltage levels to the 0–3.3V range accepted by the GPIO pin. Therefore, we need to scale the values back.

According to this tutorial the register is updated every 2µs to a value in the range [0, 2^12). Reading the value with machine.ADC().read_u16() will scale the value to [0, 2^16).

On the Pico, the VSYS voltage level can also be monitored by ADC3; this should approximately follow the 24V battery voltage level.

# Assumes adc values are already scaled to [0, 3.3], see above
batt_24v = adc1 * (32000 + 5000) / 5000
batt_48v = adc2 * (68000 + 5000) / 5000
vsys = adc3 * (200000 + 100000) / 100000
rgov commented 8 months ago

Resistor values were changed to 4.99k, 49.9k, 100k.