Using the adc8038
mosquito56
Posts: 387
·I ordered about 20 adc8038's and finally got one working today. I first used the 8031, then the 8034 and now the 8038.
· When I first started reading the adc chip operation, I read that the author had problems getting the chip to read 256. Then I remembered the 8031 could read 256 so I checked his code.
Basically 2 options
Method 1:
··datar:=2
· repeat i from 0 to 7········· ' read 8 bits············ 'Example 3
··· if ina[noparse][[/noparse]dataoutFromADC] == 1········
······· datar:=datar*2
other method:
datar:=0
· repeat i from 0 to 7········· ' read 8 bits············ 'Example 3
··· if ina[noparse][[/noparse]dataoutFromADC] == 1
····· datar |= |< i············ ' set bit i HIGH
··· else
···· ·datar &= !|< i
I can get a reading of 256 when connected to vref from the first code but not the second.
Am I just cheating? Grounding the input gives a value of 2. This makes me think that I am just doubling the values.
Has anyone figured this problem out? Which method is more accurate?
P.S. Can someone translate this into english?· datar &= !|< i
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 4/17/2009 10:52:36 AM GMT
· When I first started reading the adc chip operation, I read that the author had problems getting the chip to read 256. Then I remembered the 8031 could read 256 so I checked his code.
Basically 2 options
Method 1:
··datar:=2
· repeat i from 0 to 7········· ' read 8 bits············ 'Example 3
··· if ina[noparse][[/noparse]dataoutFromADC] == 1········
······· datar:=datar*2
other method:
datar:=0
· repeat i from 0 to 7········· ' read 8 bits············ 'Example 3
··· if ina[noparse][[/noparse]dataoutFromADC] == 1
····· datar |= |< i············ ' set bit i HIGH
··· else
···· ·datar &= !|< i
I can get a reading of 256 when connected to vref from the first code but not the second.
Am I just cheating? Grounding the input gives a value of 2. This makes me think that I am just doubling the values.
Has anyone figured this problem out? Which method is more accurate?
P.S. Can someone translate this into english?· datar &= !|< i
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 4/17/2009 10:52:36 AM GMT
Comments
The question regarding datar &= !|< i. Here is how I think it works....
i is a value that is decoded into a long. If i is 1, the 1 bit is set, if i is 10, the 10 bit is set (counting from zero), if i is 31, the 31 (or most significant bit) is set. If the value is bigger than 31, then the remainder is the value that is set. In other words if i is 32, it is the same as 0, 33 is the same as 1, etc.
The decoded value is then inversed. This will create a long with all 1s and one 0 in the i position. That long is then anded with the current value of datar.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
8-Bit High-Speed Serial I/O A/D Converters with Multiplexer
Options, Voltage Reference, and Track/Hold Function
Data Sheet:
www.national.com/ds/DC/ADC08031.pdf#page=1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Aka: CosmicBob
Judging by the response, not to many people are using this chip.
Thanks for the explaination about ·datar &= !|< i. A little to advanced for me. This is MIT stuff and I'm just a community college type guy. ·Reminds me of the contests in school of people trying to write code in the smallest space possible.
· Any discussion on the subject is welcome.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
·I have been for about 2 months now. I used the 8031, 8034 and now 8038.
Non of them will read 256. I was modifying one today and it seems to work. I tried to copy it into my prog and it doesn't work.
· 7 bits is fine for my job. I understand the timing of the chips but why re-invent the wheel?
Have a good one
Don
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
I don't understand what you mean by reading 256. I think I might not be understanding the part fully since I only glanced at the data sheet. From what I see it is an 8-bit device when means that you should read values from 0 to 255. When you say 256 do you mean 8-bit?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Even with the one I have "working", it only reads 254.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Is it possible to manually operate the chip by having toggle switches for for CS and CLK and hooking up an LED to DO? For example: Switch on CS and toggle CLK on and off 16 times? <-ignore this, didn't print the AC section of the data sheet-'cause I'm not measuring AC (hehe)
And just a general question, since I have hooked up and not yet applied power to my 8031, do I need to use current limiting resistors on anything but from the DO pin to my prop? I plan on using my +5V bus as Vref and Vcc and +3.3 V bus for Vin+. Vin- and GND hooked straight to ground.
It should output somewhere around 10101001, right?
Post Edited (grindel) : 4/18/2009 3:28:08 AM GMT
I installed the 8038 backwards yesterday, pluged it in, saw my led dim and left it connected for· a couple minutes. I put my finger on the reg chips and literly? burned my fingers. Found the problem, flipped the chip and it worked.
As to your question about voltages. I use 5v on all voltages so I don't know about values for 3.3v. If you use the 8031 object let me know if you get the 254 reading with vref applied.
I am wondering since my program uses about 6 cogs if there might be a timing issue. When I run one cog, just program and tv it seems to work fine but when I copy the same code into my main program, I can only get the 127.
· I played with the waitcnt in the loop, increase and decrease with no change. I don't know why this happens but until I get my temperature measuring device and hook it to some hot surfaces, 7 bits will do.
Don
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
The reason I think that 3.3 V will output 10101001 is that 3.3V/5V=.66 .66*256=169ish 169 to bin=10101001
Looking at the data sheet again I think the CLK frequency has to be between 10 and 400 khz, my switch idea will not work unless you have REALLY fast fingers...heh.
when 3.3 was compared to 5 it output 170...which I guess might mean it always rounds up. I only have a $2 volt meter so I couldn't confirm that with any sort of confidence.
By using a thermocouple wire to imput thru an op amp, I can get the chip to count from 1 to 25 by ones.·I didn't go any further as it wasn't necessary. When the same pin is connected to 5v·it reads 127. I guess you can just connect to a pot that goes from 0 to 5 volts and do the same thing.
·· By changing the code I could get it to read both the msb and lsb. The chip actually outputs two sets of bits. Lsb and msb first. By waiting for sars to go high you get·msb first and by waiting for sars to go low you get lsb first. Both ways gave identical numbers.
The code is available, but it runs on t.v. You can modify it to run an 0831 by elimiating the first loop which sets the chan number. Let me know if anyone wants· it.
It reads the chip and fills a string with "10101010", prints the string and then converts the string to decimal.
Output is
Adc 1 is xx··········· 10101010101····· xx
Adc 2 is xx··········· 10101010101····· xx,· etc.
··········his coding····my coding······· my coding
········· datar
Have a good one
Don.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········