Go Down

Topic: AD7730 ADC help (Read 6532 times) previous topic - next topic

Kremitinoz

Hi,

I have been asked to look at a mates arduino project, he needs to read data from 2 load sensors and then pass that data back into another application to record strain over time.

We have selected the AD7730 as our ADC.

There will only be one SPI device connected to this project, so no need for cs pin to go high.

I have managed to get it calibrating (i think) and outputting data, however i can not seem to get the ready pin to go low after calibration.

It needs to read a min/max -15mV to +15mV , hence i have set it up in unipolar and 20mV scale.

Code attached, constructive criticism please :)

really want to know if it has calibrated, and if the data i am receiving is good.

Thanks,

Tim
aka
Kremit

Code: [Select]
/*

Circuit:
DRDY: pin 9
CSB: pin 10
MOSI: pin 11
MISO: pin 12
SCK: pin 13
Reset pin: 8

*/

// the sensor communicates using SPI, so include the library:
#include <SPI.h>


// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int RDY = 9;
const int chipSelectPin = 10;
const int resetpin= 8;
byte byte1;
byte byte2;
byte byte3;
byte byte_total;

void setup() {
  Serial.begin(9600);

  // start the SPI library:
  Serial.println("Setting up SPI ...");
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0); 
  SPI.setClockDivider(SPI_CLOCK_DIV16);


Serial.println("Reset ADC ...");
digitalWrite(resetpin,HIGH);
delay(1000);
digitalWrite(resetpin,LOW);
delay(1000);
digitalWrite(resetpin,HIGH);
delay(1000);

Serial.println("Set Filter register settings");
SPI.transfer(0x03);//Write 03 Hex to Serial Port1 /* Writes to Communications Register Setting Next Operation as Write to Filter Register*/
SPI.transfer(0x200010);//Write 200010 Hex to Serial Port1 /* Writes to Filter Register Setting a 200 Hz Output Rate in CHOP Mode*/
Serial.println("Set DAC register settings");
SPI.transfer(0x04);//Write 04 Hex to Serial Port1 /* Writes to Communications Register Setting Next Operation as Write to DAC Register*/
SPI.transfer(0x23);//Write 23 Hex to Serial Port1 /* Writes to DAC Register Setting a Subtraction Value of 7.5 mV (5 V Reference) on the TARE DAC*/
Serial.println("Channel 1 Internal full scale calibration");
SPI.transfer(0x02);//Write 02 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Write to Mode Register*/
SPI.transfer(0xA190);//Write A190 Hex to Serial Port /* Writes to Mode Register Initiating Internal Full-Scale Calibration for -20 mV to +20 mV Input Range chan 1*

//while(digitalRead(RDY) != LOW) {Serial.print(".");delay(1000);} // wait for RDY signal from AD7730
delay(1000);

Serial.println("Channel 2 Internal full scale calibration");
SPI.transfer(0x02);//Write 02 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Write to Mode Register*/
SPI.transfer(0xA191);//Write A191 Hex to Serial Port /* Writes to Mode Register Initiating Internal Full-Scale Calibration for -20 mV to +20 mV Input Range chan 2*
delay(1000);
Serial.println("Calibration done");
Serial.println("Commence data aquisition..");
Serial.println("Data as channel no: byte 1, byte 2, byte 3, decimal value");
delay(1000);



}

void loop() {
  SPI.transfer(0x02);
  SPI.transfer(0x2190); //continuous read from channel 1
  readandprint(1);
  SPI.transfer(0x30); //end continous mode
  delay(1000);
  SPI.transfer(0x02);
  SPI.transfer(0x2191); //continous read from channel 2
  readandprint(2);
  SPI.transfer(0x30); //end continous mode
  delay(1000);
}

void readandprint(int chan)
{
  byte1 = SPI.transfer(0x00);
  byte2 = SPI.transfer(0x00);
  byte3 = SPI.transfer(0x00);
  byte_total=byte1<<16; 
  byte2=byte2<<8; 
  byte_total=  byte_total|byte2|byte3; 
  byte_total=(byte_total*2)+byte_total; 
     
  Serial.print(chan);
  Serial.print(": ");
  Serial.print(byte1,BIN);
  Serial.print(" ");
  Serial.print(byte2,BIN);
  Serial.print(" ");
  Serial.print(byte3,BIN);
  Serial.print(" ");
  Serial.print(byte_total, DEC);
  Serial.print("\n");
  delay(1000);
}


