Shop OBEX P1 Docs P2 Docs Learn Events
Need assistance writing code for ADC0834 instead of ADC0831 — Parallax Forums

Need assistance writing code for ADC0834 instead of ADC0831

Mark KMark K Posts: 3
edited 2005-09-04 16:50 in BASIC Stamp
I would appreciate some assistance on how to code for the differences between the ADC0831 and the ADC0834. I know this is VERY basic for most of you, but I know that if I can REALLY understand this concept I can make it a ton further down the road. Any assistance is appreciated. I have working code for the ADC0831, I just don't want to use four of them.

The 0834 requires me to send data to the IC to request which channel to read. The request format I understand. As soon as the·first clock cycle is output I need to send a start bit, on the second I send a bit as to wether it is single ended or differential, on the third I send the sign bit, on the fourth, I need to send the select bit. I really am struggling to code this myself, in syncronizing the clock and the output of these bits. I am using a basic2 stamp and would also like to understand the porting of this timing to the basic2p.

I am using this with several Sharp IR sensors and need to be able to read multiple values with a single IC. I think the Sharp sensors will all be single ended, so any correction is appreciated.


The ADC0834CCN relevant pdf is attached.

Thanks in advance for the assistance,
Mark K

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-04 19:42
    I've attached a demo.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Mark KMark K Posts: 3
    edited 2005-08-05 02:13
    Thanks so much for the code. I wasn't interpretting the data sheet properly. Sorry to bother you with this.smile.gif
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-03 17:12
    Jon,
    I understand the program to work as "adc" is the data that is recieved from any given channel.
    if i have 2 battery circuits and pressure sensor all attached to the 0834, would i make a variable Bat1, Bat2, PresSens and use those in the place of "adc" so that i can reference them from different parts of the program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-03 19:34
    Normally, we define arrays like this:

    adc········ ·VAR··· Byte(4)

    Another way to do it so that you can give each element a unique name is to do this:

    adc········ ·VAR·· ·Byte······· ' define adc array start position
    bat1····· ·· VAR·· ·adc·········' same as adc(0)
    bat2····· ·· VAR·· ·Byte······· ' same as adc(1)
    presSense·· ·VAR··· Byte······· ' same as adc(2)
    ch4········ ·VAR·· ·Byte········' same as adc(3)·

    This works because the BASIC Stamp treats all RAM as an array, even if it's not declared, and variables of the same size are declared in the order that they are defined in the program listing.· For this to work you must NOT change the declaration order.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-03 19:42
    thank you i didnt understand the (byte(4)) thing. so at any given time in the program. if i want to know what the bat1 voltage is i just have to call adc(0) or pressure sensor, call adc(2). i am beginning to get this.

    (big light bulb flashing over my head)

    thanks again Jon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-03 19:47
    Just note that you can't alias members of a declared array, hence adc is defined as a byte (anchor point) in the second example.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-03 20:32
    would this be correct then?

    Altitude: 'read ADC0834 for altitude "ADC(0)"
    DEBUG HOME
    chan = 0
    GOSUB Read_0834
    DEBUG "CS", DEC1 chan, ": ", DEC3 adc(chan), CR
    RETURN

    FlightBat: 'read ADC0834 for Flight Battery Status "ADC(1)"
    DEBUG HOME
    chan = 1
    GOSUB Read_0834
    DEBUG "CS", DEC1 chan, ": ", DEC3 adc(chan), CR
    RETURN

    ElecBat: 'read ADC0834 for Electronics Battery satus "ADC(2)"
    DEBUG HOME
    chan = 2
    GOSUB Read_0834
    DEBUG "CS", DEC1 chan, ": ", DEC3 adc(chan), CR
    RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-04 00:18
    It looks okay. Does it work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-04 14:32
    syntax checks out but i havent had a chance yo run it yet

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-04 14:57
    You could alwasy put your test code into a loop -- that would let you see everything at once:

    Main:
    · FOR chan = 0 TO 3
    ··· GOSUB Read_ADC0834
    ··· DEBUG CRSRXY, 0, chan,
    ········· DEC1 chan, ": ", DEC3 adc(chan)
    · NEXT
    · GOTO Main

    This uses the CRSRXY functionality of DEBUG that lets the chan number set the line (y value)·to print on.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-04 16:50
    yes. i may only call for one or the other every 10 min or so. Like after 255 cycles of 255 cycles of a loop

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
Sign In or Register to comment.