Close

Battery test

A project log for Симон

The old "Simon" memory game.... with an evil twist

Nick SayerNick Sayer 09/23/2019 at 18:020 Comments

Since the XMega has an ADC and we're not using it for anything else, we do have the opportunity to use it to test the battery state.

The XMega ADC is the weak spot of the chip. The ADC is, in general, buggy and noisy. But this application isn't very demanding, so it's ok.

One issue with the ADC is that the highest internal reference available is Vcc/2, which isn't high enough to measure the incoming battery voltage. So we have to connect the AREF up to Vcc to get a reference comfortably above the battery voltage. The battery voltage goes to pin A1. We configure the ADC for signed differential conversion with 4 times oversampling. This gives us an effective unsigned 11 bit range (the entire negative range of the ADC gets thrown away by pinning the negative differential input to ground). All we really need to do is occasionally compare the ADC reading to a threshold and give a low battery visual indication and shut down whenever it's low. Since the system reliability threshold is somewhere between 2.1 and 2.2 volts, we'll just figure out what value works out reliably to be around 2.2 volts and give that a little cushion and call it a day.

EDIT: I've tested this now on a prototype by tying AREF to AVcc and A1 to the battery sense spot (immediately south of the power MOSFET). A threshold reading of 1550 works on that one. As soon as boards come back that have these connections wired in, we can test for variance to see how repeatable that value is. It'd suck to have to somehow customize each unit on the assembly line. Hopefully that sort of nonsense won't be required.

EDIT 2: Actually, using the analog comparator is easier and better than using the ADC. It doesn't require the AREF connection, has hysteresis, and the test is just checking a single bit in a register.

Discussions