#pragma vector = ADC12_VECTOR
__interrupt void ADC12_shuru(void)
{
ADCMix1[i]=ADC12MEM0; //想法是采样后的结果依次存入数组中
i++;
if(i >= ADlength)//一个电平的所有点进行处理,下抽样成为一个点
{
i=0;
ADCMix_Ave[ADC_Ave_Count] =0;
for(time=0;time
ADCMix_Ave[ADC_Ave_Count]+=ADCMix1[time];
ADCMix_Ave[ADC_Ave_Count] = ADCMix_Ave[ADC_Ave_Count]/(ADlength);
Trans_flag = 1; ADC12CTL0 &=~ADC12ENC;
}
}
void ADC12Init() //ADC设置,采样率为266KHz ,每个电平可采样77个点,下抽样成一个点,提高1位精度
{
ADC12CTL0 &= ~ADC12ENC; //转换器不使能才能设置
ADC12CTL0 = ADC12SHT0_3 + ADC12SHT1_3 + ADC12ON + ADC12MSC; // 设置采样保持时间,所有寄存器均设置时间为64/24MHz = 2.6μs以达到高采样速度
// ADC12CTL2 |= ADC12TCOFF ; // 关闭内部内部温度检测以降低功耗,注意或操作否则修改转换精度
ADC12CTL1 |= ADC12SHP + ADC12SSEL_2 + ADC12CONSEQ_2; //采样来自时钟定时器,时钟源为主时钟MCLK=24MHZ;重复单通道转换
ADC12MCTL0 = ADC12SREF_0+ ADC12INCH_0; //选择参考电压为AVcc与AVss,采样通道为外部通道A0,
ADC12IE |= ADC12IE0; //中断请求打开
ADC12CTL2 |= ADC12SR;
P6SEL |= BIT0; //设置采样通道A0,对应AD存储结果MEM0;
__delay_cycles(75); //??
ADC12CTL0 |= ADC12ENC; //转换器使能
}
****************************************************上面是我的ADC初始化模块和ADC中断代码
#pragma vector = TIMERB0_VECTOR
__interrupt void TB_Transform(void)
{
ADC12CTL0 |=ADC12ENC;
ADC12CTL0 |= ADC12SC;
// Delay_us(5);
}
********************************************************************这个是定时器B中断