AnsweredAssumed Answered

Hello adc 7682 problem

Question asked by kharade on Oct 18, 2011
Latest reply on Oct 18, 2011 by maithil

I am getting wrong output from the adc. Hardware config is corrcect-as per datasheet.

But I am not getting proper counts as expected.

My code samples are as below.

//Init code after power supply is on – 2 dummy bytes

void ad_7682_init()

{           unsigned int dummy=0;

            dummy=send_word_7682(0x3FFF);//dummy word

            dummy=send_word_7682(0x3FFF);//dummy word

}

//Configuring AD7682- continuous scanning. Unipolar channel with COM=Gnd.-Ext. ref, -  no temp

void ad_7682_cfg(void)

{           unsigned int dummy=0;

            dummy=send_word_7682(0x3BF7);

}

 

The data writing routine is as follows.

 

unsigned int send_word_7682(unsigned int w)

{           unsigned int sdi_word;

            select_chip = 0;                         //select the chip- CNV =LOW

            SPI2BUF = w;                            //send the 16 bit data to 16 bit SPI buf

            while(!SPI2STATbits.SPIRBF){;} //Wait till SPI conversion

            sdi_word=SPI2BUF;                  //read back the result

            select_chip = 1;                         //CNV = High  

            delay_us(2);                              //Conversion delay     

            return sdi_word;                                 

}

 

void get_spi_data(void)                         //Get data & store in array data[]
{  data[0]=send_word_7682(0x0);
  data[1]=send_word_7682(0x0);
  data[2]=send_word_7682(0x0);
  data[3]=send_word_7682(0x0);
}

 

int main (void)
{  unsigned char i;
  char buf1[20];
Init_Timer1();
Init_Port();
spi_init();
Uart_Init();
ad_7682_init();                              //dummy data at power up
ad_7682_cfg();                              //configure adc 7682
Uart_Puts("ADOR");
while (1)                    //Loop Endlessly - Execution is interrupt driven
      {   get_spi_data();                                    //Get 4 samples data from adc via spi
        for(i=0;i<3;i++) delay_ms(70);               //Delay between data samples
     

      for(i=0;i<4;i++)                                        //print 4 samples to uart
         {     sprintf(buf1,"%u ",data[i]);
              Uart_Puts(buf1);
         }
   Uart_Putc(0x0A);
  }                                                             //End of While
return 0;
}                                                                    //

 

Please guide me. The controller used is DSPIC6014. (16bit controller)

SPI initialisation is perfect & I can see clock pulses at clock pin of ADC.

The chip is getting selected & deselected correctly as per requirement.

The data send via microcontroller on SDO pin is received correctly on SDI pin of AD7682.

 

Please suggest

Outcomes