|
我用msp430G2433通过4片maix4618切换16路输入到2个AD通道(A0,A2).电压基准使用外接的LM385-2.5.在进行AD 转换时 ,ad值在输入不变的情况下,采集的数值最大会有5%的偏差。后来我用单通道连续采样4次取平均,结果没有改善。AD采集的信号来自放大器AD8551的输出。AD8551的输入通过MAX4618 选择不同的红外接收管。下面是AD相关程序,帮忙看看有没有问题
//////////////////////////////////////////////
//ad转换
//输入AD通道号,最大8
//输出AD数值
unsigned int AD_convert(unsigned char ad_channel)
{
ADC10CTL0 = SREF_2 + ADC10SHT_2 + MSC + ADC10ON + ADC10IE; //SREF_1 + ADC10SHT_2 + REFON + REF2_5V + ADC10ON + ADC10IE;// REF2_5V +
ADC10DTC1 = 0x04;
ADC10SA = (unsigned short) ad_tmp1;
if(ad_channel<8)
{
ADC10CTL1 = INCH_0 + ADC10DIV_3 + ADC10SSEL_3 + CONSEQ_2;
ADC10AE0 = 1;
}
else
{
ADC10CTL1 = INCH_2 + ADC10DIV_3 + ADC10SSEL_3 + CONSEQ_2;
ADC10AE0 = 4;
}
__delay_cycles(240);
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
LPM0;// __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
return (ad_tmp1[0]+ad_tmp1[1]+ad_tmp1[2]+ad_tmp1[3])/4;
}
/* Measure count result (capacitance) of each sensor*/
/* Routine setup for four sensors, not dependent on NUM_SEN value!*/
void measure_count(unsigned int *ad_data)
{
unsigned char i;
for (i = 0; i<8; i++)
{
channnel_select_1_8(i+1);
channnel_select_9_16(i+9);
__delay_cycles(36000);
*(ad_data+i) = AD_convert(i);
__delay_cycles(24);
*(ad_data+i+8) = AD_convert(i+8);
ADC10CTL0 = 0;
ADC10CTL0 = 0;
ADC10CTL1 = 0;
ADC10AE0 = 0;
P1DIR |= BIT0 + BIT2;
P1OUT &= ~(BIT0 + BIT2);
__delay_cycles(120);
P1DIR &= ~(BIT0 + BIT2);
}
DIS1_8;
DIS9_16;
// ADC10CTL0 = 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|