Shop OBEX P1 Docs P2 Docs Learn Events
MCP3208 and Battery voltage measure. — Parallax Forums

MCP3208 and Battery voltage measure.

jtilghmanjtilghman Posts: 67
edited 2013-04-12 18:01 in Propeller 1
I am trying to use a MCP3208 to measure the battery voltage for a project I am building using a propeller USB board.

My problem comes in this, as best as I understand it the MCP3208 will give a reading 0 to a max 4096 based on a given voltage VS its reference voltage.

How do I measure a battery voltage, using the battery as a reference voltage all the while powering said circuit and while the battery voltage is falling from being used ?

Would i use something like a voltage booster to maintain a steady max reference voltage ?

Thanks,
jt

Comments

  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-04-07 23:05
    You want to use a stable 5 or 3.3v vref to the adc. Then tap a wire of the batteries posotive terminal, run that wire to a voltage divider made from two resistors. Once that is done you would run the output voltage from the divider to the mcp3208 input and multiply the reading by the ratio of your voltage divider. This is the simplest way, more components such as an opamp buffer between the adc and divider will provide higher accuracy.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-04-09 10:56
    What he said: put in a voltage reference (I use 2.5V, since I run at 3.3V -- but sometimes less). Once you run the voltage through the voltage divider, you will get a value on the ADC channel. You can then do some simple multiply math to calculate the digital value to a usable format. With my setup, I multiply my 10-bit value (I'm using an MCP3008 -- but it is identical for the 12-bit ADCs) by 2.0752 and it returns the actual voltage multiplied by 100. So the output of the function is 1200 if the voltage into the circuit is 12.00 volts. I'm running a range of 0 - 21.5V, so I get a precision of 0.02V, but with the 12-bit ADC, you could run the same range and get a precision of 0.005V.

    With some more information, like what your expected range of input voltage is, what your reference voltage is, and what the output (format/precision/etc) you want is, we can help you more with a circuit and some math.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-09 12:46
    Thanks for the replies.

    I would love to show you a circuit or two, but i haven't really drawn anything up yet.

    What I can tell you is that I am using this battery: http://www.batteryplex.com/powersonic.cfm/m/PS-640-F1?gclid=CPGIh_-fvrYCFQfqnAodazMA4Q with this prop board: http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/CategoryID/73/List/0/SortField/0/catpageindex/2/Level/a/ProductID/878/Default.aspx

    I am not sure the voltage divider, I know I need to get the battery voltage down in a range for MCP3208. But I am not to sure why i couldn't just run a tap from the battery to the MCP3208 Vref and use 6 volts as the ref. then 4096 would be battery full and 0 would be flat dead. Also not sure where the usable voltage level would be, the prop only needs 3.3 to run but my motors (Stingray Chassis and Motors) can use up to 7.2.

    My 1st time with these types of questions so that's why i am asking here.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-04-09 13:03
    The MCP ADCs only allow the Vref to be a max of the Vdd, which has a max of 5.5V. You would have to operate the ADC at 5.5V, along with the Vref. The problem is that precision is lost if you don't have a "precise" reference (these are cheap and usually come in 4.096V or 2.5V --- often used for 5V ADCs and 3.3V ADCs respectively). That's only only good way to come up with an absolute voltage.

    That battery is rated at 6V, but that is just its nominal voltage, they can go higher (probably ~7.2V is "full").

    You can operate the ADC at 3.3V (same as the Propeller), and if you got a 2.5V precision reference, then ran this voltage divider: BAT-R1-R2-GND. Where the ADC channel is connected between R1 and R2, and R1 is 22K-ohm and R2 is 10K-ohm, You would put a load on the battery of only 0.2mA, and could measure the battery voltage from 0V to 8V, and have a precision of 2mV.
    Once you get the ADC channel's value, you divide by 512 to get the actual voltage of the battery. The actual math will be a little different because you will be working with integer math on the Propeller.
    An example would be if the channel's value is 2100, the battery's voltage is 4.10V.
  • kwinnkwinn Posts: 8,697
    edited 2013-04-09 22:09
    Bobb Fwed is right, you need a stable reference to get an accurate reading. For measuring and possibly controlling the charging of a nominal 6V battery the 3.3V supply voltage should be adequate if you use a precision regulator for that supply and measure the actual power supply voltage to use in your calculations. A voltage divider using a 3.3K and 2.2K of at least 1% precision would give you a range of 0V to approximately 8.2V, which should be enough to measure the charging voltage.

    To get the best possible result with this circuit you could measure the battery voltage (fully charged) with a multimeter and use that along with the measured voltage from the ADC to obtain the most accurate calibration factor.
  • RaymanRayman Posts: 14,665
    edited 2013-04-10 02:57
    I don't know... I'm not sure you gain much with the extra voltage reference in this case...
    Do you really need perfect resolution looking at the battery voltage?
    And, if you use a voltage divider, you'd have to use really good resistors to make it accurate and not sensitive to temperature...

    I think I'd start with just use the Prop's 3.3 V Vdd as reference and two regular 10k resistors for the divider..
  • kwinnkwinn Posts: 8,697
    edited 2013-04-10 15:24
    @Rayman

    I agree that for battery charging circuits using the 3.3V regulated supply is more than adequate, and 12 bits is overkill. Even an 8 bit ADC would do the job. On the other hand a 12 bitter is not much more than an 8 bitter so for low volume or one of projects it may be better to stock fewer parts even if they are over spec for some projects.

    For the divider two 10K resistors will give a range of 0 to 6.6V which may not be quite enough if the purpose is to control the battery charging.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-10 21:38
    Well i think I have given incorrect information.

    My goal here is only to know and alarm the robot that the battery is low, not to recharge it. This is a lead acid gel cell and I don't feel like it's a good idea for me to try and build a charger at this stage.

    I have a store bought charger to recharge the battery with for now.

    The reason for using the 12 bit ADC is simple, its what I have on hand and I will be using the other inputs for other sensors at some point.

    I was thinking of getting fancy and having a LED bar graph display the running voltage like a gas gauge.

    But I will take just being able to tell when the battery needs a recharge, at some point when I understand better I would like to current readings for the motors and other senors for kind of robot health check dashboard.

    Hope this puts things into scope.

    Thanks,
    JT
  • kwinnkwinn Posts: 8,697
    edited 2013-04-11 18:45
    That information simplifies this part of the project. Do what Rayman suggested and use the 3.3V supply as the reference and use 2 10K resistors of at least 1% precision to reduce the battery voltage in to the ADC by half. That will give you a 0 to 6.6V range and 1.612mV or 1612 uV per bit. By using 1612uV per bit the calculations can be done with integers instead of floating point.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-12 08:26
    Just ordered some 1% 10k's.

    Thanks, i will let you all know how it goes.

    JT
  • kwinnkwinn Posts: 8,697
    edited 2013-04-12 09:34
    jtilghman wrote: »
    Just ordered some 1% 10k's.

    Thanks, i will let you all know how it goes.

    JT

    Good luck with the project.

    BTW, if you only want to use the ADC and a led bar graph as a fuel gauge there is no need to convert the reading to a voltage. Store a table with one value for each led in the bar graph and light that led when the reading is equal to or greater than that value, and less than the next value if you want only one led lit at a time.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-12 11:01
    Wouldn't I still need to convert as the incoming voltage would be too high for the ADC ?
  • RaymanRayman Posts: 14,665
    edited 2013-04-12 13:23
    Just pick resistor values for your divider so that the biggest voltage you expect is divided down to less than 3.3 V...
    If you're looking at 12 V, maybe 15 V is the biggest you could expect...
    If you use a 2k and a 10k resistor, that should bring it down low enough...
  • kwinnkwinn Posts: 8,697
    edited 2013-04-12 18:01
    You still need the resistor divider to bring the voltage in to the ADC down to a maximum that is no higher than the ADC reference voltage. What I meant was that you do not have to program the microprocessor to calculate the actual battery voltage from the raw data out of the ADC. You can use the raw data directly from the ADC to decide which led in the bar graph to light.
Sign In or Register to comment.