Shop OBEX P1 Docs P2 Docs Learn Events
Help with ADC data — Parallax Forums

Help with ADC data

poorieuserpoorieuser Posts: 7
edited 2007-12-20 02:08 in BASIC Stamp
Ok so I'm doing some data logging use the BS2 stamp and an 8 bit ADC. Basically I need to program to bring in the data from the ADC that tells me Potential of a battery pack in a circuit. When it reaches a certain point I need the program to stop running.

Right now the program reads in the data from the ADC fine. It gives me an 8bit binary value. I can convert that outside the program and figure out the voltage easily. However I need the program to be able to convert the 8bit binary value into a decimal value so I can use a DO UNTIL loop and have it end when the potential reaches 2 volts. Otherwise the test destroys the batteries as it runs indefinitely.

Any help will be greatly appreciated.

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-12-19 21:23
    Assuming the ADC is spanned for 0 to 5V you can use the general formula of: value * output / input

    volt = binary value * 50 / 255

    This will give you a reading of 0 to 50 tenths of a volt, so 2V would be 20.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    SelmaWare Solutions - StampPlot GUI for controllers, XBee and Propeller Application Boards

    Southern Illinois University Carbondale, Electronic Systems Technologies
  • poorieuserpoorieuser Posts: 7
    edited 2007-12-20 01:23
    Don't you have to convert the binary value to a decimal value first? Thats how I've gotten voltage.

    Basically the code reads a binary value in from the adc to a variable adcBits.

    adcBits is a 8bit binary value originally but I need to convert it to a decimal value, at least, from what I understand.
  • FranklinFranklin Posts: 4,747
    edited 2007-12-20 01:40
    All numbers are binary to the computer and are different to us.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • poorieuserpoorieuser Posts: 7
    edited 2007-12-20 02:08
    ok so uh if i multiply 10000011 * 5/256 or 131 * 5/256 its going to give me the same thing?

    Basically if I have, when adcBits is an 8bit binary...

    DO UNTIL (adcBits * 5/256 <2)
    blah blah
    blah
    LOOP

    It should loop until my circuit dips below two volts?
Sign In or Register to comment.