have tried to get this to read for a week . will post my code and the interface
for this. can anyone get me started ??
The ADC can be interfaced with using the CS, DI, CLK, and DO pins. To complete a
conversion and read the digital output, follow these steps:
DIGITAL INTERFACE
Pull the CS line low. It must be held low for the entire conversion.
A clock is now generated by the processor (if not continuously generated)
and sent to the CLK line.
On each rising edge of the clock the status of the DI line is read into the
MUX address shift register. The start bit is the first logic "1" that occurs on
this line. Following this start bit should be the the 4 bits of the MUX
assignment word.
When the start bit is shifted into the start location of the MUX register,
the SAR status (SARS) line goes high to signal that a conversion is in progress
and the DI line has been disabled. This takes 1/2 of a clock period.
The DO line now comes out of tri-state and provides a leading zero during
step 4.
On each falling edge of the clock, the DO line gives the output of the SAR
comparator, which indicates whether the analog input is greater or less than
each successive voltage from the internal resistor ladder. The resulting data
stream will give the 8-bit digital result with the MSB coming out first.
After 8 clock periods all 8 bits of the digital result have been read out.
The SAR status (SARS) line returns to low 1/2 of a clock period later to
indicate this.
When the CS line is pulled high again all internal registers are cleared.
This must be done in order to do another conversion.
Assignment Codes
The following bit sequences are used to read from the various channels of the
ADC0838:
Channel Sequence
0 1000
1 1100
2 1001
3 1101
4 1010
5 1110
6 1011
7 1111
Sample Code for the Basic Stamp 2
' Ultrasnd holds the address for the channel being examined
' Sensor holds the output of the ADC0838
' digi is the DI line, digo is the DO line, clk is the CLK line, and cs is the
CS line
Ultrasound:
LOW cs
SHIFTOUT digi, clk, MSBFIRST, [ultrasnd \5]
SHIFTIN digo, clk, MSBPOST, [sensor]
HIGH cs
DEBUG ? sensor
RETURN
my code
dim i as integer
baud1=115200
TXD1=$07c
TXD1=$00 ' cls
#include "STRING.Bas"
#include "RTC.bas"
#include "PULSE.BAS"
#include "SPI.bas" ' source in /Program
Files/Coridium/BASIClib
#define FALSE 0
#define TRUE 1
' gotcha # one - you must not read faster than .22 seconds - this is
causing your same reading problem
#define TC_READ_PERIOD 500000 ' half second - MAX6675
has conversion time of .22 seconds (max), you must not read faster than .22
seconds
' SPI pin definitions
' SPIIN (CSPIN, INPIN, CLKPIN, OUTPIN, FALSE, -1,"", 16, A)
'
#define CSPIN0 12 ' reading two TC using the Maxim 6675
#define CSPIN1 10 ' reading two TC using the Maxim 6675
#define INPIN 11
#define CLKPIN 13
#define OUTPIN 10
#define MASK 4
function readTC (CS_PIN)
dim TC as integer
dim TCstring(2) as string
'SPIIN (CSpin, INpin, CLKpin, OUTpin, LSBfirst, OUTcnt, BYREF
OUTlist as STRING, INcnt, BYREF INlist as STRING
'SPIIN supports the loosely defined serial protocol used by a
variety of manufacturers. The desired device is selected by asserting CSpin
LOW. If there is no CSpin , the value should be set to -1.
'In the simplest case, INpin is used to input data clocked by
CLKpin, to fill the INlist. (OUTcnt will be 0 and OUTlist empty)
'In bi-directional cases, OUTcnt bytes of OUTlist will be output
on OUTpin before reading the INlist. OUTcnt may be -1 and OUTlist empty. If
OUTcnt is 0, then OUTlist bytes will be sent until a value of 0 is found (the 0
will not be sent). An empty OUTlist can be represented by "".
'It is also allowable to have INpin equal to OUTpin, in which
case that pin will be driven for the OUTlist and then converted to an input for
INlist.
'INlist will be filled with INcnt bytes. If INcnt is 0 then the
INlist will be filled with bytes until a 0, CR or LF character is received.
Note that no bounds checking is performed on the input, and if a 0, CR, or LF is
never received then this routine will hang.
'Data is shifted in MSB first and each element of the InputList
is filled with a byte of data. The LSBfirst can be used to change the bit order.
SPIIN (CS_PIN, INPIN, CLKPIN, OUTPIN, FALSE, -1, "", 2,TCstring)
' gotcha # two - the right most two bits are not valid and must
be masked off - I think you have this one fixed
TC = (TCstring(0)*128+TCstring(1)>>3)/4
' TC = TCstring(1) & MASK 'doesn't work with the ground on the
board
' TC = TCstring(1) & MASK 'doesn't work w/o the ground on the
board
if TCstring(1) & MASK then
if CS_PIN=CSPIN0 then print "Error on TC0"
else if CS_PIN=CSPIN1 then print "Error on TC1"
end if
return TC
end function
main:
dim TC0 as integer
dim TC1 as integer
dim TCreadPeriod as integer
TCreadPeriod = TIMER + TC_READ_PERIOD
while 1
IF (TIMER>TCreadPeriod) then
TCreadPeriod = TIMER +
TC_READ_PERIOD
TC0 = readTC (CSPIN0)
TC1 = readTC (CSPIN1)
end if
PRINT TC0, TC1
loop
end
thanks
phijoh
ADC0838 converter
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: ADC0838 converter
Looking at the ADC0838
The CLK clock is used to shift out data and also do the AD conversion.
The device is not really a byte oriented device, so SPI is probably not the best
routine to use. SHIFTIN is probably better, but you will also need to slow it
down.
Your code works on a BASIC stamp, because a BASIC stamp is about 2500 times
slower than a SuperPRO. So with the SHIFTIN routine, you'll have to insert wait
loops, that wait in microseconds.
x=TIMER
while (TIMER-x)<5
loop
would wait 5 microseconds
You really only shift out 1 word (only 26 bits) with the top 5 bits selecting
mode and address, and simultaneously shifting in 1 word (26 bits, where the
least 8 bits will be the converted data.
The CLK clock is used to shift out data and also do the AD conversion.
The device is not really a byte oriented device, so SPI is probably not the best
routine to use. SHIFTIN is probably better, but you will also need to slow it
down.
Your code works on a BASIC stamp, because a BASIC stamp is about 2500 times
slower than a SuperPRO. So with the SHIFTIN routine, you'll have to insert wait
loops, that wait in microseconds.
x=TIMER
while (TIMER-x)<5
loop
would wait 5 microseconds
You really only shift out 1 word (only 26 bits) with the top 5 bits selecting
mode and address, and simultaneously shifting in 1 word (26 bits, where the
least 8 bits will be the converted data.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: ADC0838 converter
> Looking at the ADC0838
>
Actually looking closer at the ADC0838 timing diagram, you control CS pin
manually, SHIFTOUT 13 bits and then SHIFTIN 8 bits. Again you will need to go
into the source for SHIFTIN/SHIFTOUT and slow them down.
>
Actually looking closer at the ADC0838 timing diagram, you control CS pin
manually, SHIFTOUT 13 bits and then SHIFTIN 8 bits. Again you will need to go
into the source for SHIFTIN/SHIFTOUT and slow them down.