Author Topic: Battery Monitor - Proper Way  (Read 10980 times)

0 Members and 1 Guest are viewing this topic.

Offline vitormhenriqueTopic starter

  • Supporter
  • ****
  • Posts: 23
Battery Monitor - Proper Way
« on: July 20, 2015, 07:55:58 pm »
Hello Guys,
Quick question: If I have a 5v battery, can I monitor the battery voltage straight to the arduino analog pin? Or should I use a resistor divider?
I know if the battery voltage would be greater than 5V we would need a voltage divider to not fry arduino.
But If I direct link the a battery (that has less than 5V) to the analog pin, what is the internal resistance of the atmega chip? how much current it will draw? I don't want to consume to much energy (obviously) measuring the battery voltage.

So I can think of three ways to build the circuit:
  • Plug the battery directly on the atmega chip
  • Pug a resistor in series directly to the atmega chip, to possibly reduce the current drawn
  • Measure the voltage between a voltage divider, but I'll end up losing resolution

Thank you very much,

Vitor Henrique
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #1 on: July 20, 2015, 09:17:48 pm »
Is there a separate 5V or higher supply powering the Arduino? If so, you can attach the battery directly to an analog pin and set the Arduino reference to Vcc. The analog input will have a very high input impedance, so you don't need to add a series resistor to reduce current.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Battery Monitor - Proper Way
« Reply #2 on: July 20, 2015, 09:22:26 pm »
Not sure I've ever seen a 5 volt battery before, but assuming you have such a beast..

There are two conditions you need to be concerned about and deal with.

1. Wiring +5vdc directly to an analog input pin is not a problem as long as the micro has at least +4.5vdc or so applied to it's power pins (Vcc, Avcc). So as long as you have a power plug or switch that removes the 5vdc battery to both the micro's Vcc pins as well as the analog input pin you should have no problems.

2. If you do ever have a condition where the +5vdc to the analog pin is active but the Vcc is removed from the micro then the input pin's clamping protection diode will conduct with possible chip damage resulting. One fix is to wire a 10k ohm series resistance between the 5 volt battery and the input pin which will limit the current to a non-damaging level.

« Last Edit: July 20, 2015, 09:24:45 pm by retrolefty »
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #3 on: July 20, 2015, 10:10:16 pm »
Not an expert but these are my thoughts if it helps.

In general you want the source resistance to be low (lower than 10k). If necessary use a voltage divider to make sure battery voltage is less than Vcc, but try to make the output resistance of the voltage divider lower than about 10k (the output resistance is equal to the divider resistors in parallel). A voltage divider will drain the battery continuously though, but if the current through the divider is low (less than 10mA) you could ground it through one of the I/O pins. Just put that output pin low when you are about to measure the voltage.

So for example with a divider with 10k and 90k output resistance would be 9k and the current draw would be about 5V / (10k+90k) = 50 uA wich is no problem to sink with one of the IO pins.

For better resolution you could also use an op amp circuit like the one in answer 1 in the following page to scale the input battery voltage range into the range of the ADC:
http://electronics.stackexchange.com/questions/18264/subtracting-two-voltages-using-an-op-amp
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #4 on: July 20, 2015, 11:11:39 pm »
In general you want the source resistance to be low (lower than 10k).
A low source resistance is only required for fast moving signals at high acquisition rates. For monitoring a battery, which I suspect will change voltage very slowly and will be read at long intervals, the source resistance can be much higher. A divider of even 1Meg total would probably work in this situation.

However, from what has been described, it doesn't look like a divider will be necessary as long as the processor's Vcc remains higher than the maximum battery voltage.

If protection from battery connected with no Vcc is required, as retrolefty described in his second point, the series protection resistor could actually be much higher than 10k, for the same reasons as above.
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #5 on: July 20, 2015, 11:26:22 pm »
A low source resistance is only required for fast moving signals at high acquisition rates.
Yes, that seems to be true <10k is to ensure a high sampling speed. If the battery voltage is less than 5V a series resistor on the input might be simplest/safest.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Battery Monitor - Proper Way
« Reply #6 on: July 20, 2015, 11:27:46 pm »
BS.  The maximum source resistance is defined exactly by the sampling time and sampling capacitor charged voltage error < 1LSB. You can calculate that from the sampling cap capacitance and overall circuit impedance (sample switch resistance, etc..).

If I remember right, for the AVR is suggested to have <1kohm in the datasheet. You can check yourself.
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #7 on: July 20, 2015, 11:34:27 pm »
From the ATmega328P (etc.) datasheet:
Quote
The ADC is optimized for analog signals with an output impedance of approximately 10k or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the S/H capacitor, with can vary widely.
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #8 on: July 21, 2015, 12:09:46 am »
Anyway, best solution is probably to have source resistance < 10k and make sure that battery isn't connected to AD when power is off, after all, draining a battery to 0 will destroy it and usually make a mess (not sure what the application here is?). Can be done with a transistor or with a two pole power switch as retrolefty wrote. Maybe add a resistor in series so total input source resistance is > 500 Ohm just to make it foolproof if there is a problem with the switch or during prototyping etc.
« Last Edit: July 21, 2015, 04:04:02 am by apis »
 

