This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430f2619 ADC12多通道重复序列采样 查询方式,ADC采样结果跳动约15个码,多次平均结果一致



我采用的是从AD1顺序采样至AD5的采样序列,串口接收到5000D555指令将AD采样结果返至上位机,从反码看AD采样结果跳动,单片机电源纹波100MV以内和ADC参考电平是内部参考,纹波在100mV内,下面是我的程序,请各位帮忙看一下是否程序有问题。

void adc_init() {   ADC12CTL0&=~ENC;   ADC12CTL0 =REF2_5V + REFON+ SHT0_15 + ADC12ON+MSC;             // Set sampling time 16 ADC12CLK cycles, turn on ADC12,the first conversion tigger by SHI,the next conversion is trigged when the prior conversion is completed

   ADC12CTL1 = SHP+CONSEQ_3+ADC12SSEL_1+ADC12DIV_7  ;                          // Use sampling timer  

ADC12MCTL0 = INCH_0+SREF_1;                      // ref+=2.5v, channel = A0   ADC12MCTL1 = INCH_1+SREF_1;                      // ref+=2.5v, channel = A1 end of the conversion sequence  

 ADC12MCTL2 = INCH_2+SREF_1;                      // ref+=2.5v, channel = A2  

ADC12MCTL3 = INCH_3+SREF_1;  

 ADC12MCTL4 = INCH_4+SREF_1;                     // ref+=2.5v, channel = A5 end of the conversion sequence   ADC12MCTL5 = INCH_5+SREF_1+EOS;   ADC12IE=0x00;  

ADC12CTL0 |= ENC;                        

 // Conversion enabled }

void adc_process()

 {     ADC12CTL0&=~ENC;   //停止重复转换  

 int i=0;

  if(ad<30)

   {     A0results[ad] = ADC12MEM0;             // Move A0 results, IFG is cleared    

A1results[ad] = ADC12MEM1;             // Move A1 results, IFG is cleared    

A2results[ad] = ADC12MEM2;     

A3results[ad] = ADC12MEM3;    

A5results[ad] = ADC12MEM5;     

 ad++;

   }    

 if(ad==30)  

   {       ad=0;      

 for(i=0;i<30;i++)      

{       

 if(i>5)      

    {          sum0+=A0results[i];    

      sum1+=A1results[i];     

     sum2+=A2results[i];   

       sum3+=A3results[i];    

      sum5+=A5results[i];          }      

  sum0=sum0/25;        

 sum1=sum1/25;      

  sum2=sum2/25;       

sum3=sum3/25;       

 sum5=sum5/25;      

P1OUT^=0x80;     

   }  

    }  

ADC12CTL0|=ENC+ADC12SC; //开始新一轮转换

 }

void main(void)

 {   int iq0=0;   WDTCTL = WDTPW + WDTHOLD;             

    // Stop Watchdog Timer   BCSCTL1 &= ~XT2OFF;        //ACLK为XT1,开启XT2震荡  

do    

  {           IFG1 &= ~OFIFG;                  //清除振荡器失效标志        

   for (iq0=0xFF; iq0>0; iq0--);    //延时,等待XT2起振   

   }          

 while ((IFG1 & OFIFG)!= 0);   //判断XT2是否起振  

 BCSCTL2=SELM_2+SELS+DIVS_0+DIVM_0;               //选择MCLK、SMCLK为XT2

 BCSCTL3=XCAP_1+LFXT1S_0+ XT2S_2;    //XT1工作在32.768KHz的低频模式下,内部电容为6PF,XT2的频率为2-16MHZ 

  //********* port Initialize******//  

         port_init();      // P6SEL=0x3f

//********* timer Initialize******//   

   timer_init();  

//********* uart Initialize******//    

   uart_init();  

//********adc12 initialize*******//    

    adc_init();   //******dac inttialize******//   

    dac_init();  

    _EINT();     

 ADC12CTL0 |= ADC12SC;  // Start convn, software controlled

   while (1)  

        {     

 com_process();   

adc_process();   

 ios_adj();   // delay_ms(1);

 }

 }

程序进入了平均算法,P1.9是一个固定频率的脉冲