本帖最后由 qinhuan7 于 2012-7-29 10:04 编辑
这是AD配置 P6SEL=0xFF; //A/D转换
ADC12CTL0&=~ADC12ENC; //在对控制位进行设置时要先复位转换允许位
ADC12CTL0=ADC12SHT0_8+ADC12MSC+ADC12ON; //4,3
ADC12CTL1=ADC12CSTARTADD_0+ADC12SHP+ADC12DIV_7+ADC12SSEL_2+ADC12CONSEQ_1; //7,4//转换速度是转换所需时间的倒数,此处为103kbps
ADC12MCTL0=ADC12SREF_6+ADC12INCH_0;
ADC12MCTL1=ADC12SREF_6+ADC12INCH_1;
ADC12MCTL2=ADC12SREF_6+ADC12INCH_2;
ADC12MCTL3=ADC12SREF_6+ADC12INCH_3;
ADC12MCTL4=ADC12SREF_6+ADC12INCH_4;
ADC12MCTL5=ADC12SREF_6+ADC12INCH_5;
ADC12MCTL6=ADC12SREF_6+ADC12INCH_6;
ADC12MCTL7=ADC12EOS+ADC12SREF_6+ADC12INCH_7;
ADC12IFG=0;
ADC12IE=BIT7; //BIT7,1
ADC12CTL0=ADC12CTL0|ADC12ENC;
ADC12CTL0|=ADC12SC; //启动AD采样
AD中断
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{ char i,j;
int tmp;
long sum0,sum1,sum2,sum3,sum4,sum5,sum6,sum7;
switch(ADC12IV)
{
case 0x14:
{ time_flag=0;
ADC12IE=0;
_EINT();
inch[0][ad_cnt]=ADC12MEM0;
inch[1][ad_cnt]=ADC12MEM1;
inch[2][ad_cnt]=ADC12MEM2;
inch[3][ad_cnt]=ADC12MEM3;
inch[4][ad_cnt]=ADC12MEM4;
inch[5][ad_cnt]=ADC12MEM5;
inch[6][ad_cnt]=ADC12MEM6;
inch[7][ad_cnt]=ADC12MEM7;
ad_cnt++;
ADC12IFG=0;
if(ad_cnt<40)
{ delay(20);
ADC12CTL0|=ADC12SC;
}
else
{ WDT_CTL();
ad_flag++; //用于开机连续采样12的标志
sum0=0;sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;sum7=0;
for(i=0;i<39;i++)
{ for(j=0;j<39-i;j++)
{ if(inch[0][j]>inch[0][j+1]){tmp=inch[0][j];inch[0][j]=inch[0][j+1];inch[0][j+1]=tmp;}
if(inch[1][j]>inch[1][j+1]){tmp=inch[1][j];inch[1][j]=inch[1][j+1];inch[1][j+1]=tmp;}
if(inch[2][j]>inch[2][j+1]){tmp=inch[2][j];inch[2][j]=inch[2][j+1];inch[2][j+1]=tmp;}
if(inch[3][j]>inch[3][j+1]){tmp=inch[3][j];inch[3][j]=inch[3][j+1];inch[3][j+1]=tmp;}
if(inch[4][j]>inch[4][j+1]){tmp=inch[4][j];inch[4][j]=inch[4][j+1];inch[4][j+1]=tmp;}
if(inch[5][j]>inch[5][j+1]){tmp=inch[5][j];inch[5][j]=inch[5][j+1];inch[5][j+1]=tmp;}
if(inch[6][j]>inch[6][j+1]){tmp=inch[6][j];inch[6][j]=inch[6][j+1];inch[6][j+1]=tmp;}
if(inch[7][j]>inch[7][j+1]){tmp=inch[7][j];inch[7][j]=inch[7][j+1];inch[7][j+1]=tmp;}
}
}
for(j=4;j<36;j++) //求均值
{ sum0+=inch[0][j];
sum1+=inch[1][j];
sum2+=inch[2][j];
sum3+=inch[3][j];
sum4+=inch[4][j];
sum5+=inch[5][j];
sum6+=inch[6][j];
sum7+=inch[7][j];
}
for(j=0;j<11;j++) //滑动滤波
{ channel[0][j]=channel[0][j+1];
channel[1][j]=channel[1][j+1];
channel[2][j]=channel[2][j+1];
channel[3][j]=channel[3][j+1];
channel[4][j]=channel[4][j+1];
channel[5][j]=channel[5][j+1];
channel[6][j]=channel[6][j+1];
channel[7][j]=channel[7][j+1];
}
channel[0][11]=sum0>>5;
channel[1][11]=sum1>>5;
channel[2][11]=sum2>>5;
channel[3][11]=sum3>>5;
channel[4][11]=sum4>>5;
channel[5][11]=sum5>>5;
channel[6][11]=sum6>>5;
channel[7][11]=sum7>>5;
}
break;
}
default: break;
}
ADC12IFG=0;
ADC12IE=BIT7;
}
问题:上电后用串口发回的数据在一段时间内是正常的,但是过一段时间后(时间不确定),AD就停止工作了,串口发回的数据不变,请教各位大虾这是怎么回事? |