大学生,接触电路不久,正在过一个创新实验,用的基本是TI 的样片,最近在调试ADS1252,下面附上我的程序,但是有个小问题,测得的电压:a的值转化计算后于实际存在近两倍的误差,不知道哪里出了问题,特来请教论坛大神~多谢各位指点。测量值=a/(2^24)*5.0 是这样吗?
//ADS1251_4 ADS1252_CLK PAout(5)
//ADS1251_5 ADS1252_DOUT PCin(12)
//ADS1251_6 ADS1252_SCLK PCout(10)
void ADS1252_Config(void)
{
GPIO_QuickInit(HW_GPIOC,10,kGPIO_Mode_OPP);
GPIO_QuickInit(HW_GPIOA, 5,kGPIO_Mode_OPP);
GPIO_QuickInit(HW_GPIOC,12,kGPIO_Mode_IFT);
}
unsigned long int ADC_1252(void)
{
unsigned long int a;
unsigned char i;
a=0;
ADS1252_SCLK = 0;
ADS1252_CLK = 0;
//DRDY ģʽ,36¸öCLKÖÜÆÚ
for(i=0;i<48;i++) ADS1252_CLK = ~ADS1252_CLK; //t4
for(i=0;i<12;i++) ADS1252_CLK = ~ADS1252_CLK; //t2
for(i=0;i<12;i++) ADS1252_CLK = ~ADS1252_CLK; //t3
//DOUT ģʽ,348¸öCLKÖÜÆÚ
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_SCLK = 1;
if(ADS1252_DOUT==1) a|=0x01;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_SCLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0; //4¸öCLKÖÜÆÚ
for(i=0;i<23;i++)
{
a=a<<1;
if(ADS1252_DOUT==1) a|=0x01;
ADS1252_SCLK = 1;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_SCLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
} //4*23=92¸öCLKÖÜÆÚ
ADS1252_SCLK = 1;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_SCLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0;
ADS1252_CLK = 1;
ADS1252_CLK = 0; //4¸öCLKÖÜÆÚ
//248¸öCLKÖÜÆÚ
for(i=0;i<248;i++) {ADS1252_CLK = ~ADS1252_CLK;}
for(i=0;i<248;i++) {ADS1252_CLK = ~ADS1252_CLK;}
return a;
}
|