Need assistance writing code for ADC0834 instead of ADC0831
Mark K
Posts: 3
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
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
pdf
762K
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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!!
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
(big light bulb flashing over my head)
thanks again Jon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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 Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!