Forum Index
Monitoring battery voltage

 
Author Message
FFMan



Joined: 09 Jan 2010

Posted: 27 January 2010, 9:20 AM    Post subject: Monitoring battery voltage

I think i've seen this talked about elsewhere so perhaps i just need pointing to a previous post.

I'm running a ZX24 from a 2 cell lipo and I want to warn the user when the lipo cell voltage falls to a certain point. I think i read somewhere that connecting 1 cell to an ADC pin is flawed and doesn't work but i don't recall why or what the solution was.

thanks
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 27 January 2010, 15:45 PM    Post subject: Re: Monitoring battery voltage

FFMan wrote:
I think i read somewhere that connecting 1 cell to an ADC pin is flawed and doesn't work but i don't recall why or what the solution was.
In order to read the value of an analog signal (the battery voltage) you must feed a signal that is proportional to the battery voltage to one of the ADC inputs. The only problem is what reference to use for the conversion.

The System Library function GetADC() uses the voltage on the Aref pin pins as the reference. On 24-pin ZX devices, the Aref pin is connected to Vcc so the net effect is self-referential. That's the part that doesn't work.

The solution is to use a reference that does not vary with the battery voltage. Fortunately, the AVR devices have an internal reference voltage that can be used as the reference. For ZX devices other than the 24-pin series, you can also use an external reference voltage.

There is an application note on the topic: AN217 - Measuring the Power Supply Voltage.
Back to top
FFMan



Joined: 09 Jan 2010

Posted: 02 February 2010, 18:49 PM    Post subject:

I'm still a bit confused.

I have a 2 cell lipo, delivering say 7.1v to the regulator on board the zx24, so the zx24 will always have 5v.

I can monitor 1 cell of the lipo which will vary between 3v (my shutdown value) and say 4v when fully charged on an adc pin can't I and get an accurate enough reading ?

thanks
Back to top
GTBecker



Joined: 18 Jan 2006
Location: Cape Coral

Posted: 02 February 2010, 20:13 PM    Post subject:

FFMan wrote:
I can monitor 1 cell of the lipo which will vary between 3v (my shutdown value) and say 4v when fully charged on an adc pin...

You can do that, yes, but you won't be able to accurately determine the 3v level. If you wait until the lower cell voltage is 3v, the two-cell voltage should be 6v - which is below the ZX-24 regulator dropout voltage. Consequently, the processor (and thus, Aref) will be supplied with less than 5v so the ADC reading will be falsely high, perhaps never yielding the apparent 3v level you seek. If you want to look at just the lower cell, shutdown no lower than 3.5v.

