0
\$\begingroup\$

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

enter image description here

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
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  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.

\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$ Nov 2, 2020 at 15:35

1 Answer 1

1
\$\begingroup\$

No, that won't work. The VCC and AVCC must be within 0.3V of each other, so connecting them to separate voltages, e.g. one to battery and another to regulator makes it very difficult to ensure that they are always within 0.3V of each other. Simply by connecting the battery could damage it, if battery voltage rises rapidly and regulator output rises slowly.

Also if the AVR clock is 8 MHz, it needs at least 2.4V supply voltage to operate, voltages below 2.4V is out of the safe operating area. Therefore it cannot be expected to run at supply voltages below 2.4V.

So it depends on what is the other device uses for logic level limits, but using different supply voltages for two SPI devices can be difficult unless voltage level translation is used. AVR tolerates only voltage max of 0.5V above VCC on its input pin, so if the other device runs at 3.0V, minimum AVR supply must be 2.5V or over, or absolute maximum is exceeded. It also needs to be checked if 2.5V from AVR exceeds logic high minimum input level of the other device that runs on 3.0V.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the answer. Now I checked Atmel and surely there is information that Vcc and AVcc cannot differ more than 0.3V. So, what I left is to use regulator for power and using ADC pin to measure battery over voltage divider. \$\endgroup\$
    – Marko
    Nov 3, 2020 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.