I found that I can get the battery voltage using a built-in resistive divider connected to the ADC using board.BATTERY. Multiplying by 2 and then converting ADC units to voltage should give me the battery level.
However, there is a problem. (A couple of problems) One is that the AREF voltage for the ADC is tied to the voltage regulator output. Assuming that it is 3.3V is incorrect, because I've measured it when on the battery and when the battery input falls to about 3.4V the regulator output falls to about 3.1V.
Fortunately there is a solution provided by the good folks who maintain Micropython's microprocessor and board modules, plus thoughtful design of the Feather itself.
board.BATTERY input comes from a resistive divider that is connected to BAT and then connected to an ADC input. It's divided by 2.
The microcontroller.cpu.voltage property appears to give a voltage for the regulator output that is measured using an internal bandgap reference.
Using them, one can do something like this:
Code: Select all
import microcontroller
import board
from analogio import AnalogIn
cpu_volt = microcontroller.cpu.voltage #Also can use this to detect imminent brownouts
batt_volt =AnalogIn(board.BATTERY).value *2 * cpu_volt / 65536
The discrepancy during charging I kind of expect, but the one during discharge is bigger than I'd hoped. Coupled with the regulator dropout it means that the supply voltage is going to go too low when the battery is still quite healthy at 3.4 volts or so.
It should not be anything to do with the dropout across the regulator because the board.BATTERY input comes from a resistive divider that is connected to BAT before the regulator(as far as I can tell from the published Adafruit schematic, thanks for that!) Maybe there's a drop across the FET that connects the battery to the regulator input.
Nonetheless, at least the measurements are better than what I had before when I was assuming 3.3V on the regulator output.
Terry