Grumpy_Mike

Quote
There will only be one SPI device connected to this project, so no need for cs pin to go high.

Most SPI chips need the CS line to change in order to function correctly.

So what data are you getting from it? Normally to test things like this you put a known voltage in and see if you measure what you expect to see.

Kremitinoz

The data will be from a torque bench(make up/ breakout bench),the load/strain sensors are built into it however the recording device was damaged and not able to be purchased/replaced. So we are building a replacement. It is all hydraulic and works as is, just need a way to record the make up torque over time.

Unfortunately i don't have access to the bench at the moment, so unable to test it. Kinda want to be sure calibration is running before I connect it up.

I did try using the cs pin, toggling on, sending the calibration bytes, then toggling back off. but this made no difference at all. The rdy pin stays high.

I have also read over the datasheet for this, not the easiest to read, and still cant work it out.

Google was no help either, A few posts here and there asking for help, but no real solution. One post suggested to ignore the rdy pin. But this is not what the data sheet says...



Grumpy_Mike


MarkT


Quote
There will only be one SPI device connected to this project, so no need for cs pin to go high.

Most SPI chips need the CS line to change in order to function correctly.



But not this one - see figure 20: Datasheet: http://www.analog.com/static/imported-files/data_sheets/AD7730_7730L.pdf

[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

Thanks Mark, what a great data sheet.
So the question is how have you wired it up?

Kremitinoz



ad7730 pin 1 --> arduino D13(sclk)
pin 2 & 3 --> 4.9152M clock (with 2 x 22uf caps)
pin 4 NC
Pin 5 --> Tied High 5v
Pin 6 --> arduinoD8(reset)
Pin 7 NC
Pin 8 -->GND
Pin 9 -->+5v
Pin 10 --> channel 1 input +
Pin 11 --> channel 1 input -
Pin 12 --> channel 2 input +
Pin 13 --> channel 2 input -
Pin 14 --> 5v
Pin 15 --> GND
Pin 16 NC
Pin 17 NC
Pin 18 --> Tied High 5v
Pin 19 NC
Pin 20 --> arduino D9 (rdy pin)
Pin 21 --> arduino D12 (dout)
Pin 22 --> arduino D11 (din)
pin 23 --> 5v
Pin 24 --> gnd


Any help is appreciated, I'm more into coding rather than electronics so this is a bit of a steep learning curve for me. Never had to interface with an SPI chip before

Grumpy_Mike

I hope you have 22pF caps and not 22uF.

Pin 19 CS needs to be connected to ground like the data sheet shows. I haven't checked the others so there may be something else missing.

Kremitinoz

yeah ,, they are pf not uf, will try the cs to gnd...


rodriguesluis

Good afternoon, i have read the post about the ADC AD7730 and i have tried to mount the circuit described, i have read also the datasheet of this ADC but the only result obtained was 0,0,0. Anyone have already obtained any data conversion from this component? anyone could help me?

thanks for the time spent with me

Best regards

José Luis Rodrigues

MarkT

Its about the worst documented SPI interface I've ever seen!

What are logic level are you putting on the POL pin?

Note that the correct SPI mode won't be 0 (CPHA = 1) and _will_ depend on the POL
pin logic level (CPOL).

The best approach to a chip like this is to first write code to read all the internal
registers - once this is working you should seen plausible values coming out,
until you do there's no point doing anything else really.  Hunt the internet for
working code to confirm/refute any guesses you have to make.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

mojzare70

hi
i use this codes for use a load cell with AD7730 and arduino mega. but just receive  0.0.0 !!
what's the problem?
do any one have better code for me?

thanks
mojtaba

Boxxylols

Those still looking for information check out my post here http://forum.arduino.cc/index.php?topic=331913.0

Go Up