Offline vitormhenriqueTopic starter

  • Supporter
  • ****
  • Posts: 23
Re: Battery Monitor - Proper Way
« Reply #9 on: July 22, 2015, 05:43:26 am »
Guys!

Thank you all for the responses!

@retrolefty you are correct, the battery is not actually 5V, I but 5V as an example, because i know the battery voltage will not be higher than vcc (5V).

My case I want to measure an alarm the user when a lipo battery (one cell) get's in a low voltage state.

The battery will go to a step up circuit to 5V and feed the atmega, I want to alarm the user when it get''s to a point that it should be charged again. As the processor might turn off due to the low battery I guess is better to put a resistor in series to to make sure that that case is also covered!

Again thank you all for the help!
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2585
  • Country: fr
    • kripton2035 schematics repository
Re: Battery Monitor - Proper Way
« Reply #10 on: July 22, 2015, 06:02:05 am »
it would be less waste of energy if you power the atmega directly under 3.3V using the 3.7-4.2 volts the battery provides
instead of stepping up the whole thing to 5v. just my 2 cts.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: Battery Monitor - Proper Way
« Reply #11 on: July 22, 2015, 06:53:05 am »
In general you want the source resistance to be low (lower than 10k).
A low source resistance is only required for fast moving signals at high acquisition rates.

Not necessarily true.  The input leakage current will determine the maximum usable source resistance at low frequency or DC levels.

The OP hasn't said what he is using for the ADC reference voltage either.  Obviously you can't power the AVR Vref from the same supply you are trying to measure, and you can't regulate the battery supply to the AVR and measure the battery voltage directly with no divider.

One trick that may be useful is to power the AVR (and ADC reference) from the battery supply, and then measure an e.g. 2.5v voltage reference on one of the ADC pins.  Some simple maths on the ADC result will yield the battery voltage.
« Last Edit: July 22, 2015, 06:57:46 am by mikerj »
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #12 on: July 22, 2015, 07:42:54 am »
One trick that may be useful is to power the AVR (and ADC reference) from the battery supply, and then measure an e.g. 2.5v voltage reference on one of the ADC pins.
I think the mega is nice enough to have an internal bandgap voltage reference, so you only need an external reference if you really care about accuracy.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: Battery Monitor - Proper Way
« Reply #13 on: July 22, 2015, 09:49:42 am »
One trick that may be useful is to power the AVR (and ADC reference) from the battery supply, and then measure an e.g. 2.5v voltage reference on one of the ADC pins.
I think the mega is nice enough to have an internal bandgap voltage reference, so you only need an external reference if you really care about accuracy.

Can you select Vdd as the ADC reference and measure the internal reference on one of the ADC channels?  If so then this is probably the best way forward for the OP if he is determined not to have a potential divider for some reason.
 

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28371
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
Re: Battery Monitor - Proper Way
« Reply #14 on: July 22, 2015, 10:27:51 am »
I don't want to consume to much energy (obviously) measuring the battery voltage.
This has been my preferred device:
http://www.maximintegrated.com/en/products/power/supervisors-voltage-monitors-sequencers/ICL7665.html
Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Battery Monitor - Proper Way
« Reply #15 on: July 22, 2015, 10:52:41 am »
Best practice is to use a high impedance resistor divider + small capacitor to reduce the absolute maximum battery voltage to the level of internal Vref.
Use a at least 100k as R1 and a few dozens of nF. Since you'll not be sampling at Ksps the ADC impedance can be neglected.
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #16 on: July 22, 2015, 11:09:23 am »
Just an idea, if one power it directly from the battery without regulation couldn't one just measure the internal vref?
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #17 on: July 22, 2015, 11:38:10 am »
Best practice is to use a high impedance resistor divider + small capacitor to reduce the absolute maximum battery voltage to the level of internal Vref.
Use a at least 100k as R1 and a few dozens of nF. Since you'll not be sampling at Ksps the ADC impedance can be neglected.
A buffer cap on the analog input would reduce the source resistance the adc sees, but why would you want to reduce the battery voltage so that max battery voltage matches internal vref?  ???
Vref is 1.1 V so if Vcc is 5V you would only utilize 5% of the ADC range in the case of a single cell lipo battery like here?

