2
\$\begingroup\$

I am designing a system focused on the uC ATmega328p and I am feeding it directly with a 3.7V LiPo battery. I also have a 3.3V LDO feeding several sensors in the system.

My question is the next, If I want to read the battery voltage [full charge = 4V, discharged = 3V (approx.)] How should I configure the Vcc, AVcc and AREF pins of ATmega in order to achieve that result?

At the moment I feed the ATmega328p (with internal crystal 8MHz) to the battery voltage and I was thinking of connecting Vcc with AVCC and with the 3.3V that the LDO gives me to connect them to AREF and put the voltage of the battery with a voltage divider to an analog arduino input.

What do you think? Any better solution?

PS: I would not like to add any extra components to the system.

Thank you.

\$\endgroup\$
7
  • 2
    \$\begingroup\$ Possible duplicate of How to read high voltages on microcontroller? \$\endgroup\$
    – MCG
    Feb 20, 2019 at 10:36
  • \$\begingroup\$ You're not the first to want this, many have done the same already. Some have described how they did this on some website. You should search for "Arduino battery monitor" and you will find plenty of examples. No need to ask here for the same now is there? \$\endgroup\$ Feb 20, 2019 at 10:40
  • \$\begingroup\$ Yes, you can do that. Or, you can use the internal 1.1V reference. The internal reference will be more stable. You can measure it with high precision for the chip (with a multimeter) and put that in software. 1.1V is nominal, it will vary from chip to chip. The actual value can be stored in eeprom, if producing in large numbers. \$\endgroup\$
    – Indraneel
    Feb 20, 2019 at 10:50
  • \$\begingroup\$ Thanks for the reply Bimpelrekkie, but I'm not using an arduino or 5V as power. @Indraneel with respect to using internal 1.1V, it is necessary to feed Aref with 1.1V but I have no way of doing it (I think). \$\endgroup\$
    – Wave Wolf
    Feb 20, 2019 at 11:13
  • \$\begingroup\$ @WaveWolf it is an INTERNAL reference. You do not have to supply anything. It is generated by the uC. Look it up. And just to clarify, make sure you do NOT supply anything to aref when using the internal reference, or it might damage the aref or the reference. It's all there in the datasheet. \$\endgroup\$
    – Indraneel
    Feb 20, 2019 at 11:59

2 Answers 2

4
\$\begingroup\$

You can use the internal 1.1V bandgap reference to indirectly measure the voltage on the Vcc pin. This 1.1V reference is built into the chip and can be connected to the ADC by setting the MUX registers correctly.

enter image description here

Full details here...

https://wp.josh.com/2014/11/06/battery-fuel-guage-with-zero-parts-and-zero-pins-on-avr/

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Technically you are actually measuring the reference voltage using an unknown voltage as your reference and back-calculating from there. You should probably add that detail to your answer. \$\endgroup\$ Feb 23, 2019 at 5:02
  • 1
    \$\begingroup\$ @EdgarBrown Answer updated to read "indirectly measure". Thanks! \$\endgroup\$
    – bigjosh
    Feb 23, 2019 at 22:55
0
\$\begingroup\$

Finally I decided to feed Aref with a stable voltage of 3.3V (LDO) used for a sensor in the system. The option of 1.1V I like but for "requirements" of design and components I will use 3.3V and a voltage divider at the output of A0 with the battery voltage. I just need to know when it's running out, I don't need something precise. Thank you all.

\$\endgroup\$
3
  • \$\begingroup\$ Note: If the dropout voltage of the LDO + 3.3V (ie. minimum input voltage for regulation) is higher than the desired cutoff voltage then you will not be able to detect it, because the reference voltage will drop first - making the measurement higher than expected. So you will need a true LDO with dropout voltage < 0.3V (to detect 'low battery' between 3.6-3.7V), not eg. 1117 types which may drop up to 1V. \$\endgroup\$ Feb 23, 2019 at 23:21
  • \$\begingroup\$ Your plan here is substantially inferior to using the bandgap, and your "requirement of design and components" makes no sense since the bandgap approach doesn't require any components at all. \$\endgroup\$ Feb 24, 2019 at 7:34
  • \$\begingroup\$ I'm using a real "LDO", I have no problem :). Chris Stratton, you right. I didn't watch the bandgap link, it's my fault. Thank you again! ;) \$\endgroup\$
    – Wave Wolf
    Feb 26, 2019 at 0:41

Your Answer

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

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