|
AD初始化程序段:
ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time
// to ××oid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0; // ref+=××cc, channel = A0
ADC12MCTL2 = INCH_2 + EOS; // ref+=××cc, channel = A2, end seq.
ADC12IE = 0x04; // Ena××e ADC12IFG.3
AD中断函数如下:
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR ( void )
{
static unsigned int index = 0;
ad_i++;
A0results[ ad_i ] = ADC12MEM0; // Move A0 results, IFG is cleared
A1results[ ad_i ] = ADC12MEM2; // Move A1 results, IFG is cleared
if( index != 1 ) //index = 1时的初次数据无效,舍去
{
A0××erage += A0results[ ad_i ];
A1××erage += A1results[ ad_i ];
}
/*
A0××erage += ADC12MEM0;
A1××erage += ADC12MEM2;
*/
index = ( index + 1 ) % ( Num_of_Results + 1); // Increment results index, modulo;
if ( index == 0 )
{
ADC12CTL0 &= 0xfffc; //关ADC
A0temp = A0××erage / Num_of_Results;
A1temp = A1××erage / Num_of_Results;
A0××erage = 0;
A1××erage = 0;
}
}
目的是采样4次取平均,但现在的情况是单步运行OK,连续运行存在明显的系统误差:测量值与真实值存在一定的比例关系,这是为什么???
|
|