A way to measure battery voltage on Feather M4

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

A way to measure battery voltage on Feather M4

Post by tcornall »

I am needing to get an indication of battery health in a project (Handheld Mapping GPS receiver) that uses an Adafruit Feather M4 plus a Sharp Memory display (2.7")
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
It's better but not perfect. The other issue I've identified is that there appears to be a considerable difference between the voltage that this method reports and actual measurements with a voltmeter at the battery. This difference can be as much as 150mV during charging and as big as 200mV during discharging.

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

User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

Re: A way to measure battery voltage on Feather M4

Post by tcornall »

Quick correction. On checking the schematic it appears that the voltage divider from VBAT is connected directly to the battery and so any drop across the FET shouldn't affect the measured voltage. So I dunno what it is. But it's there. I need to add 0.150V to the calculated voltage to get agreement with the Voltmeter (Hmm, maybe I need to check the voltmeter...)

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: A way to measure battery voltage on Feather M4

Post by adafruit_support_mike »

Remember that the resistors have tolerances. A voltage divider with equal value 5% resistors has a nominal center voltage of Vin/2, plus a tolerance of +/-5% of Vin.

Checking your voltmeter is also a good idea. I'm sure it's reasonably accurate, but *all* measuring systems contain some amount of offset and noise. Calibration is the process of measuring and tracking those unwanted values over time. Even if you don't maintain a full, traceable calibration history, it's worth testing any device against a better one or against a known reference to get a general idea of how it behaves.

User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

Re: A way to measure battery voltage on Feather M4

Post by tcornall »

Good point about the resistors, though if Adafruit use 5% resistors on their boards for halving battery voltage I'll be disappointed...
Though, 5% of 3.3V is 0.16V (which is about what I have to add to my ADC result to match the voltmeter.) Hmm.. It's in the right ballpark...
Add voltmeter errors, resistor errors, ADC errors and maybe all the tolerances have just stacked up against me.

Meh, close enough to tell if the battery is flattish.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”