I am trying to create a low power device, which would work off a LIR2450 or similar coin cell battery. athe device has long periods of sleep with short periods when it performs operation (e.g. reading sensor and/or sending LoRa data).
For this purpose, I am using an atmega328p. The idea is to have a stable 3.3V out of a voltage regulator and correct battery reading over the voltage divider R9/R10.
Here is the relevant part of the diagram:
I have selected high resistance values for the voltage divider in order to reduce current (this might have been a bad idea).
I am getting readings of Vmeas, but depending on the battery voltage they are somehow - not consistent. When I have approx. 3.5V I seem to get around expected measurement of ADC, however, with around 3V or 4V the readings are strange - either lower than expected or sometimes higher, as if the ADC is not linear in its readings.
How do I measure:
// calculate Vbat from adc value, assuming Vbat:Vmeas is over the resistor-devider 1M:2M
float adcVbat(int adcV) {
// first calculate adc measurement (10 bit adc - reference 3.3V)
double meas = ((double)3.3) * ((double)adcV) / 1023;
// calculate Vbat from voltage devider
double result = meas * (R1M + R2M) / R2M;
return result;
}
// read Vcc in miliVolts
long readVcc() {
int adc = analogRead(A6); // read ADC
return (adcVbat(adc) * 1000);
}
Do you see anything wrong with my concept and should it, in general, work as I expect?