问题1:
switch(temp)
{
case 0: tempk = 0x87; break;
case 1: tempk = 0x97; break;
case 2: tempk = 0xA7; break;
case 3: tempk = 0xB7; break;
case 4: tempk = 0xC7; break;
case 5: tempk = 0xD7; break;
case 6: tempk = 0xE7; break;
case 7: tempk = 0xF7; break;
default: break;
}
正常的通道选择如上面的代码,但是在做八路循环检测的时候,却成了。硬件通道1输入,显示数据出现在4通道,硬件通道2输入,显示数据出现在1通道。。。等等,只有0通道和7号通道是显示与通道正确对应的。
问题2:
输入0.560V,循环测试显示集中在0.553V,并且循环数据不稳定,上下波动能到达10mV左右。
附上ADS8345读写函数和电路图:
unsigned int Read_ADS8345(unsigned char byte)
{
unsigned char temp,tempk;
unsigned int tempdata = 0;
DDRF = 0XFD;
PORTF = 0XF0;
temp = byte;
switch(temp)
{
case 0: tempk = 0x87; break;
case 1: tempk = 0x97; break;
case 2: tempk = 0xA7; break;
case 3: tempk = 0xB7; break;
case 4: tempk = 0xC7; break;
case 5: tempk = 0xD7; break;
case 6: tempk = 0xE7; break;
case 7: tempk = 0xF7; break;
default: break;
}
AD8345_clock_clr;
AD8345_datain_clr;
AD8345_cs_set;
delay_nus(1);
AD8345_cs_clr;
delay_nus(1);
for(temp = 0;temp < 8;temp++) //发控制字,收转换数据
{
if(tempk & 0x80) AD8345_datain_set; //输出控制字
else AD8345_datain_clr;
tempk <<= 1;
AD8345_clock_set; //产生一个时钟,上升沿
delay_nus(1); //上升沿写入数据
AD8345_clock_clr;
delay_nus(1);
}
AD8345_datain_clr;
AD8345_clock_clr;
delay_nus(50);
for(temp = 0;temp < 24;temp++) //发控制字,收转换数据
{
AD8345_clock_set;
delay_nus(5);
AD8345_clock_clr;
delay_nus(5);
if(AD8345_read_data)
tempdata |= 0x01; //读数据端口,获取转换值
else
tempdata &= 0xfffe;//CLR_BIT(tempdata,0);
if(temp<16)tempdata <<= 1;
delay_nus(1);
}
delay_nus(1);
AD8345_cs_set;
return tempdata;
} |