AnsweredAssumed Answered

Load Cell AD7730+SPI+atmega328

Question asked by Dante on Aug 16, 2012
Latest reply on Jan 26, 2015 by bobity

          Hi, I and my group are trying to use the IC ad7730bnz with atmega328(using the duemilanove board), the ready pin is always in high state, we don't know if we have done something wrong in the code, on hardware or both .

          We are using a 4.9152MHz crystal(made by sjk) with 15pF ceramic capacitor, we made our load cell(and it works with a comercial balance module ), the output of load cell is 8uV, the rest os circuit is in the chart below:

 

ad7730BNZ(pins)

1atmega 13 sck(SPI pin function)
2crystal (made by sjk) 4.9152MHz with 15pF
3crystal (made by sjk) 4.9152MHz with 15pF
4GND
55V
6atmega 9
7open
8GND
95V
10S+ (sense + from load cell)
11S- (sense - from load cell)
12open
13open
145V
15GND
16open
17open
185V
19atmega 10 ss(slave select, SPI pin function)
20atmega 8
21atmega 12 miso (master input slave output)
22

atmega 11 mosi (master output slave input)

235V
24GND

 

From the chart above we can see, that my group are using 5V as reference.

Code

#define reset 9
#define ss 10 //slave select
#define miso 12 
#define mosi 11
#define rdy 8
#define reset_all 3


#define lcd_linhas 2  // number of lines in your display
#define dout_pin  6  // Dout pin
#define strobe_pin 5  // Strobe pin
#define clock_pin 7  // Clock pin


#include <SPI.h>
#include <LCD3Wire.h>
#include <Stepper.h>
#include <avr/io.h>
#include <avr/wdt.h>


// commands do AD7730 datasheet
const byte comm_reg_filter= 0x03;
const byte comm_reg_mode = 0x02; 
const byte comm_reg_stop = 0x30; //stop continuos read
const byte comm_reg_gain = 0x06;
const byte comm_reg_dac = 0x04; 




const byte comm_reg_data = 0x21;
const byte dac_reg = 0x23; 


const byte mode_reg_config1 = 0xB1; 
const byte mode_reg_config2 = 0xB0; 


const byte mode_reg_config3 = 0x91; 
const byte mode_reg_config4 = 0x80; 


const byte mode_reg_config5 = 0x21; 
const byte mode_reg_config6 = 0x80; 




const byte mode_reg_tara_ext1 = 0xD1;
const byte mode_reg_tara_ext2 = 0x80;


const byte filter_reg1 = 0x80; 
const byte filter_reg2 = 0x00;
const byte filter_reg3 = 0x10;


const byte gain_reg1 = 0x00;//gain=500
const byte gain_reg2 = 0x01;
const byte gain_reg3 = 0xF4;


const int steps_per_revolution=200;


Stepper step_motor(steps_per_revolution, 15, 17, 16, 14);            
LCD3Wire lcd = LCD3Wire(lcd_linhas, dout_pin, strobe_pin, clock_pin);


const int taraExtpin = 2; 
const int resetPin = 3;
const int motorPassoA0 = 14; 
const int motorPassoA1 = 15; 
const int motorPassoA2 = 16; 
const int motorPassoA3 = 17; 


