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

Measuring voltage

StevezilaStevezila Posts: 35
edited 2009-09-12 18:13 in BASIC Stamp
Can anyone tell me the best way to measure voltage up to 12 vdc with a BS2? I saw in· stampworks a program that uses the adc 0831 to measure voltage but it only measures up to 5 vdc. Does anyone know of a simular device that measures up to 12 vdc.· I have some remote projects that I'm working and it would be really nice to be able to check the condition of the 12v battery supplying the power and maybe flag an output , or prohibit certain events from tacking place when voltage drops below a certain level.

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 19:56
    Generally, you won't find an ordinary ADC that can measure voltages higher than the supply voltage. The normal way to do this is to use a voltage divider (do a websearch for "wiki voltage divider") like this (using 1K resistors):

    12V --- 1K --- 1K ---x--- 1K --- Ground

    The voltage between the "x" and Ground will be 1/3 of the voltage across the whole thing (4V in this case). The 1/3 ratio allows for voltages > 12V like for charging while limiting the measured voltage to 5V for an ADC. There's a current drain through this voltage divider of about 4mA. If you need to reduce this, you can use multiples of 1K as long as all 3 resistors have the same value.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-08 20:09
    You can use the RCTIME command for this purpose, to monitor battery voltage, without an analog to digital converter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-08 20:19
    Monitoring battery voltage is not a reliable·way to predict battery life and / or control the process.
    If you are serious about it, look into IC's ·designed for such purpose.
    Check TI "Battery fuel gauges" for example.
  • everesteverest Posts: 141
    edited 2009-09-09 07:46
    Hey Steve,

    You just need to use a voltage divider to bring the voltage down to the 0-5v range, and then read it with an ADC0831 (or equivalent). I've attached a schematic that I've used, and it works very well.

    This circuit will let you use the sample code for the ADC0831 in Experiment 28 in the Stampworks Manual.

    -Jeff
  • StevezilaStevezila Posts: 35
    edited 2009-09-11 20:38
    Thanks so much for the reply. After looking at it this way, I'm not sure if its worth it to have the check battery function if it's going to constantly put a drain on the battery. May look into using a small relay dirven off a second pin to connect the resistor array to the pin that reads the voltage. That way I only have a drain when measuring the voltage.

    Thanks
  • Alan BradfordAlan Bradford Posts: 172
    edited 2009-09-12 15:01
    If you do the math, the voltage divider will draw .36 MA.
    At that rate the battery will self discharge before the VD will run it down.
    If you use a relay and energize it for 1 second every minute, it·will take more juice to energize the coil than the voltage divider.

    You can also change the resistor values to· 100k, 10k ans 220k and the draw will be 36 micro amps.

    Good Luck,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alan Bradford ·N1YMQ

    Plasma Technologies
    Canaan NH 03741
    www.plasmatechnologies.com
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-12 18:13
    If you use the RCTIME method with a 680 kOhm resistor, and leave the pin high after doing the RCTIME measurement of voltage, then the 10 microamps of quiescent current flows into the pin and helps to power the Stamp. That 10 microamps is inconsequential for a big SLA battery, but can be a minor savings when you do have to count microamps. This method does not use the ADC.

    681 kohm        470 ohm 
        Vx ----/\/\/\---o-----/\/\/\----P0 to stamp
        unknown         |
        voltage       ===== 0.01 uF film
                             |
                            Vss
    
    P0: make LOW, PAUSE, then RCTIME, make HIGH quiescent between readings.
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.