Castor
- 30th May 2008, 16:46
http://img145.imageshack.us/img145/1979/adclf3.th.jpg (http://img145.imageshack.us/my.php?image=adclf3.jpg) http://img229.imageshack.us/img229/8586/ad7680cj8.th.jpg (http://img229.imageshack.us/my.php?image=ad7680cj8.jpg)
I'm trying to interface the AD7680 16 bit ADC with a pic18F4685 running at 20MHZ, external osc. The timing diagram for the AD7680 is attached as a thumbnail. The shiftin command is not an option.
I'm using the 24 sclk transfer which should output the result as: 4 leading 0, 16bit result, 4 trailing 0. For that i'm using 3 variables: one, two, three. In theory the result would be:
one: 0000 xxxx
two: xxxx xxxx
three: xxxx 0000, where x is a relevant bit
DEFINE OSC 20
DEFINE LCD_DREG PORTD' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4' Set LCD Register Select port
DEFINE LCD_RSREG PORTD' Set LCD Register Select bit
DEFINE LCD_RSBIT 0' Set LCD Enable port
DEFINE LCD_EREG PORTD' Set LCD Enable bit
DEFINE LCD_EBIT 2' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4' Set number of lines on LCD
DEFINE LCD_LINES 2' Set command delay time in us
DEFINE LCD_COMMANDUS 3000' Set data delay time in us
DEFINE LCD_DATAUS 100
' -----[ Variables ]-------------------------------------------------------
led var portd.3 'led connected to portd.3
sd_mps var porte.1 'shutdown pin on the main power supply
ad_cs Var PortC.5 ' ad chip select line
' -----[ Initialization ]--------------------------------------------------
adcon1=$0F 'all digital i/o
CMCON=$07 'disable comparators
trisa=%11000001 'porta HZ; except mux pins
trisb=$FF 'portb HZ
trisc=%11010111 'portc HZ; except ad lines
trisd=%00000000 'set the lcd lines as digital output
trise=%00000000 'porte output
SSPCON1=%00110000
SSPSTAT=%11000000
'variables
one var byte
two var byte
three var byte
a_mux var porta.1
b_mux var porta.2
c_mux var porta.3
d_mux var porta.4
inh var porta.5
pause 2000 'lcd init
main:
high inh
lcdout $FE, 1 'clear lcd
high ad_cs
high led 'turn on running led
high sd_mps 'turn on the main power supply
low a_mux:high b_mux:low c_mux:low d_mux:low inh 'select channel 0
pauseus 10
low ad_cs 'turn on the a/d converter
SSPBUF = 0 ' write to SSPBUF to start clock
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
one=SSPBUF
SSPBUF = 0
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
two=SSPBUF
SSPBUF = 0
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
three=SSPBUF
high ad_cs 'turn off the a/d converter
high inh 'disable mux
LCDOUT $FE, $80, BIN one 'print first byte of result, first line
LCDOUT $FE, $C0, BIN two
LCDOUT $FE, $94, BIN three
pause 1000
goto main
I'm trying to interface the AD7680 16 bit ADC with a pic18F4685 running at 20MHZ, external osc. The timing diagram for the AD7680 is attached as a thumbnail. The shiftin command is not an option.
I'm using the 24 sclk transfer which should output the result as: 4 leading 0, 16bit result, 4 trailing 0. For that i'm using 3 variables: one, two, three. In theory the result would be:
one: 0000 xxxx
two: xxxx xxxx
three: xxxx 0000, where x is a relevant bit
DEFINE OSC 20
DEFINE LCD_DREG PORTD' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4' Set LCD Register Select port
DEFINE LCD_RSREG PORTD' Set LCD Register Select bit
DEFINE LCD_RSBIT 0' Set LCD Enable port
DEFINE LCD_EREG PORTD' Set LCD Enable bit
DEFINE LCD_EBIT 2' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4' Set number of lines on LCD
DEFINE LCD_LINES 2' Set command delay time in us
DEFINE LCD_COMMANDUS 3000' Set data delay time in us
DEFINE LCD_DATAUS 100
' -----[ Variables ]-------------------------------------------------------
led var portd.3 'led connected to portd.3
sd_mps var porte.1 'shutdown pin on the main power supply
ad_cs Var PortC.5 ' ad chip select line
' -----[ Initialization ]--------------------------------------------------
adcon1=$0F 'all digital i/o
CMCON=$07 'disable comparators
trisa=%11000001 'porta HZ; except mux pins
trisb=$FF 'portb HZ
trisc=%11010111 'portc HZ; except ad lines
trisd=%00000000 'set the lcd lines as digital output
trise=%00000000 'porte output
SSPCON1=%00110000
SSPSTAT=%11000000
'variables
one var byte
two var byte
three var byte
a_mux var porta.1
b_mux var porta.2
c_mux var porta.3
d_mux var porta.4
inh var porta.5
pause 2000 'lcd init
main:
high inh
lcdout $FE, 1 'clear lcd
high ad_cs
high led 'turn on running led
high sd_mps 'turn on the main power supply
low a_mux:high b_mux:low c_mux:low d_mux:low inh 'select channel 0
pauseus 10
low ad_cs 'turn on the a/d converter
SSPBUF = 0 ' write to SSPBUF to start clock
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
one=SSPBUF
SSPBUF = 0
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
two=SSPBUF
SSPBUF = 0
PauseUs 25 '25uS fudge factor
while !SSPSTAT.0 :WEND ' while buffer empty
PauseUs 25 '25uS fudge factor
SSPSTAT.0=0
three=SSPBUF
high ad_cs 'turn off the a/d converter
high inh 'disable mux
LCDOUT $FE, $80, BIN one 'print first byte of result, first line
LCDOUT $FE, $C0, BIN two
LCDOUT $FE, $94, BIN three
pause 1000
goto main