SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By kaiki
#16266
I have a small battery (3.3V) operated circuit that I want to add a voltage level feature to.

I want to occasionally measure the battery voltage level using the MCU's ADC. The adc input pin is high impedance however I don't want to directly provide a 3.3V connection to it all the time as it will drain the battery fairly quickly. I was wondering if there are any small switches out there which I could control through another IO line which can be kept open for the most part but can be switched on for a short time when trying to calculate the voltage level.

Important factors for this part will be size and cost, cheap as heck and 'VERY' tiny as I'm severely restricted by board space.

Any ideas?
By busonerd
#16267
er, high impedance means it will draw almost no current, especially compared to the mcu power supply :P.

Something else you'll have to deal with is your reference voltage - where are you going to get that from?

--David Carne
By kaiki
#16271
Something else you'll have to deal with is your reference voltage - where are you going to get that from?
I was thinking a direct VCC connection right from the batt. (alternative strategies most welcome)

I'm using a HCS08 which seems to say High impedence leakage current of min 0.025 upto 1uA.
I'm hoping that the off state current of a switch will basically be 0 and quiescent currents would be lower.
By busonerd
#16275
er, if you're reference voltage is off the battery, and you're measuring the battery.... think about it :P

--David Carne
By kaiki
#16280
oh right!!
hmm, so how do I measure how much 'juice' is left in the battery..
basically I need to know roughly (+- 10-15% accuracy) how much charge is left in the battery?
By busonerd
#16284
First, check if your micro has an optional built in voltage reference. If so, then you can just use that and divide the incoming batt voltage to be less then the reference voltage.

Otherwise, you need to use some sort of external voltage reference + a voltage divider. A zener + resistor is an easy way to do it, but then you'll need to be able to switch that whole chunk of circuit because that will eat lots of current. Maybe just do the whole measurement + voltage ref bit and connect them to vcc through a p-chan fet. Then you can just drive its gate low to enable the measurement chunk, or drive it back high to disable it all and lower current consumption.

--David Carne
By kaiki
#16290
HCS08 GT/GB series doesn't seem to have an internal voltage reference.

Thank you for the other info, i'll check..
By bikeNomad
#17668
kaiki wrote:HCS08 GT/GB series doesn't seem to have an internal voltage reference.

Thank you for the other info, i'll check..
That series has a VrefH (and VrefL) input pin for the A/D reference. You don't say what voltage your micro is running at, but you could either feed VrefH from a voltage reference source (and not waste an analog input pin) or connect the reference output to an analog input. Here's what you can do:
  • get a voltage reference IC (typically 3-pin devices, some are 2-pin and require an external resistor) whose output is less than your lowest supply voltage and which will still produce a good output voltage at that low supply voltage
  • arrange to power the reference from an output pin (so you can turn it off when not needed)
  • either connect the output of the reference to VRefH or to an analog input pin
  • Connect VRefL to analog ground
  • If you've connected the reference to an analog input pin, connect VRefH to analog Vcc
  • Connect a 2-resistor voltage divider to the output pin that you're using to power the voltage reference from. Make sure that its output voltage will not exceed the voltage from the reference.
  • Connect the common point of that voltage divider to another analog input pin
Now you can read the ratio of the battery voltage to the reference voltage. This will take either one (if your reference is feeding VRefH) or two (if the reference is connected to an input) ADC readings.

As far as knowing how much charge is left in the battery, voltage alone is not terribly accurate. What kind of battery? In the case of lithium ion batteries, the voltage stays more or less constant for a long time, so you can't really get a feel for percent remaining (until you're almost empty, that is). Likewise for NiMH batteries; you can do a little better on alkalines and reasonably well on lead-acid batteries.

Refer to the battery manufacturer's data sheet for voltage vs. capacity curves; the flatter the curve the worse your accuracy will be.

Also note that battery voltage is quite dependent on temperature; if you have to operate over a wide temperature range this can further degrade your accuracy.
User avatar
By roach
#17998
I'm trying to figure out the same thing right now. Refernce voltage to the uC will be through a 3.3V buck-boost converter, and I guess i'll stick the raw battery voltage across an analog IO (via a voltage divider).

Problem is: I don't want to be draining the battery when I'm not measuring the voltage. If I set fairly high values for R1 and R2 of the voltage divider (say 1M, or something), will there still be enough current for the uC to detect anything on the analog IO? (I'm using an LPC2148)
By bikeNomad
#18001
roach wrote:I'm trying to figure out the same thing right now. Refernce voltage to the uC will be through a 3.3V buck-boost converter, and I guess i'll stick the raw battery voltage across an analog IO (via a voltage divider).

Problem is: I don't want to be draining the battery when I'm not measuring the voltage. If I set fairly high values for R1 and R2 of the voltage divider (say 1M, or something), will there still be enough current for the uC to detect anything on the analog IO? (I'm using an LPC2148)
Well, if you drive the voltage divider from an output pin you won't have this problem. With high-value divider resistors, the output resistance of the micro won't really affect the readings. Typical micros have very high A/D input resistances (essentially a low-leakage capacitor), so if you use high value resistors it'll still work.
User avatar
By roach
#18009
bikeNomad wrote:Well, if you drive the voltage divider from an output pin you won't have this problem.
hmmm... But then, instead of battery voltage, I'll be measuring my regulated reference voltage, which is not very useful.

Or do you mean "drive", like through a transistor?
User avatar
By ohararp
#18434
Roach, are you going to be using a 3.3V regulator (buck/boost). Since you know that you will always have 3.3V on the uP. Therefore go ahead and measure teh voltage at the battery seperately. Add a 10k resistor in series and you should be golden. You won't be drawing that much current for this a/d sampling.
By reklipz
#18437
if your using a LiPo or any other 3.7V bat. the sampling amperage is:

With 10K Resistor:
3.7V / 10,000Ω = 0.00037A or .37mA or 370µA
2.75V / 10,000Ω = 0.000275A or .275mA or 275µA

With 100K Resistor:
3.7V / 100,000Ω = 0.000037A or .037mA or 37.0µA
2.75V / 100,000Ω = 0.0000275A or .0275mA or 27.5µA

So, anything wrong with a 100K resistor?

thats like .37mA MAX with 10K, per sample... so say .25s per sample? (its probably a lot less, but this whole post is just junk anyways :shock:)
Thats 0.0256944444µAh(.0000256944444mAh) * num samples...

or is this completely wrong, and the current draw is constant whether or not you are sampling the ADC line?
User avatar
By roach
#18438
ohararp wrote:Add a 10k resistor in series and you should be golden. You won't be drawing that much current for this a/d sampling.
So, wait. Just connect the AIO pin directly to the battery? Is that "safe"? Will the current draw be constant, or will the uC only draw current when I sample the IO? (I'm using an LPC2148).
User avatar
By ohararp
#18447
I can say that I did this and freakish things happened! Current was following through the uPic causing it to heatup alot. Put a 10K or 100k resistor in series (current limiting) and you should be fine.