atmega328p measuring supply battery voltage

I have a custom PCB with ATMega328p (3V, 8Mhz external resonator) where both Vcc and AVcc are connected to a battery.

Device is in sleep mode most of the time, and only occasionally wakes to process data. Power consumption is important priority. Currently in sleep mode I measure ~ 8uA.

This circuit is working properly. I am measuring battery voltage this way:

long readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);

delay(2); // Wait for Vref to settle

uint8_t high = ADCH; // unlocks both

long result = (high<<8) | low;

result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
return result; // Vcc in millivolts
}


So far I had both Vcc and AVcc connected to a battery supply. Now I am introducing a voltage regulator (3V output) for additional component (requiring more stable 3V), and I have a dilemma - how to continue monitoring the battery level:

• To connect ATmega Vcc to a voltage regulator (3V) as well and have AVcc connected to a battery directly. Would this work properly?
• I can leave ATmega connected directly to a battery supply (2 x 1.5V AAA=3V), and continue using it as before. Can this cause problem with other device (working on 3V through regulator) that I am connecting to (for SPI communication) if the battery level drops low (e.g. ~2V)? ATmega is set to 1.8V BOD.

I do not use ADC except for battery voltage measurement.

• Unless your regulator is a buck-boost, your output voltage is going to be several hundred millivolts below your input, never higher. A major thing you need to be aware of is never having an input signal more than a diode drop above a supply rail, either on the MCU or on the other devices with which it communicates. To measure an analog input above the supply rail you would need a voltage divider - but you'd need a PFET to enable the divider and an NFET to enable the PFET. Ultimately without full details of all components better advice cannot be given. Please add a complete schematic Nov 2, 2020 at 15:35