Shop OBEX P1 Docs P2 Docs Learn Events
Measuring battery voltage — Parallax Forums

Measuring battery voltage

mosquito56mosquito56 Posts: 387
edited 2008-01-17 22:51 in Propeller 1
·The input of the adc chip is 5v. How do I measure the voltage on the 9v battery. Will a simple divider work?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hmm, "If you can't say something nice, don't say anything at all"

······· "No such thing as a dumb question" unless it's on the internet
········"What happens in Vegas ends up on the Internet"

Technologically challenged individual, Please have pity.

Post Edited (mosquito56) : 1/16/2008 10:16:15 PM GMT

Comments

  • RaymanRayman Posts: 14,162
    edited 2008-01-16 23:14
    Divider will work, but the ADC chips sold by Parallax seem to all have a fairly low input impedance, ~10kOhms. So, you probably would want to measure across a 1k resistor or less... Maybe use two to divide the voltage in half...
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-17 00:57
    I was not aware of the low impedence on the inputs, time to start using the 470 input resistors. Thanx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "If you can't say something nice, don't say anything at all"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • DgswanerDgswaner Posts: 795
    edited 2008-01-17 03:07
    I spent about 20 minutes trying to figure out what is wrong with my code to finally realize it is my battery is that my battery is low and causing problems. so I was wanting to do the same thing.

    for those who haven't used a ADC or divider before... Me. could you explain how it actually works? what is the out put of the ADC. is it a pulse or is it resistance I though the way to read voltage was by measuring the time to charge a cap?

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-17 03:21
    Mosquito, I'm doing something, again, very similiar. I need to measure the voltage on a very small capacitance and if I use a low resistance voltage divider, it will drain the cap too quickly. Because of this, I can't use a low impedence ADC. Instead, what I use is a high resistance voltage divider(~1MOhm) and connect the output to an opamp configured as a voltage follower. Basically, in this setup, the opamp has a very high input impedence so it doesn't cause a voltage drop, and in turn an error in the reading. I'll talk to you sometime on MSN about this. I think this would help in this situation too because if you have a voltage divider(I'm assuming to step down the 9V scale of the battery to the 5V scale of the ADC), it will continually drain the battery even though it's a small amount. With this method, 1Mohm is negligable in regards to current draw. The only real current draw is the ADC itself now. The opamp requires on the order of 10's of micro-Amps to operate when the output isn't being sourced.

    Like I said, we'll talk on MSN.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-17 03:40
    Dgswaner,

    A voltage divider is one of the most simple circuits. It consists of basically, 2 resistors connected in series. One end of this "chain" of resistors is connected to ground, while the other is connected to the voltage you want to "divide". The output of this is located in the middle, between the two. If the resistors are equal values, e.g. 1K and 1K, the output will be about half of the input voltage. I say "about half" because when you put any measuring device up to the ouput, it pulls off some current from the divider, which causes the voltage to drop. A common analogy is water pipes. Let's say you have a narrow pipe with a pressure gauge right in the middle(or where ever, but in the middle for this). If you connect the input of a pump to one end, and the ouput of the pump to the other, you will have water flowing through the pipe. Let's say this pipe is surgical tubing... The pump is a 500HP industrial water pump that "can" deliver 5000 gallons per minute. you're probably only taking 1/2 a gallon per minute and the pressure is 50PSI at the input of the pipe(relative to the exit end). Te pressure at the exit end, relative to the exit end, is obviously zero. Now, the pressure difference is because there is a flow through the pipe, but the pipe walls cause friction on the water flow, which causes a resistance to the water flow. This resistance turns into a pressure. If you think about it, if one end of the pipe is 50PSI, and the other is 0PSI, then at some point inside the pipe, the pressure is 25PSI(and every value between 0 and 50 for that matter). Because the tubing is uniform, then the pressure decreases at a uniform rate from one end to the other. Since it's uniform, then the middle of the pipe will "drop" half the pressure. The gauge on the pipe will read "25PSI".

    Now, suppose you give the water an alternate route to flow from at the middle of the pipe by the gauge. Let's say you give it another piece of tubing to flow through. Now, the gauge should read less than 25 PSI because it has less resistance after it gets to the gauge. This is how a voltage divider works.

    If you have two resistors and the first one is connected to the voltage source, and then connected to the second, which is connected to ground, you will get current flowing like the water. Only so much current can flow through the first resistor, even if IT is connected to ground as well. As the current flows from the first, into the second resistor, it creates a slight back pressure(voltage) at the point where they join. This voltage is the result of the ratio of the two resistances. If you want to find the voltage produced by a set of resistors, it's like this...

    V_out = V_in * (R2/(R1 + R2) )
    That is, with R1 being connected to the input, and R2 connected to ground and both joined at the ends. That's a voltage divider. Simple.

    As for ADC's, there are many different types and methods of how they do it, but an ADC is just a chip that converts a voltage reading into a binary value. Some have a bajillion pins and functions and even it's own crystal and micro processor, while others are simple 8 pin devices that just need a chip select, data line, and a clock line. You can get a pretty good 12bit ADC from TI as a free sample(5 max per order... don't abuse it). This is the one I use and I've written some code as a "driver". No cog required. Just hook it up, and call the "getvalue" command and it returns the value(0-4096). In code, you then just convert this to a 0-5v scale if you need to.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-17 05:49
    Dgswaner,
    ·Since i got my first adc working today i guess i can give it a shot at what they are. The adc chip takes an analog signal(voltage) and converts it to binary numbers that the prop can understand.
    · You have to read the datasheet to find out what signals need to do what to talk to the chip. This is an example from my 0831 from parallax.
    ·· 1. Send hi then low signal to CS. This turns the chip on
    · 2. Send a clk signal to another pin. When the pulse of the clock goes neg or pos depending on the chip. The adc chip sends a binary 1 or 0 that the prop is looking for on another input pin. This pin is the DO "data out"
    · 3. you repeat number 2·the required times. 8 bit=8 times, 12bit=12times, etc.
    · 4. you "read the data", msb first in this case.
    ·repeat 8
    ··· ·if ina[noparse][[/noparse]pin]:=1
    ····· ··calculate=1
    ···· else
    ······ ·calculate=0
    · calculated:=calculated+calculate
    ··calculated=calculated*2·· 'or just shift the bits 1 left.
    print.bin(calculated)

    Now convert this number to something that makes sense: I.E. temperature, salinity, etc. This is a book in itself.

    Read the tutorials and do as many as you need to until you understand what is going on. Try to find the "Basic analog to digital" tutorial. It's written for stamp but the electronics will be alot of help. They cover the adc0831 which is a very primative chip. I say primative because the parallax store says they are on their last run and will be discontinuing the chip.

    Hope this helps. I am sure someone will elaborate and critique this but that is my hope as that is how you learn.

    Have a great proping day!!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.

    Post Edited (mosquito56) : 1/17/2008 6:18:11 PM GMT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2008-01-17 12:00
    Too much thread to read but I'll throw in my2cents worth. When an ADC is described as low-impedance input it doesn't mean you have to buffer it with an opamp or use low value resistors. Basically the ADC input takes a sample by charging a small internal capacitor which can be a problem if your input circuit can't drive it without dropping voltage. The solution is simple, just add a capacitor to the input circuit which provides the low impedance for the adc when it takes a sample. This is especially true of low bandwidth type inputs such as battery monitors. But why all the fuss with ADC chips when you can do the same thing with an RC network? [noparse]:)[/noparse]

    *Peter*
  • RaymanRayman Posts: 14,162
    edited 2008-01-17 14:06
    Peter: That (adding a cap) sounds like a very good solution for battery voltage monitoring...
  • RaymanRayman Posts: 14,162
    edited 2008-01-17 17:12
    The MAX1270 doesn't work that way though...· It has fixed resistors to ground at the input:
    520 x 524 - 19K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2008-01-17 22:51
    Hi Rayman,
    The max1270 does have resistors to ground but the diagram shows that this presents around 21K of load which is no real load anyway. Another way to look at this is to factor in the input resistance as part of the external divider in that it forms the lower divider so that you just feed a resistor (around 100k) from the battery directly into the input. I would still add a capacitor of at least 0.1uf or so.

    *Peter*
Sign In or Register to comment.