我用一个高精度的万用表测量了一下,电压为2496.5mV,应该是很准的了。那么一定是程序出了问题了吗?AD部份用到的函数就两个,一个是初始化,一个是AD转换,我把程序贴上来,请帮我分析一下哪里有问题,多谢多谢啊!!!!
void AD_Init(void)
{
P6SEL |= BIT0+BIT1+BIT2; // Enable A/D channel A0 A1 A2
ADC12CTL0 = ADC12ON+MSC+SHT0_6; // Turn on ADC12, set
ADC12CTL1 = SHP+CONSEQ_1+ADC12SSEL_2; // Use sampling timer,
ADC12MCTL0 = INCH_0+SREF_7; // VeREF+=ref+, channel=A0
ADC12MCTL1 = INCH_1+SREF_7; // VeREF+=ref+, channel=A1
ADC12MCTL2 = INCH_2+SREF_7+EOS; // VeREF+=ref+, channel=A2. end seq
}
void AD_start(void)
{
char i,time;
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
for (i=0;i<20;i++) // 20次转换取平均
{
while (!(BIT2&ADC12IFG)); // wait untile AD conversion finished
AD_results[0] = ADC12MEM0; // Move results, IFG is cleared
AD_results[1] = ADC12MEM1; // Move results, IFG is cleared
AD_results[2] = ADC12MEM2; // Move results, IFG is cleared
AD_AVG[0] = AD_AVG[0] + AD_results[0];
AD_AVG[1] = AD_AVG[1] + AD_results[1];
AD_AVG[2] = AD_AVG[2] + AD_results[2];
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
}
ADC12CTL0 &= ~ENC; // disable conversions
for(i=0;i<3;i++)
AD_AVG = (unsigned long)(AD_AVG/AD_COUNT); // AD平均值
} |