Alternatively, you can use a resistive voltage divider to reduce the nominal 7.2v of two cells to a usable level. To accurately measure the battery level while charging, the divider should produce no more than 5v at the ADC pin when the two batteries are under charge (usually 8.4v for LiPo). I have a current project that does exactly that; it uses 56k over 82k (56k from 7.2v to the ADC pin, 82k from the ADC pin to ground. The resulting voltage range at the pin is ~4.1v-5v, corresponding to 7.2v-8.4v at the batteries. In this case, you should trigger your shutdown no lower than 7v since, as above, the regulator will not operate properly below that level.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 02 February 2010, 21:56 PM    Post subject:

GTBecker wrote:
[Y]ou should trigger your shutdown no lower than 7v since, as above, the regulator will not operate properly below that level.
I haven't studied the behavior of a typical linear regulator when the input voltage drops below the regulated level plus the dropout voltage. My suspicion is that the output voltage follows the input voltage down (less the dropout). Consider, for example, a 5 volt regulator with a 1.7V dropout voltage. My guess is that with a 6 volt input the output would be approximately 4.3 volts. It is probably true that the output voltage would vary, perhaps significantly, depending on the load.

Given that the 14.7MHz ZX devices are operating within spec down to about 3.55 volts, if the conjecture above is correct you may be able to exploit that fact by detecting an output voltage from the regulator below 5 volts. Of course, you would have to use an external reference voltage or one of the internal reference voltages for this use case. Whether this strategy would work or not depends on how the regulator reacts while under load when it loses regulation.
Back to top
GTBecker



Joined: 18 Jan 2006
Location: Cape Coral

Posted: 14 February 2010, 5:47 AM    Post subject:

FWIW, I just monitored the unregulated and regulated voltages from a partially-charged 2-cell 500mAh LiPo pack, which started at 7.7v, regulated to 4.99v. With a ~100mA average load, (ZX-24a, a few LEDs, a Bluetooth module and an occasionally-pulsed cellphone vibrator motor), the pack fell to 7.4v within 30 minutes and stayed pretty flat for about five hours, then started to fall again.

For another 30 minutes or so, the ZX-24a-regulated supply remained at 4.99v until the pack fell to 6.7v, and code correctly indicated the pack voltage, via a 100k/100k voltage divider from the pack to an ADC pin, down to that point. When the pack had reached 6.0v the regulator output was 4.35v; code falsely indicated the pack was still at 6.7v.

So, using the 5v Vref - at least with this machine and ambient conditions - code can correctly measure its unregulated Vin supply down to ~6.8v, below which the indication will falsely plateau.
Back to top
GTBecker



Joined: 18 Jan 2006
Location: Cape Coral

Posted: 14 February 2010, 20:28 PM    Post subject:

While on the subject, BTW, I've found a rechargeable LiPo battery that has been very handy for a portable project and is relatively inexpensive; it is intended for a micro helicopter. The battery has the same footprint as a conventional 9v battery but is a little shorter, comes with a two-pin 0.1" female load connector, and a three-pin charge connector that permits cell-balancing charging with a matching charger. Rated 500mAh, it can produce bursts of 10 Amps. Like most 2-cell LiPos, when fully-charged it produces 8.4v and is said to be discharged at 6.0v; the discharge curve is very flat at ~7.4v for most of that period.

http://www3.towerhobbies.com/cgi-bin/wti0001p?&I=LXVJE4&P=M
Matching charger: http://www3.towerhobbies.com/cgi-bin/wti0001p?&I=LXVJE5&P=V



Both, and similar competing batteries, can be found on ebay for less.

Another similar 500mAh battery is less expensive, but larger and lacks cell balancing: http://www3.towerhobbies.com/cgi-bin/wti0095p?FVPROFIL=++&FVSEARCH=va1016&search=Go
Back to top
FFMan



Joined: 09 Jan 2010

Posted: 17 February 2010, 22:43 PM    Post subject:

I've decided to measure the voltage on 1 cell of my lipo using a divider using the code from AN-217.

However, if i move this code to a 328n there doesn't appear to be a port A, can the code be adjusted to use port C. I did try and consult the Atmel datasheet but its not so clear to me.

Can anyone assist please ?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 17 February 2010, 23:12 PM    Post subject:

FFMan wrote:
[C]an the code be adjusted to use port C.
The only reference to PortA in the code for AN-217 is in a comment and it is with respect to the ADC channel number. The channel numbers correspond to the bit numbers of the port containing the analog inputs (i.e. 0-7).

On a ZX-328n, the ADC channels are on PortC and are numbered 0-5. The code can be used as-is; just choose the channel number corresponding to the bit of PortC to which you're feeding the analog signal.
Back to top
FFMan



Joined: 09 Jan 2010

Posted: 18 February 2010, 16:06 PM    Post subject:

thanks - i can now get the 328 to measure the voltage but the scaling is quite different to the zx24a

same code, same power supply etc etc

1v on 328 gives a value of 2.398
1v on zx24 gives a value of 1.382

what is the reason for this ?

thanks
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 18 February 2010, 16:51 PM    Post subject:

FFMan wrote:
what is the reason for this ?
Here's where it pays to take a look at the datasheet. The top two bits of the ADMUX register select the reference for the conversion on both the mega644 and the mega328P. However, the mega644 has two reference voltages available and having the top two bits of ADMUX both be 1 selects the 2.56V internal reference. In contrast, the mega328P has only one internal reference (see the attached datasheet excerpt) and the same value in the top two bits of ADMUX selects that reference - a 1.1V internal reference.

This means that on the mega328P, you'll need to use a different divider ratio to keep the measured voltage below 1.1V. Also, the Aref pin requires an external capacitor (as mentioned in the datasheet). The ZX-24 has this capacitor on-board but you'll have to add your own with the ZX-328n. A ceramic capacitor with a value of 0.01uF or 0.1uF will be suitable.



mega328P_ADMUX.jpg
 Description:

Download
 Filename:  mega328P_ADMUX.jpg
 Filesize:  92.04 KB
 Downloaded:  47 Time(s)

Back to top
FFMan



Joined: 09 Jan 2010

Posted: 18 February 2010, 17:20 PM    Post subject:

thanks for the response.

the capacitor is already in place as this is shown on the recommended psu diagram.

the 328l will be the same as the 328n in this regard won't it ?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 18 February 2010, 18:00 PM    Post subject:

FFMan wrote:
the 328l will be the same as the 328n in this regard won't it ?
Yes. The underlying processor is the same, the ZX-328L just runs at a lower frequency thus allowing a lower supply voltage.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008, 2009, 2010 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group