Shop OBEX P1 Docs P2 Docs Learn Events
ADC0831 Based Battery Monitor - Doesn't work! Help! — Parallax Forums

ADC0831 Based Battery Monitor - Doesn't work! Help!

everesteverest Posts: 141
edited 2009-03-13 01:06 in BASIC Stamp
I just updated the title because it turns out the voltage divider wasn't the problem. . .looks like I've got the ADC0831 wired up incorrectly at the current time. I'd REALLY appreciate any help with this. . .I'm lost and dealing with high currents here, so I don't want to blow anything up (including myself!) Thanks!

Original Message ******

I know fully well that this has to be trivial question, and once again I've searched and searched and found multiple schematics, none of which seem to work properly! I've built the voltage sensor outed in the "Stamps in Class" and now I need to reduce a car battery to a voltage that's measurable by the program. . .the first step is to reduce the voltage flowing into the ADC 0831 so that 15v = 5v. And I have absolutely no idea how to do that. . .I've got buckets of resistors but I can't figure this one out [noparse]:([/noparse]

Can someone help me out?

-Jeff

Post Edited (everest) : 3/12/2009 5:39:54 PM GMT

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-03-12 05:52
    everest,

    Google "Voltage Divider"

    http://en.wikipedia.org/wiki/Voltage_divider



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • everesteverest Posts: 141
    edited 2009-03-12 06:25
    Okay, maybe I'm asking the wrong question. . .I used a calculator I found after Googling earlier that and determined that 22k and a 11k resistor would do the trick. I don't have an 11k resistor so I just put a 10k, a 1k, and a 22k all in series and tap + voltage between the 22k and 1k resistor. My battery is at 12.77 volts so I'm getting about exactly 4.25. . .about what I would expect.

    Here's the problem though, I have wired up my ADC0831 just like the example in "Analog to Digital Conversion" Stamps in Class .pdf available here, except that I've rewired pin 2 (vin+) to connect in between the pair of 10-1k resistors and the 22k resistor. I also connected pin 3 (vin-) to the battery ground (I removed both from the stamp circuit obviously). I'd expect to get 4.25volts reported by the program, but instead it's bouncing around wildly from 3.6 to 4.0 or so. . .it's just all over the place.

    Any suggestions on what I've done wrong? I think I actually have the voltage reduction part correct. . .so my problem must be elsewhere. . .?!?

    -Jeff
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-03-12 06:29
    Boy-O-boy, is that hard to visualize. Post a schematic?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • everesteverest Posts: 141
    edited 2009-03-12 06:48
    I don't have any software to build a "real" schematic, but I've done my best with Photoshop and PowerPoint. Sorry, this project is making me feel just as dump as a post! (Updated with accurate schematic per Bean's questions. . .Thanks Bean!)

    -Jeff

    Oh, and at this point I'm literally running the BS2 code right out of the ADC "Stamps in Class" lesson:

    '
    [noparse][[/noparse] Title ]
    ' Basic Analog and Digital - PL3_1R0.bs2
    ' Program Listing 3.1 Revision 0.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] Declarations ]
    adcBits VAR Byte
    v VAR Byte
    r VAR Byte
    v2 VAR Byte
    v3 VAR Byte
    '
    [noparse][[/noparse] Initialization ]
    CS PIN 0
    CLK PIN 1
    DataOutput PIN 2
    DEBUG CLS 'Start display.
    '
    [noparse][[/noparse] Main Routine ]
    DO
    GOSUB ADC_Data
    GOSUB Calc_Volts
    GOSUB Display
    LOOP
    '
    [noparse][[/noparse] Subroutines ]
    ADC_Data:
    HIGH CS
    LOW CS
    LOW CLK
    PULSOUT CLK, 210
    SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
    RETURN
    Calc_Volts:
    v = 5 * adcBits / 255
    r = 5 * adcBits // 255
    v2 = 100 * r / 255
    v3 = 100 * r // 255 '.. new line
    v3 = 10 * v3 / 255 '.. new line
    IF (v3 >= 5) THEN v2 = v2 + 1 '.. new line
    IF (v2 >= 100) THEN '.. new line
    v = v + 1 '.. new line
    v2 = 0 '.. new line
    ENDIF '..
    RETURN
    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
    DEBUG CR, CR, "DVM Reading: " '.. new line
    DEBUG DEC1 v, ".", DEC2 v2, " Volts" '.. new line
    RETURN

    Post Edited (everest) : 3/12/2009 3:26:41 PM GMT
  • Craig EidCraig Eid Posts: 106
    edited 2009-03-12 07:10
    Jeff,

    The jitter in the ADC reading indicates that you have noise in the system and this is typical in an automotive application. Add a filter capacitor and this should solve the problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Craig Eid

    www.TriadRD.com
  • everesteverest Posts: 141
    edited 2009-03-12 07:24
    Hi Craig,

    This is not an automotive application, I'm monitoring a charged AGM battery right now with no load attached. . .it should be extremely clean. I think the issue is that I may have Vref wired incorrectly. I believe it may need to tie into the 12v side, but I'm not exactly sure how. . .that pin is used to "bias" the IC, so maybe it needs to be attached to the positive terminal of the 12v battery. I need to figure this out before I try that though, otherwise I'm sure I'll release the magic blue smoke. . .

    -Jeff
  • BeanBean Posts: 8,129
    edited 2009-03-12 11:21
    Jeff,
    I assume the "220K" in the picture is really a 22K ?
    You have the resistors reversed. You need the 1K and 10K on the LEFT side (connected to the - terminal) and the 22K on the right side (connected to the + terminal).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • everesteverest Posts: 141
    edited 2009-03-12 15:21
    Hi Bean,

    Shoot. . .yea, sorry those are mistakes in my schematic, not my actual circuit. I checked everything with my volt meter before hooking it up. Attached is an updated schematic that should be correct (in terms of what I'm actually doing).

    Note that this does not work at all as I expect. . .how can I get this darn thing to read the voltage off that battery?!?! Help!

    -Jeff
  • JonathanJonathan Posts: 1,023
    edited 2009-03-12 15:51
    Are -Vref and GND tied together? For your application, all grounds should be common and the -Vref pin tied to ground as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • everesteverest Posts: 141
    edited 2009-03-12 16:58
    Right now Vref- and GND are both connected to the STAMP Board of Education circuit. In the schematic VDD and VSS refer to the STAMP Board of Education I'm using.

    So I need to connect all of those directly to the 12v system? I have a strong fear that that would blow something up, but let me know if I'm wrong on that please. I thought that the ADC0831 needed 5v in power, also I though the STAMP pins needed to be connected to the STAMP VDD to work properly. . .this looks like it would ground out the pins against the 12v system rather than the 5v STAMP power system. Can I mix power like that?

    Help! I really really need to get this working by the weekend so I can install this sucker in my observatory. Thanks!

    -Jeff
  • JonathanJonathan Posts: 1,023
    edited 2009-03-12 18:58
    Jeff,

    The - side of the battery should be connected to the ground (VSS) of the Stamp, and the GND and -Vref on the ADC should be connected to ground (VSS). The positive side of the battery should go to your voltage divider and the input side of the voltage regulator for the Stamp.

    EDIT: Just to make sure, and to answer your question, the ADC does need a regulated 5V.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot

    Post Edited (Jonathan) : 3/12/2009 7:05:49 PM GMT
  • everesteverest Posts: 141
    edited 2009-03-12 19:27
    Jonathan,

    Thanks again for your help with this! I've taken what you've said and re-worked my schematic to look like the attached. Basically this combines the STAMP 5v ground and the 12v battery ground, so that it's a common ground. The power voltage for the ADC0831 come from the STAMP circuit (+5v) but all grounding is now done to the combined STAMP/battery common ground.

    Could I get you to have a look at the attached schematic and tell me if I've gotten it right this time? I'm dealing with sufficient power to explode my components, so I can't afford to get this wrong and smoke $100 worth of equipment. Thanks!

    Let me know if this schematic implements your note. Thanks!

    -Jeff
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-03-12 19:43
    Jonathan, All....

    Double check the datasheet.... looks like Vref should go to +5V. Are you confusing Vref with -Vin by chance?

    I would go with the "ratiometric" reference example located on page 14 of the PDF sited below.

    Reference:
    http://eshop.engineering.uiowa.edu/NI/pdfs/00/55/DS005583.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • JonathanJonathan Posts: 1,023
    edited 2009-03-12 19:44
    Jeff,

    That looks good. I assume that the Stamp is powered from the 12V battery via a regualtor? If it is through another battery or a wall wart, make sure to tie it's ground in too.

    Also, google up grounds, particularly note the "star" ground configuration. ADC's are sensitive to ground loops.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2009-03-12 19:50
    Beau,

    We crossed posts above. I don't have the pinout, and I think I misread the schematic above. You are right that +vRef should be to +5v. If there is a -vRef (which I dunno, don't have the sheet) it would go to ground. Good catch!

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • everesteverest Posts: 141
    edited 2009-03-12 19:54
    Funny, I was about to post the same question. . .I've attached the schematic that's in the "Stamps in Class" .pdf that I've been using as reference. In this configuration, everything works just perfectly. It struck me looking at the two that Vref was getting switched from +5v to the common ground.

    I'll re-work the schematic and post it shortly. I really need experienced eyes on this because I don't have time to destroy everything and start over. . .I've got a weekend pass to work on the observatory and I've got to use it! Thanks!

    -Jeff
    863 x 434 - 145K
  • everesteverest Posts: 141
    edited 2009-03-12 20:11
    Okay, here is yet another schematic that I think now aligns with what I'm hearing. Now I have a combined ground from the 9v battery, the 5v regulator on the STAMP (Vss), and the 12v battery I'm trying to monitor. . .that's a little scary to me, but that may be my own ignorance. . .thanks for your patience!

    I've just read several articles on star grounding and while my schematic doesn't show this working that way, I could easily pull all the grounds from the 9v, 5v, and 12v to a single point and break them out to all the various connection points from there. . .which seems to be the recommended method.

    Anyways, how does this look? If I wire this up am I going to blow up anything? jumpin.gif

    Thanks!

    Post Edited (everest) : 3/12/2009 8:28:32 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2009-03-12 20:43
    Looks good. I'm assuming that the 9V battery is going to power the stamp via a regulator. You know that with the right regulator you could run the whole thing from the 12V battery, right?

    The main thing is to make sure that all grounds are common, and that the VIN to the ADC never exceeds 5V. Make sure your voltage divider can handle it. If the battery is ever going to have an equalizing charge placed on it, that can go to 15.5V or even a little higher depending on the charger.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • everesteverest Posts: 141
    edited 2009-03-12 21:19
    Jonathan,

    THANK YOU for all your help. . .this is starting to make sense to me now and I'm confident in re-wiring this sucker. The 9v battery is directly attached to the Board of Education and there is a 5v regulator soldered right on to the board, so that takes care of the STAMP, and as such the ADC will also get the regulated 5V.

    The charger I'm using right now is a simple two stage charger, it doesn't have an equalization cycle so no worries there. . .what would happen though if the input on the ADC went to 5.5v or so? Would it really destroy it?

    I ask because I *ahem* actually threw more voltage at it a couple of times and it seems like it just maxes out it's reading, but it didn't damage it. . .
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2009-03-12 22:27
    They are pretty tough but my experience is that when they fail they fail. I've never seen one degrade in performance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When your problem seems insurmountable, read the forum for a while.
    Solve someone else's problems and yours won't seem so bad.
  • everesteverest Posts: 141
    edited 2009-03-12 22:44
    Hehe, thanks. I accidentally hooked mine straight up to my 12v battery and it locked up for a while until it cooled down. . .I mean that sucker must have been 150 degrees in the second I had it connected (before I realized that I'd connected it wrong).

    Anyways, I don't anticipate going over 15 volts. . .I'll just see how it goes. THANKS EVERYONE! This is the best support forum I've ever been on. . .and you are even very tolerant of stupid questions. Bonus!

    -Jeff
  • everesteverest Posts: 141
    edited 2009-03-13 01:06
    All,

    Thanks again for the help, I just wired up the new schematic and it's working perfectly. . .actually it's reading just a tad high, but I adjusted the code slightly to accommodate for that. . .8 bits only provides so much accuracy I guess!

    Anyways, it's all working perfectly! Thanks again!

    -Jeff
Sign In or Register to comment.