EDIT: I see you can set AVcc to be the internal ref as well, so that makes sense, but one can also use Vcc as AVcc and then measure the value of the internal reference.
« Last Edit: July 23, 2015, 07:17:45 pm by apis »
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #18 on: July 22, 2015, 03:39:03 pm »
A low source resistance is only required for fast moving signals at high acquisition rates.
Not necessarily true.  The input leakage current will determine the maximum usable source resistance at low frequency or DC levels.
Yes, you have to take into account leakage currents and input impedances for just about any type of electronic input. My point was that you could go quite a bit higher than the recommended <10k source impedance in this particular situation, involving a slow moving (almost DC) signal and long intervals between sampling.

For instance, the ATmega328P and Atmega32u4 used in the most popular Arduinos both are specified to have a typical ADC input resistance of 100M.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Battery Monitor - Proper Way
« Reply #19 on: July 22, 2015, 03:51:28 pm »
No you cannot, omg, dude.

The low impedance needed is there for a reason. And as long as you can't change the sampling time much on AVR, you will measure rubbish!

the src impedance together with S&H circuit switch and the capacitance creates an RC circuit, which must be charged fast enough, fort the error to be small enough, usually calculated for an error of less than a LSB!

The interval in between taking samples doesn't matter. What matters is the sampling time, the time the sampling capacitor is connected to your voltage source.

The partial solution is to use external cap on the ADC input, if High-Z source.
« Last Edit: July 22, 2015, 04:35:49 pm by Yansi »
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #20 on: July 22, 2015, 04:22:48 pm »
The battery will go to a step up circuit to 5V and feed the atmega, I want to alarm the user when it get''s to a point that it should be charged again. As the processor might turn off due to the low battery I guess is better to put a resistor in series to to make sure that that case is also covered!
There have been some comments about alternate methods of powering the Arduino and monitoring the battery, but in case you want to stick the what you've stated above, note the following:

The difference in voltage between a LiPo cell at full charge and discharged is quite low (about 4.2V-3.2V=1V). To accurately determine that your battery has reached the desired "alarm" voltage will require your ADC reference to be quite precise a stable.

If you're using a voltage boost circuit to provide 5V Vcc and using Vcc as the ADC reference, and you're software calculates based on a 5V reference, the actual output voltage of the regulator circuit will have to be quite close to 5V (probably within 1%) to obtain an accurate enough battery reading. Otherwise, you may end up giving the "alarm" long before the battery needs to be charged, or too late.

If you can't guarantee a precise absolute known value for the supply/reference voltage, but for a given unit this voltage, though not necessarily exactly 5V, is always the same when the battery reaches the "alarm" voltage, you can calibrate each individual unit and store the necessary calibration values in EEPROM. You might want to do this even if you're making only one unit. For multiple units, each one will need it's own separate calibration, though
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: ca
Re: Battery Monitor - Proper Way
« Reply #21 on: July 22, 2015, 04:38:32 pm »
And as long as you can't change the sampling time much on AVR, you will measure rubbish!
You can change the sampling time on an AVR!

In single conversion mode the sample time is the time between when the last conversion ended and the start of the next conversion. As long as a given input is selected, the internal switch that allows charging of the sample/hold capacitor via the source is always on until it is opened to "hold" the voltage for the conversion. It then closes again immediately after the conversion. Therefore, the sampling time required to charge the capacitor can be infinite, as long at the voltage you're sampling doesn't change.
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #22 on: July 23, 2015, 07:27:54 pm »
Therefore, the sampling time required to charge the capacitor can be infinite, as long at the voltage you're sampling doesn't change.
I cant find anything about it in the datasheet but sounds reasonable, you assume the ADC isn't used for other things meanwhile though... I don't understand why you'd wan't to add more source resistance than necessary for protection (500 ohm), seems like it will only make life more complicated?
 

Offline apis

  • Super Contributor
  • ***
  • Posts: 1667
  • Country: se
  • Hobbyist
Re: Battery Monitor - Proper Way
« Reply #23 on: July 23, 2015, 07:31:58 pm »
My case I want to measure an alarm the user when a lipo battery (one cell) get's in a low voltage state.
An alternative would be to use the internal comparator, might be simpler if you just want an alarm. Then you need a voltage divider and set it so that battery min voltage == internal v ref voltage.
 

Offline UPI

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
Re: Battery Monitor - Proper Way
« Reply #24 on: July 23, 2015, 08:06:58 pm »
I use the following method to reduce the 5V to a lower value to be sent to the ADC through a 7.5k resistor. We do many reads while on the ADC input and do a bunch of  reads/mean to make sure we have a solid read. We also use a  precision 4.096 reference on the AREF pin.

I can't remember the exact voltage setting, but we set the TL431 to something like 3V and then monitor the remaining voltage dropped across the 499 ohm resistor. In other words, any change of the 5V signal is only reflected in the voltage drop across the resistor as the TL431 stays at a solid 3V.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf