已回答假定已回答

AD7708

motingwei 在 2015-7-2 詢問的問題
最後回覆由motingwei於2015-7-6提供

使用AD7708时发现,偶尔设备重新上电,CPU采集到AD7708输出的码值为全0或都32767.不知道是怎么回事,大部份时间芯片能正常工作,就是上电的时候会出现所有通道采集到的值都不变,一直是0或32767.以下是硬件和程序。断电后重新启动故障消失,芯片工作正常。

708.jpg

这是硬件连接,基准电压是2.5V,单端方式工作。

 

INT8U channel2[10] = {0x0f,0x1f,0x2f,0x3f,0x4f,0x5f,0x6f,0x7f,0xef,0xff};  //0-10v==0-65535

void SpiWrite (unsigned int data,unsigned char s )

{

  unsigned char i;

  //chop_select();//片选

  //spi_clk_hi();

  if(s == 0) s = 8;

  else s = 16;

  for(i=0;i<s;i++)

  {

  spi_clk_lo();//低时钟

  nop();

  nop();

  nop();

  nop();

  WDR();

  if(data&0x80)

  spi_data_hi();

  else

  spi_data_lo();

  spi_clk_hi();

  nop();

  nop();

  nop();

  nop();

  WDR();

 

  data = data << 1;

  }

   //chop_unselect();

}

unsigned int SpiRead (unsigned char s)

{

  int i,data=0;

  //chop_select();//片选

  //spi_clk_hi();

  if(s == 0) s = 8;

  else s = 16;

  for(i=0;i<s;i++)

  {

    data = data << 1;

  spi_clk_lo();

  WDR();

  nop();

  nop();

  nop();

  nop();

  if(AD7708_DATA)

  data |=  0x01;

  else

  data &= ~0x01;

  spi_clk_hi();

  nop();

  nop();

  nop();

  nop();

  WDR();

 

   }

   //chop_unselect();

   return(data);

}

void AD7708Init ( void )

{

  chop_select();//片选

  nop();

  nop();

  nop();

  nop();

  SpiWrite(0x07,0);//write I/O Control Register

  SpiWrite(0x30,0);

  SpiWrite(0x03,0);//write Filter Register

  SpiWrite(0x0D,0);

  SpiWrite(0x02,0);//ADC Control Register

  SpiWrite(0x0F,0);

  SpiWrite(0x01,0);//write Mode Register

  SpiWrite(0x02,0);//

  nop();

  chop_unselect();

}

void Start(unsigned char data)

{

  SpiWrite(0X01,0);//write Mode Register

  SpiWrite(0x02,0);//

  SpiWrite(0x02,0);//ADC控制寄存器

  SpiWrite(channel2[data],0);

}

 

 

unsigned int GegAdcValuea (unsigned char data)

{

  unsigned int i,temp_data = 0;

  //AD7708Init();

  chop_select();

  nop();

  Start(data);

  WDR();

  while(!AD7708_READY)

  WDR();

  SpiWrite(DATA_REG_R,0);//5

  temp_data = SpiRead(1);

  chop_unselect();

  return (temp_data);

}

結果