Interfacing a 16-bit ADC (AD7706) with Picaxe 28x2

rberkelm

New Member
I’d love some help interfacing a 16-bit ADC (AD7706) with a 28x2 (3v) picaxe using SPI comms protocol if possible?

My ultimate goal is to use this ADC to read the S+ and S- output from a set of electronic bathroom scales. I realise there are more elegant ADC's for weigh scales, e.g. the TI1231 which are dedicated and have no registers to program. However, I happen to have some AD7706 ADC's on hand and figure I could learn a lot about precision analogue to digital interfacing if I master this one.

Since this is my first foray into external ADC and SPI, I thought I’d go simple and breadboard the ADC to a 28x2 3v MCU and try and read the output of an analogue LM35 temperature sensor. Power to my breadboard is via a 3.6v SAFT Lithium battery reduced to 3.0V via an in-line regulator to the MCU, suitably decoupled. Reference voltage to the ADC and LM35 temp sensor is 2.5V via a REF192 precision voltage reference IC, also decoupled as per the datasheet.
I’m currently getting nothing at all in my debug screen, so am guessing I’m not even connecting with the ADC. I’ve triple checked my wiring against the data sheets and have tried all 8 possible SPI modes and a few speeds. All to no avail. Any ideas?

Here’s my code so far:
Code:
; #####################################
;RB implementation of the AD7706 16-bit ADC and Picaxe 28X2 (3v) with an LM35 analog temperature sensor
; ADC setup includes an external 4.9152mHz crystal on the MCLKIN and MCLKOUT pins, buffered on both sides with a 0.1uF ceramic capacitor.
; Also includes a REF192 precision 2.5V voltage reference for the ADC, decoupled with a 10uF electrolytic and 0.1uF ceramic capacitor on the Vdd input side and with a 1uF tantalum and 0.1uF ceramic capacitor at the output side.
; Vdd is via a SAFT 3.6v Lithium SOCL2 battery reduced to 3.0V by a LE30AB in-line voltage regulator decoupled with a 10uF electrolytic and 0.1uF ceramic capacitor.
' 28X2 (3v) Picaxe MCU
;#########################################

Symbol CS = C.2 'AD7706 Chip select on C.2 MCU pin

init:
hspisetup spimode00, spimedium ' not sure on mode but have tried all combinations. Have also tried Slow and Medium speeds to no avail.
High CS

' Params for Setup registry :
Low CS
Hspiout (%00010000) 'zero 'write' bit to Communications Register, instruct to enter Setup Register and that next operation is a 'write'
Hspiout (%01000110) 'Perform calibration at full scale on channel 1; set gain to 1; unipolar input; buffered; and FSYNC disabled.
High CS

' Params for Clock registry :
Low CS
Hspiout (%00100000)     'instruct to enter Clock Register (from Communications registry) and next operation is a 'write'
Hspiout (%00010100)     'MCKOUT disabled since using ext crystal; CLKDIV turn off to use 4.9152 crystal internally as well; CLK set to 1 for crystal; 50Hz update frequency
High CS

Main:
Low CS
Hspiout (%00111000)     'instruct to enter Data Register (from Communications registry) and next operation is a 'read'
Pause 50
Hspiin (b1,b0)    	'Shift in the 16-bit data in two bytes
debug
High CS
Pause 1000
Goto Main
 

hippy

Technical Support
Staff member
It can be hard to say what may not be right for a component one is not familiar with which may only work as expected once everything is right.

For "getting nothing at all in my debug screen" I presume you mean it simply shows b0 and b1 at zero; it might be worth trying to read other registers to see if you can get a non-zero response out of it, that might show something is working.

If not it could be anything from wrong SPI setup, wrong command bytes sent, wrong sequences of commands, not being initialised, wrong wiring, or something else not working or not connected correctly. There doesn't seem to have been anyone on the forum who has got an AD7707/AD7066 working with a PICAXE but there may be software for other micros which may help in showing how they have done things found via Google.
 

inglewoodpete

Senior Member
Depending on your experience with electronics you have probably jumped into the deep end of the pool!

Some basic questions:
Can you be really specific with your diagnostics? As hippy alludes: "getting nothing at all in my debug screen" does not help us. Is nothing $FF or $00 or $7F or....?
Is the crystal oscillating? Oscilloscope or logic probe?
Do you see data on the DIN pin?
Is the clock pin clocking when commands are sent from the PICAXE?
Do you see data on the DOUT pin when you clock data into the chip?

Have you compared your setup commands with posts on another forum? (Eg The Microchip PIC forum) I'm not saying use a bare PIC: just compare the command format, sequence and timing(?)
 

rberkelm

New Member
Thanks SAborn - great tip! Very cheap indeed and it even looks to have an on-board voltage reference? Knowing that you've done good with them is a big help. I'll definitely get some!

BTW, I've been reading your past posts about the AD3231 ADC - very informative, thanks for sharing! I was wondering what you used with these ADC's for a voltage reference? Is the voltage reference on the M2/X2 Picaxe (through FVRSETUP) sufficiently stable for 16-bits of stable weight data?
 

SAborn

Senior Member
Hi Rberkelm,

The AD1231 (correction on part number) is a great chip, and i have spent a lot of time in getting noise out of the circuit with using this chip, as when you deal with 24 bit data it needs to be squeaky clean or as close to as you can get it.

The HX711 boards are not quite as good as i got from the AD1231 for low noise, but for the price of a HX711 board i would not go back to building boards for the AD1231 chip and use the HX711 for future projects

Bottom line is the HX711 has a little more noise in the readings, but well good enough for the average project and far good enough for most projects because they are cheap and do function very well.

I am able to read down to 1 gram with the HX711 board, which is good enough for the projects i do, but that is Dependant of the load cell range you are using.
Most load cells have a 20 mV range for their rated capacity, so hence a 5kg load cell will return a far higher resolution in its ADC reading than a 500Kg load cell.

As for a reference voltage, i use 5v for both picaxe reference and also to excite the load cell with (supply to the cell).

More than happy to discuss the use of the HX711 board further once you receive one to play with.
 
Top