用的是内部电压参考,2.048V,当输入悬空或接地时。转换结果是
0x000109左右,而且基本上高12~16位不变,低位变化幅度也不大,貌似正常,但是输入一个零点几伏电压之后,结果就变化成0xFDDBXX 左右,高位字节也基本不变,但是转换的结果与实际不匹配,大于不知道是为什么。
下面是代码,求解答。
#include"ADS1248.h"
uchar idata channel_0[3];
uchar idata channel_1[3];
uchar idata channel_2[3];
uchar idata channel_3[3];
uchar idata channel_4[3];
void w_ads(uchar x,uchar y) //x寄存器地址,y寄存器内容
{
uchar i,RXBUF;
RXBUF = 128;
for(i = 8;i;i--)
{
adsclk = 1;
delay_us(2);
adsdin = (x&RXBUF)?1:0;
delay_us(2);
RXBUF = RXBUF>>1;
adsclk = 0;
delay_us(2);
}
for(i = 8;i;i--)
{
adsclk = 1;
delay_us(2);
adsdin = 0;
delay_us(2);
adsclk = 0;
delay_us(2);
}
RXBUF = 128;
for(i=8;i;i--)
{
adsclk = 1;
delay_us(2);
adsdin = (y&RXBUF)?1:0;
delay_us(2);
RXBUF = RXBUF>>1;
adsclk = 0;
delay_us(2);
}
}
void start_ad()
{
uchar channel[3];
uchar i,RXBUF;
RXBUF = 128;
for(i = 8;i;i--)
{
adsclk = 1;
delay_us(2);
adsdin = (0x06&RXBUF)?1:0;
delay_us(2);
RXBUF = RXBUF>>1;
adsclk = 0;
delay_us(2);
}
delay_ms(20);
//-----------选择通道,配置寄存器----------
w_ads(MUX0,29); //burnout current source off (default)
w_ads(VBIAS,0); // Bias voltage not enabled (default)
w_ads(MUX1,0x30); // Internal oscillator in use,Internal reference is always on,Normal operation (default)
w_ads(SYS0,2); // gain of the PGA = 1(default),output data rate of the ADC = 20SPS
w_ads(OFC0,0); //--------------------------------------------------------
w_ads(OFC1,0); // register value of 000000h provides no offset correction
w_ads(OFC2,0); //--------------------------------------------------------
w_ads(FSC0,0); //--------------------------------------------------------
w_ads(FSC1,0); // normalized to 1.0 at code 400000h
w_ads(FSC2,0x40); //------------------------------------------------------
w_ads(IDAC0,0); //DOUT/DRDY pin functions only as Data Out (default)
w_ads(IDAC1,0xCC);//DISCONNNECTED (default)
w_ads(GPIOCFG,0); //The pin is used as an analog input (default)
w_ads(GPIODIR,0); //The GPIO is an output (default)
//-------------start-------------
adstart = 1;
delay_us(1);
adstart = 0;
// delay_ms(60);
while(adsrdy);
rdata_ads(channel_0);
}
void rdata_ads(uchar channeldata[3])
{
uchar i,j,BUF;
BUF = 128;
//------写读命令------
for(i=8;i;i--)
{
adsclk = 1;
delay_us(2);
adsdin = (0x12&BUF)?1:0;
delay_us(2);
BUF = BUF>>1;
adsclk = 0;
delay_us(1);
}
//-------读出---------
for(i=8;i;i--)
{
adsclk = 1;
delay_us(2);
j = adsdout?1:0;
delay_us(2);
channeldata[0] = channeldata[0]<<1;
channeldata[0] = channeldata[0]|j;
adsclk = 0;
delay_us(2);
}
for(i=8;i;i--)
{
adsclk = 1;
delay_us(2);
j = adsdout?1:0;
delay_us(2);
channeldata[1] = channeldata[1]<<1;
channeldata[1] = channeldata[1]|j;
adsclk = 0;
delay_us(2);
}
for(i=8;i;i--)
{
adsclk = 1;
delay_us(2);
j = adsdout?1:0;
delay_us(2);
channeldata[2] = channeldata[2]<<1;
channeldata[2] = channeldata[2]|j;
adsclk = 0;
delay_us(2);
}
} |