enguson

Why I am getting incorrect values when I read the data register of AD7714

Discussion created by enguson on Oct 18, 2015
Latest reply on Oct 26, 2015 by JellenieR

AD7714 i am getting unchanged value when I read the data register.

I try to develop a new project using PIC18F45K22, where I need to continuously read 5 strain gauges in pseudo differential mode.I am using all 5 channels.

The CS, SYNC,STANDBY pins are hardware wired to start the ADC using the reset pin only.

After initialization I read channel AN5/AN6 and AN1/AN6. I have placed a weight only on channel AN5/AN6 and I observed that the values increased also on channel AN1/AN6.

I have tried many ways to correctly read the channels without success.

Can anybody help ?

Here is my code:

 

#include <variabile.h>

 

// Functions-----------------------------------------------
void hard_init();
void variable_init();
void AD7714_init();
int ADC_Read_Analogue_16bit();

 


//***************************************************************************
void main() {

hard_init();
variable_init();
   AD7714_init();
  
  while(1)
  {
//AN1/AN6 ---------------------------------------------------------------------
   SPI2_Write( 0x5E);// next read data AN5/AN6
   while(ADC_DRDY) {}
      AN5_AN6 = ADC_Read_Analogue_16bit();


   IntToStr(AN5_AN6, txt);
    UART1_Write_Text("AN5_AN6");
          UART1_Write(0x09);//tab
    UART1_Write_Text(txt);
          UART1_Write(0x09);//tab
          UART1_Write(0x09);//tab

  //AN1/AN6 ---------------------------------------------------------------------
  SPI2_Write( 0x58);// next read data AN1/AN6
   while(ADC_DRDY) {}
      AN1_AN6 = ADC_Read_Analogue_16bit();


   IntToStr(AN1_AN6, txt);
    UART1_Write_Text("AN1_AN6 ");
          UART1_Write(0x09);//tab
    UART1_Write_Text(txt);
          UART1_Write(0x09);//tab
          UART1_Write(0x09);//tab


//-------------------------------------------------------------------------
// Reag back Reg. Filter Low ----------------------------------------------

    SPI2_Write( 0x3E); // next filter low read AN5/AN6
    //SPI2_Write( 0x3F); // next filter low read AN6/AN6
              val = My_SPI2_Read();
    ByteToHex(val, txt);
    UART1_Write_Text("LOW 0x");
    UART1_Write_Text(txt); 
    UART1_Write(' ');


     UART1_Write(10);

  Delay_ms(500);
}//while(1)
}//main

 


//=============================================================================
void AD7714_init()
{
ADC_ENABLE = 1; // pull high ADC  reset  PIN
Delay_MS(15);

  SPI2_Write(0x27);//  set the operation as a write to the FILTER HIGH register AIN6/AIN6 //
  SPI2_Write(0x10);// bipolar, 16bit word length NEG,DISAB, filter select = 0//  //250 data rate

  SPI2_Write(0x37);// set the operation as a write to the FILTER LOW register AIN6/AIN6
      SPI2_Write(0x4d);// 2.4576 MHz, -3Db cutoff 65.32987Hz, Data Rate 250 data rate//
    

// Calibration all register pairs
SPI2_Write(0x10);// next op. write to the MODE register AIN1/AIN6 Cal.Reg0//
      SPI2_Write(0x28);//self calibration, Gain4,no burnout no fsync//
       while(ADC_DRDY == 1){} // wait for /DRDY to go low //

SPI2_Write(0x11);// next op. write to the MODE register AIN2/AIN6 Cal.Reg1//
      SPI2_Write(0x28);// self calibration, Gain4,no burnout no fsync//
       while(ADC_DRDY == 1){} // wait for /DRDY to go low //
      
SPI2_Write(0x12);// next op. write to the MODE register AIN3/AIN6 Cal.Reg2//
      SPI2_Write(0x28);// self calibration, Gain4,no burnout no fsync//
       while(ADC_DRDY == 1){} // wait for /DRDY to go low //
      
SPI2_Write(0x13);// next op. write to the MODE register AIN4/AIN6 Cal.Reg2//
      SPI2_Write(0x28);// self calibration, Gain4,no burnout no fsync//
       while(ADC_DRDY == 1){} // wait for /DRDY to go low //

SPI2_Write(0x16);// next op. write to the MODE register AIN5/AIN6 Cal.Reg2//
      SPI2_Write(0x28);// self calibration, Gain4,no burnout no fsync//
       while(ADC_DRDY == 1){} // wait for /DRDY to go low //

}

 

//=============================================================================
unsigned char My_SPI2_Read()
{
unsigned char in_reg;

  SSP2BUF =0x00 ; //dummy write

  while (SSP2STAT.BF == 0) {}  //BF: Buffer Full.  0 = Receive not complete, SSPxBUF is empty
    in_reg = SSP2BUF;

return (in_reg);
}//  end My_SPI2_Read()

 

 

//=============================================================================
int ADC_Read_Analogue_16bit()
{
char local_read2;
char local_read1;
int AN_value;

local_read2 =  My_SPI2_Read();
local_read1 =  My_SPI2_Read();

AN_value = AN_value + local_read2;   AN_value << 8;
AN_value = AN_value + local_read1;

 

return  (AN_value);
}// end ADC_Read_Analogue_16bit()

Attachments

Outcomes