Go Down

Topic: Arduino and the AD7730 (Read 5089 times) previous topic - next topic

Boxxylols

Jun 24, 2015, 07:01 pm Last Edit: Jun 24, 2015, 07:54 pm by Boxxylols
Hello this is a brief post to help as an example of a working AD7730 project, I was unable to find any fully functioning code for the AD7730 and arduino so I created my own and will provide it below. This is only to serve as refrence for somebody who has a decent understanding of both Arduino and the AD7730 Datasheet.

The components used were the AD7730, the Arduino Nano v3.0, a load cell a 4.9 MHz crystal clock and the appropriate capacitors with the clock (22pf in this case)
The ino file contains my current working code and the png contains a simplified image of our connections used. If you prefer to simply see our connections in text format the table is below (No assignment means no connection / open circuit)

*Disclaimer* There may be mistakes in my documentation or you may be doing something incorrect, when in doubt double check with the data sheet

770 PINS Mnemonic Our Assignment
1 SCLK Arduino D13
2 MCLK IN Crystal +
3 MCLK OUT          Crystal -
4 POL 5v
5 ~SYNC 5v
6 ~RESET Arduino D8
7 VBIAS
8 AGND GND
9 AVDD 5v
10 AIN1+ Load Cell + (Green)
11 AIN1- Load Cell - (White)
12 AIN2+
13 AIN2-
14 REFIN+ 5v
15 REFIN- GND
16 ACX
17 ~ACX
18 ~STANDBY 5v
19 ~CS Arduino D10
20 ~RDY Arduino D9
21 DOUT Arduino D12
22 DIN Arduino D11
23 DVDD 5v
24 DGND GND

MarkT

#1
Jun 25, 2015, 11:46 am Last Edit: Jun 25, 2015, 11:48 am by MarkT
Firstly where are the decoupling capacitors?

You don't need a crystal, you could use the Arduino to generate a clock using one
of the timers (if you don't need it for PWM that is).

The first thing is configure SPI to read the chips registers - somewhere in the datasheet
it says CPOL=0 CPHA=1, so that's probably what you need.

Once you can read the registers you need to carefully go through the chip's register
bank and decide how to configure each one and try getting conversions happening.

One sneaky trick is look on the web for existing code to drive the chip (for any
microcontroller) and see what register configurations are used, and just try that.
(hint: bingo!, an AVR example)

If you've not interfaced something to SPI before go read some libraries that do this
for inspiration.

Then when its working report back :)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Boxxylols

#2
Jun 30, 2015, 04:32 pm Last Edit: Jun 30, 2015, 07:23 pm by Boxxylols
I did not include the decoupling capacitors in my circuit diagram but you can find more information on them in page 34 of the datasheet.

 I think you may have misinterpreted my post as the given example is functioning (Polling data at around 150Hz, few mN sensitivity).

As for the SPI configuration, that is covered by setting to Mode 3 in the arduino SPI library in addition with the POL hardware pin on the AD7730 being wired high in my setup

edit: Not sure if it's better to edit or double post but I forgot to mention the clock stuff, how are you supposed to make the 4.9152 MHz PWM signal with the Arduino nano (ATmega328)'s 16MHz clock. Of course a 4 MHz signal is possible but the AD7730 is characterized around the 4.9152 MHz clock.

kaushik_ray_1

I wrote a similar code for AD7730 but for CC3200 controller @1200Hz. I wish i got this code that time. Great ref thanks a lot.

odalxen

void setup() { 
  Serial.begin(9600);
  Serial.println("My Sketch has started");
  if(DEBUG)
    Serial.println("Welcome");

  pinMode(RDY , INPUT);
  pinMode(MISO , INPUT);
  pinMode(RESET , OUTPUT);

  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  if(DEBUG)
    Serial.println("Reseting AD7730");

  time = millis();
  reset();
 
  if(DEBUG)
    Serial.println("Beggining Setup");
 
 
  //-----------Filter Configuration------------------------------- 
  if(DEBUG){
    Serial.println("Filter Default");
    sendByte(CR_SINGLE_READ | CR_FILTER_REGISTER);
    readBytes(3);
    Serial.println("Setting Up Filter");
  }
 
  sendByte(CR_SINGLE_WRITE | CR_FILTER_REGISTER);
  send3Bytes(FR2_SINC_AVERAGING_2048, FR1_SKIP_OFF | FR1_FAST_OFF, FR0_CHOP_ON);
 
 
  if(DEBUG){
    Serial.println("Filter set to ");
    sendByte(CR_SINGLE_READ | CR_FILTER_REGISTER);
    readBytes(3);
  }
  //--------------------------------------------------------------
  delay(30);
  //----------------DAC Configuration-----------------------------
  if(DEBUG){
    Serial.println("DAC Default");
    sendByte(CR_SINGLE_READ | CR_DAC_REGISTER);
    readBytes(1);
    Serial.println("Setting Up DAC");
  }
 
  sendByte(CR_SINGLE_WRITE | CR_DAC_REGISTER);
  sendByte(DACR_OFFSET_SIGN_POSITIVE | DACR_OFFSET_NONE);
 
  if(DEBUG){
    Serial.println("DAC set to ");
    sendByte(CR_SINGLE_READ | CR_DAC_REGISTER);
    readBytes(1);
  }
  //--------------------------------------------------------------
  delay(30);
  //---------Internal Zero Calibartion----------------------------
  if(DEBUG)
    Serial.println("Starting Internal Zero Calibartion");
   
   
  sendByte(CR_SINGLE_WRITE | CR_MODE_REGISTER);
  send2Bytes(MR1_MODE_INTERNAL_ZERO_CALIBRATION | CURRENT_MODE_1_SETTINGS, CURRENT_MODE_0_SETTINGS);

  waitForReady();

  if(DEBUG)
    Serial.println("Internal Zero Calibartion Done");
  //--------------------------------------------------------------

  //---------Internal Full Calibartion---------------------------- 
  if(DEBUG)
    Serial.println("Starting Internal Full Calibartion");
   
  sendByte(CR_SINGLE_WRITE | CR_MODE_REGISTER);
  send2Bytes(MR1_MODE_INTERNAL_FULL_CALIBRATION | CURRENT_MODE_1_SETTINGS, CURRENT_MODE_0_SETTINGS);

  waitForReady();

  if(DEBUG)
    Serial.println("Internal Full Calibartion Done");
  //--------------------------------------------------------------

  //---------------SET CONTINOUS MODE----------------------------- 
  if(DEBUG)
    Serial.println("Starting Continous Mode");
   
  sendByte(CR_SINGLE_WRITE | CR_MODE_REGISTER);
  send2Bytes(MR1_MODE_CONTINUOUS | CURRENT_MODE_1_SETTINGS, CURRENT_MODE_0_SETTINGS);

  while(digitalRead(RDY) != LOW) {
  }

  if(DEBUG)
    Serial.println("Continuous conv. started");

  //--------------------------------------------------------------
 
  //---------------START CONTINUOUS READ-------------------------- 
  if(DEBUG)
    Serial.println("Starting Continuous Read");
   
  sendByte(CR_CONTINUOUS_READ_START | CR_DATA_REGISTER);

  if(DEBUG)
    Serial.println("Reading started");
  //--------------------------------------------------------------

}


How is this if statement being initialized? I have tested this code, however, it just hangs in the welcome sketch statement. What are you doing with DEBUG, is it a arduino pin that you are toggeling?

Go Up