void setup()
{
  lcd.init(); 


  delay(2000);
  Serial.begin(9600);
  pinMode(reset , OUTPUT);
  digitalWrite(reset , HIGH);


  pinMode(ss , OUTPUT);
  pinMode(miso , INPUT);
  pinMode(mosi , OUTPUT);
  pinMode(rdy, INPUT);


  digitalWrite(ss , HIGH);


  pinMode(taraExtpin, INPUT);
  pinMode(reset_all, INPUT);
  digitalWrite(reset_all , HIGH);
  pinMode(motorPassoA0, OUTPUT);
  pinMode(motorPassoA1, OUTPUT);
  pinMode(motorPassoA2, OUTPUT);
  pinMode(motorPassoA3, OUTPUT);


  //-----------------------------------------------------------------------------------
  //SPI
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST); //
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  delay(100);
  //-----------------------------------------------------------------------------------




  //-----------------------------------------------------------------------------------
  //ad7730


    digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_gain); 
  SPI.transfer(gain_reg1);
  SPI.transfer(gain_reg2);
  SPI.transfer(gain_reg3);
  ready();
  digitalWrite(ss, HIGH);


  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_filter); 
  SPI.transfer(filter_reg1);
  SPI.transfer(filter_reg2);
  SPI.transfer(filter_reg3);
  ready();
  digitalWrite(ss, HIGH); 


  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_dac); 
  SPI.transfer(dac_reg);
  ready();
  digitalWrite(ss, HIGH); 




  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_mode);
  SPI.transfer(mode_reg_config1);
  SPI.transfer(mode_reg_config2);
  ready();
  digitalWrite(ss, HIGH);


  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_mode);
  SPI.transfer(mode_reg_config3);
  SPI.transfer(mode_reg_config4);
  ready();
  digitalWrite(ss, HIGH);


  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_mode);
  SPI.transfer(mode_reg_config5);
  SPI.transfer(mode_reg_config6);
  ready();
  digitalWrite(ss, HIGH);


}


//-----------------------------------------------------------------------------------


byte valor1=0;
byte valor2=0;
byte valor3=0;


byte valor1_de;
byte valor2_dec;
byte valor3_dec;
unsigned long valor_total=0;


void loop()
{


  attachInterrupt(0, tara_ext, FALLING); //digital pin 2 -> 0
  attachInterrupt(1, reseta_circuito, FALLING); //digital pin 3 -> 1


  int entradaA4 = analogRead(A4);
  int veloMotor = map(entradaA4, 0, 1023, 0, 100);


  transfere();


  valor_total=valor1<<16;
  valor2=valor2<<8;
  valor_total=  valor_total|valor2|valor3;
  valor_total=(valor_total*2)+valor_total;


  lcd.clear();
  lcd.print(valor1_dec);
  lcd.print(valor2_dec);
  lcd.print(valor3_dec);
  lcd.printIn(" gramas");
  Serial.print(valor_total);
  Serial.print("\n");


  step_motor.setSpeed(veloMotor);
  step_motor.step(steps_per_revolution);
}


//---------------------------------------------------------------------------------------
//subroutines


void ready()
{
volta:
  if(rdy==HIGH)goto volta;
  delay(10); 
}


byte transfere()
{
  digitalWrite(ss, LOW);
  delay(10);
  SPI.transfer(comm_reg_data); 
  while(rdy!=LOW)
  {
    valor1=  SPI.transfer(0x00);
    valor2=  SPI.transfer(0x00);
    valor3=  SPI.transfer(0x00);
  } 


  SPI.transfer(comm_reg_stop);
  digitalWrite(ss, HIGH);
  return valor1, valor2, valor3;
}


void tara_ext()// external tare
{


  digitalWrite(ss, LOW);
  SPI.transfer(comm_reg_mode);    
  SPI.transfer(mode_reg_config1);
  SPI.transfer(mode_reg_config2);
  delay(10);
  digitalWrite(ss, HIGH);


  digitalWrite(ss, LOW);
  SPI.transfer(comm_reg_mode);  
  SPI.transfer(mode_reg_tara_ext1);
  SPI.transfer(mode_reg_tara_ext2);
  delay(10);
  digitalWrite(ss, HIGH);


}


void reseta_circuito() //when pin 3 receives LOW the atmega and ad7730are reseted
{
  digitalWrite(reset,LOW); 
  cli();
  wdt_enable(WDTO_30MS);
  while(1) {  
  }
}

 

We get nothing in out put, we tried everything, changed the crystal, the capacitors, we have done the code from datasheet and nothing.

 

So we are here , any help will be very appreciated!

 

Thanks in advance, it's a long post and sorry for my bad english

Outcomes