我用AD7730做24位高精度转换,按理来说,AD采样,采到多少?就显示AD多少?可是转换出来始终显示是:16777215 这是什么意思?这不是长整型最大值吗?而且这个8位数一直跳动,不知让它如何稳定?这是程序的问题,还是电路上的问题?求大虾们指导一下?
这是程序:
这是程序:
void writebytetoAD7730(u8 writedata)
{
u8 i;
AD7730_CS=0;
for(i=0;i<8;i++)
{
AD7730_SCLK=0;
if(writedata&0x80)
AD7730_DATAIN=1;
else
AD7730_DATAIN=0;
writedata=writedata<<1;
AD7730_SCLK=1;
//Delay4us(); //延时4us
//AD7730_SCLK=0;
}
AD7730_DATAIN=0;
AD7730_CS=1;
}
u8 readbyteAD7730(void)
{
u8 i;
u8 readData;
AD7730_CS=0;
AD7730_DATAIN=0;
readData=0;
for(i=0;i<8;i++)
{
AD7730_SCLK=0;
readData= readData<<1;
if(AD7730_DOUT)
readData+=1;
AD7730_SCLK=1;
//Delay4us();
//AD7730_SCLK=0;
}
AD7730_CS=1;
return (readData);
}
void AD7730_Init(void)
{
u8 i;
writebytetoAD7730(0x03); //写通讯寄存器,下一次对滤波寄存器进行操作,
writebytetoAD7730(0x80); //设置滤波寄存器,50hz输出速率
writebytetoAD7730(0x00); //设置滤波寄存器
writebytetoAD7730(0x10); //50hz输出转换值,chop模式
writebytetoAD7730(0x04); //写通讯寄存器,下一次对DAC寄存器进行操作,
writebytetoAD7730(0x20); //2.5V基准电压输入
writebytetoAD7730(0x14); //read from DAC
i=readbyteAD7730();
writebytetoAD7730(0x02); //写通讯寄存器,下一次对模式寄存器进行操作,
writebytetoAD7730(0xb1); //internal fullscale calibration,unipolar input
//writebytetoAD7730(0x10); //2.5V基准电压输入,写模式寄存器0-20mV
writebytetoAD7730(0x02); //2.5V基准电压输入,写模式寄存器0-10mV
//while(AD7730_RDY) rst_wdt();
//delay_1ms(50);
writebytetoAD7730(0x02); //写通讯寄存器,下一次对模式寄存器进行操作,
writebytetoAD7730(0x91);
writebytetoAD7730(0x10); //进行零刻度校准,
//while(AD7730_RDY) rst_wdt();
//delay_1ms(50);
writebytetoAD7730(0x02); //写通讯寄存器,下一次对模式寄存器进行操作,
writebytetoAD7730(0x31); //continuous conversion mode,unipolar
writebytetoAD7730(0x10); //read from status
// while(AD7730_RDY) rst_wdt();
//delay_1ms(50);
}
long readAD7730ConversionData(void)
{
long sum=0;
u8 count;
long Converdata;
writebytetoAD7730(0x21);
AD7730_DATAIN=0;
//while(AD7730_RDY);
//delay_1ms(50);
if(!AD7730_RDY)
Converdata=0;
Converdata=readbyteAD7730();
Converdata=Converdata<<8;
Converdata=readbyteAD7730()+Converdata;
Converdata=Converdata<<8;
Converdata=readbyteAD7730()+Converdata;
writebytetoAD7730(0x30);
for(count=0;count<N;count++) //算术平均滤波运算
{
sum+=Converdata;
delay_1ms(2);
}
return(sum/N);
//return (Converdata);
}
|