Atmel AVR Microcontroller discussion group.
ADC and AT90S2313 - mr_kidkill - May 24 16:25:00 2002
I am working with an ADC0834acn and keep getting 00000000 an matter
what the analog voltage is.. It is a 4 channel ADC. I included a
snipit of code.. I know it is sloppy but i think it should work.
please any help will be greatly apriciated. I think that the 0834 is
a common ADC sso someone is bound to have worked with ine and could
provide some insight. Also i am using an AT90S2313 for control.
thanks everyone!!!!
ReadADC:
cbi ADCPORT,CSnot ; start the conversion CS not is now low
sbi ADCPORT,Din ; Start Bit Digital in is taken high
nop
nop
sbi ADCPORT,Sclk ; First clk cycle and start bit shifted in
nop
nop
cbi ADCPORT,Sclk
cbi ADCPORT,Din ;Din low for for the begining of the channel select
nop ;will be using channel 0 and 1 for + and - respectivly
nop ;this is low low low
sbi ADCPORT,Sclk
nop
nop
cbi ADCPORT,Sclk
nop ;first bit shifted in
nop
sbi ADCPORT,Sclk
nop
nop
cbi ADCPORT,Sclk
nop ;second bit shifted in
nop
sbi ADCPORT,Sclk
nop
nop
cbi ADCPORT,Sclk ;third bit shifted in
sbi ADCPORT,Sclk ; 1/2 clock cycle required to settle in
ldi AL,8 ; number of bits to read is 8
adcread:
cbi ADCPORT,Sclk ; take clock low
nop ;delay
nop
sbi ADCPORT,Sclk ; clock high
clc ; clear the carry bit
sbic ADCINP,Dout ; check the data
sec ; data is high so set carry
rol TEMPL ; shift the data (carry bit) in
dec AL ; done eight bits?
brne adcread ; no, so loop back
; all done, drop the clock and bring CS/ high
cbi ADCPORT,Sclk
sbi ADCPORT,CSnot
ret

(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )