AD7705B interface to the BS2pe24
Andy McLeod
Posts: 40
I have an application that will monitor pressure and temperature using the AD7705B ADC with the BS2pe. I have some code that was used with the 7706, but I can't seem to modify it successfully. Analog Devices provides a schematic to make this device, but is unfamiliar with the BS2, using instead some of their own microcontrollers as an example. Has anyone made this ADC work with the BS2/PBasic architecture?
Comments
Here is the connection between AD7730 & BS2:
AD7730··················· BS2
(SCLK) pin1
pin12 (P7)···············CLOCK············
(DIN) pin22
pin13 (P8)················AD data input
(DOUT) pin21
pin14 (P9)············· AD data output
(RDY) pin20
pin15 (P10)············ Input pin number
You have DRDY instead of RDY
RESET => +5v
CS····· · => GND
Thank you for that pinout. I'll try it with the code I have and see what it gives me.
Do you have code for the 7730 that you would share with me?
Andy
Using your prompt, I've come up with this code. It appears to work, thank you for the prompting!
' {$STAMP BS2pe}
' {$PBASIC 2.5}
'AD7705 BS2
'(SCLK) PIN1
PIN12 (P7) CLOCK
'(DIN) PIN14
PIN11 (P6) ADC DATA INPUT
'(DOUT) PIN13
PIN10 (P5) ADC DATA OUTPUT
'(DRDY) PIN12
PIN9 (P4) INPUT PIN number
'RESET
+5v
'CS
GND
'
Variables
sample VAR Word 'ADC reading
numsamples VAR Word 'Used to count samples in multiple instances
avg VAR Word(3) 'Temp variables for storing samples to be averaged
'
Constants
SCLK CON 7 'serial clock p7
DIN CON 5 'serial data in p5
DOUT CON 6 'serial data out p6
DRDY CON 4 'logic output p4
GOSUB initadc
avg = 0 ' Clear avg
'
Take 3 samples, at 60Hz intervals, and store in avg(0),avg(1),avg(2)
FOR numsamples = 0 TO 2
GOSUB getsample
PAUSE 17
avg(numsamples) = sample
NEXT
'
Calculate approximate average, preventing overflow
avg(0)=((avg(0)/3)+(avg(1)/3)+(avg(2)/3))
DEBUG "Avg=",DEC avg(0),CR ' Display the average value by sending over serial port
'
Subroutines
initadc:
SHIFTOUT 6,7,1,[noparse][[/noparse]%00100000] ' Configure a write to CLOCK register
SHIFTOUT 6,7,1,[noparse][[/noparse]%00001101] ' Master clock ENABLE, 4.9152 MHz config, 20 Samp/sec
SHIFTOUT 6,7,1,[noparse][[/noparse]%00010000] ' Configure a write to the SETUP register
SHIFTOUT 6,7,1,[noparse][[/noparse]%01000010] ' Self calibration, gain=1, bipolar buffered input
RETURN
getsample:
SHIFTOUT 6,7,0,[noparse][[/noparse]%00111000] ' Configure read from DATA register, 1st channel selected
SHIFTIN 5,7,0, [noparse][[/noparse]sample\16] ' Read in 16 bits, store in sample
RETURN
ADdata··· ·· var·· · WORD 'variable to hold 16 bit result.
DATAin···· con····· 2···········'AD data input pin.
DATAout· con·······3········· 'AD data output pin.
SCKL········· con····· 4········· 'clock to AD.
RDY·········· ·con····· 5········· 'RDY ·input .
INPUT 5
Initial:
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$FFFF\16,$FFFF\16] 'write 32 ones will reset the AD7730 to the default state
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$02] 'write to communication register setting next operation as write to mode register.
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$B0B0\16]'write to mode register initiating internal full scale calibration
pause 500
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$02]
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$B0B0\16]'write to mode register initiating system zero scale calibration
pause 500
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$3080\16] 'write to mode register starting continuous conversion for 10mV input range,unipolar,16 bit data word and 5V reference.
SHIFTOUT DATAin, SCLK, MSBFIRST, [noparse][[/noparse]$21] 'write to communication register setting next operation as continuous read from data register.
LOW 2 ' set DIN line low to insure part is not reset while in continuous read mode.
ReadData:
waitRDY:
IF RDY = 1 THEN waitRDY 'wait for RDY to go low to indicate output update.
SHIFTIN DATAout, SCLK, MSBPOST, [noparse][[/noparse]ADdata\16] 'read conversion result from data register.
DEBUG DEC ADdata, CR 'display data in decimal.
PAUSE 500 'wait 0.5 second between reading.
GOTO ReadData