External ADC

TomMystery

New Member
Hello, I'm trying to use a external adc and I'm having trouble doing the correct timing for the Chips Select and Clocking pin. Can someone give me a general idea of how I would go about doing this?
 

premelec

Senior Member
It depends on the external chip's communication interface - often a 3 wire sort of thing but if you have multiple ADC channels it could be more complicated.

Uusually there is a clock line and a data line and so forth... READ THE ADC DATA SHEET carefully and study the timing diagrams. You need to emulate that with the PICAXE inputs and outputs. I think there was code to read an 11 channel TI chip on Peter Anderson's site as well as single channel chips... www.phanderson.com....
 

TomMystery

New Member
Actually I'm using the ADC0832, and I have pretty much figured it out. 4 Mhz clock on clock pin. Shtdn pin on high. Keep CS on low until I want to send a digital output, then switch to high and I should get a value with 3 0's preceding it that I can tell my program to standby on.

Right?
 

andrewpro

New Member
Actually...That wont work.

First...Are you sure it's an ADC0832?

Theres no shutdown pin on them.

The clock pin is for clocking out the serial data. You cant do that at 4mhz with a picaxe. This clock signal comes from the picaxe, as it gets a bit, processes it, then gets another bit.

The CS pin is active when it's low, not high.

The first three clock cycles are for data input (which you MUST provide to the chip). During this time the outputs are tristated, which means neither 0 or 1...just nothing in the way of valid data.

I would do a forum search on SPI for ideas on how to interface the chip with a picaxe. That's the basic premise here, though the timing is different it seems (appearantly two clock pulses per data bit? Maybe it's a microwire thing).

--Andy P
 

TomMystery

New Member
Sorry, I was looking at the wrong datasheet when I was typing up the previous post, however, I am working with a 0832, with two channels.

Can I just put a 4MHZ Xtal on the adc and keep CS low until I want to recieve a conversion from the chip?

So that I have something like:

high 2 'chipselect
serin 1, N2400, adc 'serial in
 

andrewpro

New Member
That still wont work. You cannot use serial in. Like I said earlier, do a search for "SPI" (without the quotes) on the forum. It's not a UART based ADC. It's a microwire device, which is similar to SPI, but this chip seems to have two clock pulses per data bit.

Serin will not work, a 4mhz clock will not work, you cannot hook a crystal to it. The clock has to come from the picaxe.

--Andy P
 

SD2100

New Member
If your using the 0832 then send clock pulses to it from the picaxe.
At the start have clk low, cs high & data either high or low. take cs low & data high then start pulsing the clock pin.
On the high to low of the 4th clock the first
bit (MSB)will appear on the data out pin. Just keep clocking until you have the byte. You can read the bits from it using just basic input such as "if pin0 = 1 then". You don't need xtals etc.
Check the data sheet, theres different modes
depending on the data in pin.
If your looking for a simpler chip then look at the 0831, it has no data in pin.


Edited by - Phil75 on 13/04/2006 07:25:18
 

SD2100

New Member
;This is sort of what you need, I wrote this for the 0832 but I tested it on a 0831(with some mods) as I didn't have an 0832, might need some adjustments here and there ??? and the pauses can reduced or removed, Iput them in when I was testing it.

;Picaxe 18x
;Read ADC0832
;

symbol cs = 0 ;Chip enable pin
symbol clk = 1 ;Clock pin
symbol dat = 2 ;Data pin
symbol loop = b0 ;for/next loop variable
symbol byte = b1 ;Final value
symbol bit = b2 ;bit value
symbol DataIn = pin1 ;data bit from adc

main:
low clk ;Clock low
low dat ;Data pin low
high cs ;Chip enable pin high

pause 50 ;Short delay
high dat ;Start bit
low cs ;Enable chip
pause 50 ;Delay before first clock

for loop = 1 to 3 ;First 3 clock pulses to set chip up
pulsout clk,5
next loop

byte = 0
Bit = 128 ;Set value for MSB
for loop = 1 to 8 ;Read 8 bits, MSB first
pulsout clk,5
if DataIn = 1 then DoBit ;If the data bit is high add bit value to byte
Bit = Bit / 2 ;If data bit is low divide for next bit
NextBit: next loop
high cs ;Finished so disable chip
sertxd (#byte ,13,10) ;Send byte to pc
goto main ;Read adc again

DoBit:
byte = byte + Bit ;Add bit value to byte variable
Bit = Bit / 2 ;Divide for next bit
goto NextBit


Edited by - Phil75 on 16/04/2006 11:57:42
 
Top