TI中文支持网
TI专业的中文技术问题搜集分享网站

2812的ADC

输入信号稳定,但是ADC不稳定

SysCtrlRegs.HISPCP.all = 0x0001; // HSPCLK=150/2=75MHz

void InitEv(void)
{
     EvaRegs.T1CON.bit.TMODE=2;      //¼ÆÊýģʽΪÁ¬ÐøÔö¼ÆÊý
     EvaRegs.T1CON.bit.TPS=1;        //T1CLK=HSPCLK/2=37.5MHz
     EvaRegs.T1CON.bit.TENABLE=0;    //ÔÝʱ½ûÖ¹T1¼ÆÊý
//     EvaRegs.T1CON.bit.TENABLE=1;            //Æô¶¯T1¼ÆÊý
     EvaRegs.T1CON.bit.TCLKS10=0;    //ʹÓÃÄÚ²¿Ê±ÖÓ
  EvaRegs.T1CON.bit.TCLD10=2;
     EvaRegs.GPTCONA.bit.T1TOADC=2;  //ÖÜÆÚÖжÏÆô¶¯ADC
     EvaRegs.EVAIMRA.bit.T1PINT=1;   //ʹÄܶ¨Ê±Æ÷T1µÄÖÜÆÚÖжÏ
     EvaRegs.EVAIFRA.bit.T1PINT=1;   //Çå³ý¶¨Ê±Æ÷T1µÄÖÜÆÚÖжϱê־λ
  EvaRegs.T1PR=0xEA5;
     EvaRegs.T1CNT=0;                //³õʼ»¯¼ÆÊýÆ÷¼Ä´æÆ÷
}

void ADC_init(void)
{
//    Uint16 i;
    AdcRegs.ADCTRL1.bit.RESET=1;     asm(" NOP ");           //¸´Î»
 AdcRegs.ADCTRL1.bit.RESET=0;
 AdcRegs.ADCTRL1.bit.SUSMOD=3;             ////·ÂÕæÔÝͣʱ£¬ÐòÁз¢ÉúÆ÷ºÍÆäËûÊý×Öµç·Âß¼­Á¢¼´Í£Ö¹
    AdcRegs.ADCTRL1.bit.ACQ_PS=0;             //²ÉÑù´°¿Ú´óС£¬SOCÂö³å¿í¶ÈΪ1¸öADCLK
//    AdcRegs.ADCTRL1.bit.ACQ_PS=0xF;
    AdcRegs.ADCTRL1.bit.CPS=0;                //ºËʱÖÓÔ¤¶¨±êÆ÷£¬µÈÓÚ0£¬Î´½«Ê±ÖÓ½øÐÐ2·ÖƵ
    AdcRegs.ADCTRL1.bit.CONT_RUN=0;           //Í£Ö¹¿ªÊ¼Ä£Ê½
 AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0;           //½ûÓø²¸Çģʽ
    AdcRegs.ADCTRL1.bit.SEQ_CASC=1;           //¼¶ÁªÄ£Ê½
    AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;   //´ø¼ä϶²Î¿¼µç·Éϵç
 DELAY_US(8000l);                          //µÈ´ýÎȶ¨
//    for(i= 0; i< 10000; i++){}
 AdcRegs.ADCTRL3.bit.ADCPWDN = 1;    //ÆäËûµç·Éϵç
 DELAY_US(20l);                            //µÈ´ýÎȶ¨
//    for(i= 0; i< 5000; i++){}
// AdcRegs.ADCTRL3.bit.ADCCLKPS=15;          //ADCCLK=HSPCLK/(15+2)=75/6=12.5MHz
    AdcRegs.ADCTRL3.bit.ADCCLKPS=0x12C;
    AdcRegs.ADCTRL3.bit.SMODE_SEL=0;          //˳Ðò²ÉÑù
 AdcRegs.ADCTRL3.bit.EXTREF=0;             //ʹÄÜADCREFPºÍADCREFM£¬Ê¹ÓÃÄÚ²¿²Î¿¼
 AdcRegs.MAX_CONV.bit.MAX_CONV=3;         //×ܹ²²ÉÑù4·
    AdcRegs.CHSELSEQ1.bit.CONV00=0;      //²ÉÑùADCINA0
 AdcRegs.CHSELSEQ1.bit.CONV01=1;      //²ÉÑùADCINA1
 AdcRegs.CHSELSEQ1.bit.CONV02=2;      //²ÉÑùADCINA0
 AdcRegs.CHSELSEQ1.bit.CONV03=3;      //²ÉÑùADCINA3

 AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1; //Çå³ýSEQ1ÖеÄÖжϱê־λINT_SEQ1
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1; //Çå³ýSEQ2ÖеÄÖжϱê־λINT_SEQ2

 AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ=0;        //½ûÖ¹EVB´¥·¢Æô¶¯SEQ
    AdcRegs.ADCTRL2.bit.RST_SEQ1=0;
 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1;       //ÔÊÐíSEQ1ÖжÏ
 AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1=0;       //ÿ¸öSEQÐòÁÐÐòÁнáÊøʱ£¬SEQ1ÖÃλ
    AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1=1;       //ÔÊÐíEVA´¥·¢Æô¶¯SEQ
    AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1=0;
    AdcRegs.ADCTRL2.bit.RST_SEQ2=0;
    AdcRegs.ADCTRL2.bit.SOC_SEQ2=0;
 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ2=0;       //½ûÖ¹SEQ2ÖжÏ
    AdcRegs.ADCTRL2.bit.INT_MOD_SEQ2=0;
 AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ2=0;       //EVBÐźŲ»ÄÜÆô¶¯SEQ2
    AdcRegs.ADCTRL2.bit.SOC_SEQ1=0;

}

interrupt void  ADCINT_ISR(void)     // ADCÖжϺ¯Êý
{
    DINT;   //¹ØÖжÏ
  // ÔÚÕâÀï²åÈëÖжϺ¯ÊýµÄ´úÂë
    SampleCount++; //²ÉÑù¼ÆÊýÆ÷¼ÆÊý
    CurrentChanA0=AdcRegs.RESULT0>>4;
 CurrentChanA1=AdcRegs.RESULT1>>4;
 CurrentChanA2=AdcRegs.RESULT2>>4;
 CurrentChanA3=AdcRegs.RESULT3>>4;

   adcresulta0[SampleCount-1]=CurrentChanA0; //½«ADCINA0ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta0[]ÖÐ
         adcresulta1[SampleCount-1]=CurrentChanA1; //½«ADCINA1ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta1[]ÖÐ
         adcresulta2[SampleCount-1]=CurrentChanA2; //½«ADCINA2ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta2[]ÖÐ
         adcresulta3[SampleCount-1]=CurrentChanA3; //½«ADCINA3ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta3[]ÖÐ

         if(SampleCount==10) //²ÉÑùÊ®´ÎÖ®ºó£¬ÐèÒª½øÐÐÂ˲¨´¦Àí
         {
              Uint16 i;
              i=0;                    dataI0=0;
              dataI1=0;
              dataI2=0;
            dataI3=0;
  
              sequence(adcresulta0,10); //¶Ô²ÉÑùÊ®´ÎµÃµ½µÄÊý¾Ý½øÐÐÅÅÐò
              sequence(adcresulta1,10);              sequence(adcresulta2,10);
              sequence(adcresulta3,10);                      for(i=3;i<7;i++)
              {
                   dataI0=dataI0+adcresulta0[i]; //ÖÐÖµÂ˲¨·¨
                   dataI1=dataI1+adcresulta1[i]; //È¥µô×îСµÄ3¸öºÍ×î´óµÄ3¸ö                   dataI2=dataI2+adcresulta2[i]; //È¡ÖмäµÄ4¸öÊý¾Ý½øÐÐÇóºÍ
                   dataI3=dataI3+adcresulta3[i];
              }
     SampleCount=0; //Çå²ÉÑù¼ÆÊýÆ÷£¬½øÈëеÄÁ¬ÐøÊ®´ÎµÄ²ÉÑù
     dataI0=dataI0/4; //¼ÆËã4¸ö²ÉÑùÊý¾ÝµÄƽ¾ùÖµ
     dataI1=dataI1/4;     dataI2=dataI2/4;
     dataI3=dataI3/4;

     dataI0=dataI0-2131.8;         dataI0=fabs(dataI0);
     AlarmIA0=dataI0*1000/1630.75;                  dataI1=dataI1-2145;
     dataI1=fabs(dataI1);
     AlarmIA1=dataI1*1000/1630.75;                           dataI2=dataI2-2078.5;
     dataI2=fabs(dataI2);
     AlarmIA2=dataI2*1000/1630.75;                  dataI3=dataI3-2146.4;
     dataI3=fabs(dataI3);
     AlarmIA3=dataI3*1000/1630.75;
     timer1_count++;
     if(timer1_count<=10)
              {
                        MaxIA0=(dataI0>=MaxIA0)?dataI0:MaxIA0;
                   MaxIA1=(dataI1>=MaxIA1)?dataI1:MaxIA1;
                   MaxIA2=(dataI2>=MaxIA2)?dataI2:MaxIA2;
                   MaxIA3=(dataI3>=MaxIA3)?dataI3:MaxIA3;
              }

           if(timer1_count==10)
           {

                  Irms0=MaxIA0*1000/1841;                  Irms1=MaxIA1*1000/1630.75;               Irms2=MaxIA2*1000/1630.75;
            Irms3=MaxIA3*1000/1630.75;
            MaxIA0=0;
            MaxIA1=0;
            MaxIA2=0;
            MaxIA3=0;  
            timer1_count=0;   
           }                                                
          }
                 PieCtrl.PIEACK.bit.ACK1=1;                           //ÏàÓ¦PIEͬ×éÖжÏ
 AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;                        //Çå³ýADÖжϱê־λ
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1;
// AdcRegs.ADCTRL2.bit.RST_SEQ1=1;                         //¸´Î»ÐòÁз¢ÉúÆ÷SEQ
    AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;  //Á¢¼´Æô¶¯ÏÂÒ»´Îת»»
 EINT;
  // ×¢ÒâÍ˳öÖжϺ¯ÊýʱÐèÒªÏÈÊÍ·ÅPIE£¬Ê¹µÃPIEÄܹ»ÏìӦͬ×éÆäËûÖжϠ // PieCtrl.PIEACK.all = PIEACK_GROUP1;
   // ÏÂÃæÁ½ÐÐÖ»ÊÇΪÁ˱àÒë¶øдµÄ£¬²åÈë´úÂëºóÇ뽫Æäɾ³ý
   // ÖжϺ¯Êý´úÂë
  //   asm ("      ESTOP0");
  //   for(;;);

  // ·µ»Ø;
}

 

我的ADC采集总是不稳定,信号是50hz的交流电流

Johnson Chen1:

ADC测试结果有多大误差?

输入信号稳定,但是ADC不稳定

SysCtrlRegs.HISPCP.all = 0x0001; // HSPCLK=150/2=75MHz

void InitEv(void)
{
     EvaRegs.T1CON.bit.TMODE=2;      //¼ÆÊýģʽΪÁ¬ÐøÔö¼ÆÊý
     EvaRegs.T1CON.bit.TPS=1;        //T1CLK=HSPCLK/2=37.5MHz
     EvaRegs.T1CON.bit.TENABLE=0;    //ÔÝʱ½ûÖ¹T1¼ÆÊý
//     EvaRegs.T1CON.bit.TENABLE=1;            //Æô¶¯T1¼ÆÊý
     EvaRegs.T1CON.bit.TCLKS10=0;    //ʹÓÃÄÚ²¿Ê±ÖÓ
  EvaRegs.T1CON.bit.TCLD10=2;
     EvaRegs.GPTCONA.bit.T1TOADC=2;  //ÖÜÆÚÖжÏÆô¶¯ADC
     EvaRegs.EVAIMRA.bit.T1PINT=1;   //ʹÄܶ¨Ê±Æ÷T1µÄÖÜÆÚÖжÏ
     EvaRegs.EVAIFRA.bit.T1PINT=1;   //Çå³ý¶¨Ê±Æ÷T1µÄÖÜÆÚÖжϱê־λ
  EvaRegs.T1PR=0xEA5;
     EvaRegs.T1CNT=0;                //³õʼ»¯¼ÆÊýÆ÷¼Ä´æÆ÷
}

void ADC_init(void)
{
//    Uint16 i;
    AdcRegs.ADCTRL1.bit.RESET=1;     asm(" NOP ");           //¸´Î»
 AdcRegs.ADCTRL1.bit.RESET=0;
 AdcRegs.ADCTRL1.bit.SUSMOD=3;             ////·ÂÕæÔÝͣʱ£¬ÐòÁз¢ÉúÆ÷ºÍÆäËûÊý×Öµç·Âß¼­Á¢¼´Í£Ö¹
    AdcRegs.ADCTRL1.bit.ACQ_PS=0;             //²ÉÑù´°¿Ú´óС£¬SOCÂö³å¿í¶ÈΪ1¸öADCLK
//    AdcRegs.ADCTRL1.bit.ACQ_PS=0xF;
    AdcRegs.ADCTRL1.bit.CPS=0;                //ºËʱÖÓÔ¤¶¨±êÆ÷£¬µÈÓÚ0£¬Î´½«Ê±ÖÓ½øÐÐ2·ÖƵ
    AdcRegs.ADCTRL1.bit.CONT_RUN=0;           //Í£Ö¹¿ªÊ¼Ä£Ê½
 AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0;           //½ûÓø²¸Çģʽ
    AdcRegs.ADCTRL1.bit.SEQ_CASC=1;           //¼¶ÁªÄ£Ê½
    AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;   //´ø¼ä϶²Î¿¼µç·Éϵç
 DELAY_US(8000l);                          //µÈ´ýÎȶ¨
//    for(i= 0; i< 10000; i++){}
 AdcRegs.ADCTRL3.bit.ADCPWDN = 1;    //ÆäËûµç·Éϵç
 DELAY_US(20l);                            //µÈ´ýÎȶ¨
//    for(i= 0; i< 5000; i++){}
// AdcRegs.ADCTRL3.bit.ADCCLKPS=15;          //ADCCLK=HSPCLK/(15+2)=75/6=12.5MHz
    AdcRegs.ADCTRL3.bit.ADCCLKPS=0x12C;
    AdcRegs.ADCTRL3.bit.SMODE_SEL=0;          //˳Ðò²ÉÑù
 AdcRegs.ADCTRL3.bit.EXTREF=0;             //ʹÄÜADCREFPºÍADCREFM£¬Ê¹ÓÃÄÚ²¿²Î¿¼
 AdcRegs.MAX_CONV.bit.MAX_CONV=3;         //×ܹ²²ÉÑù4·
    AdcRegs.CHSELSEQ1.bit.CONV00=0;      //²ÉÑùADCINA0
 AdcRegs.CHSELSEQ1.bit.CONV01=1;      //²ÉÑùADCINA1
 AdcRegs.CHSELSEQ1.bit.CONV02=2;      //²ÉÑùADCINA0
 AdcRegs.CHSELSEQ1.bit.CONV03=3;      //²ÉÑùADCINA3

 AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1; //Çå³ýSEQ1ÖеÄÖжϱê־λINT_SEQ1
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1; //Çå³ýSEQ2ÖеÄÖжϱê־λINT_SEQ2

 AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ=0;        //½ûÖ¹EVB´¥·¢Æô¶¯SEQ
    AdcRegs.ADCTRL2.bit.RST_SEQ1=0;
 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1;       //ÔÊÐíSEQ1ÖжÏ
 AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1=0;       //ÿ¸öSEQÐòÁÐÐòÁнáÊøʱ£¬SEQ1ÖÃλ
    AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1=1;       //ÔÊÐíEVA´¥·¢Æô¶¯SEQ
    AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1=0;
    AdcRegs.ADCTRL2.bit.RST_SEQ2=0;
    AdcRegs.ADCTRL2.bit.SOC_SEQ2=0;
 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ2=0;       //½ûÖ¹SEQ2ÖжÏ
    AdcRegs.ADCTRL2.bit.INT_MOD_SEQ2=0;
 AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ2=0;       //EVBÐźŲ»ÄÜÆô¶¯SEQ2
    AdcRegs.ADCTRL2.bit.SOC_SEQ1=0;

}

interrupt void  ADCINT_ISR(void)     // ADCÖжϺ¯Êý
{
    DINT;   //¹ØÖжÏ
  // ÔÚÕâÀï²åÈëÖжϺ¯ÊýµÄ´úÂë
    SampleCount++; //²ÉÑù¼ÆÊýÆ÷¼ÆÊý
    CurrentChanA0=AdcRegs.RESULT0>>4;
 CurrentChanA1=AdcRegs.RESULT1>>4;
 CurrentChanA2=AdcRegs.RESULT2>>4;
 CurrentChanA3=AdcRegs.RESULT3>>4;

   adcresulta0[SampleCount-1]=CurrentChanA0; //½«ADCINA0ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta0[]ÖÐ
         adcresulta1[SampleCount-1]=CurrentChanA1; //½«ADCINA1ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta1[]ÖÐ
         adcresulta2[SampleCount-1]=CurrentChanA2; //½«ADCINA2ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta2[]ÖÐ
         adcresulta3[SampleCount-1]=CurrentChanA3; //½«ADCINA3ͨµÀ²ÉÑùµ½µÄÊý¾Ý´æÈëÊý×éadcresulta3[]ÖÐ

         if(SampleCount==10) //²ÉÑùÊ®´ÎÖ®ºó£¬ÐèÒª½øÐÐÂ˲¨´¦Àí
         {
              Uint16 i;
              i=0;                    dataI0=0;
              dataI1=0;
              dataI2=0;
            dataI3=0;
  
              sequence(adcresulta0,10); //¶Ô²ÉÑùÊ®´ÎµÃµ½µÄÊý¾Ý½øÐÐÅÅÐò
              sequence(adcresulta1,10);              sequence(adcresulta2,10);
              sequence(adcresulta3,10);                      for(i=3;i<7;i++)
              {
                   dataI0=dataI0+adcresulta0[i]; //ÖÐÖµÂ˲¨·¨
                   dataI1=dataI1+adcresulta1[i]; //È¥µô×îСµÄ3¸öºÍ×î´óµÄ3¸ö                   dataI2=dataI2+adcresulta2[i]; //È¡ÖмäµÄ4¸öÊý¾Ý½øÐÐÇóºÍ
                   dataI3=dataI3+adcresulta3[i];
              }
     SampleCount=0; //Çå²ÉÑù¼ÆÊýÆ÷£¬½øÈëеÄÁ¬ÐøÊ®´ÎµÄ²ÉÑù
     dataI0=dataI0/4; //¼ÆËã4¸ö²ÉÑùÊý¾ÝµÄƽ¾ùÖµ
     dataI1=dataI1/4;     dataI2=dataI2/4;
     dataI3=dataI3/4;

     dataI0=dataI0-2131.8;         dataI0=fabs(dataI0);
     AlarmIA0=dataI0*1000/1630.75;                  dataI1=dataI1-2145;
     dataI1=fabs(dataI1);
     AlarmIA1=dataI1*1000/1630.75;                           dataI2=dataI2-2078.5;
     dataI2=fabs(dataI2);
     AlarmIA2=dataI2*1000/1630.75;                  dataI3=dataI3-2146.4;
     dataI3=fabs(dataI3);
     AlarmIA3=dataI3*1000/1630.75;
     timer1_count++;
     if(timer1_count<=10)
              {
                        MaxIA0=(dataI0>=MaxIA0)?dataI0:MaxIA0;
                   MaxIA1=(dataI1>=MaxIA1)?dataI1:MaxIA1;
                   MaxIA2=(dataI2>=MaxIA2)?dataI2:MaxIA2;
                   MaxIA3=(dataI3>=MaxIA3)?dataI3:MaxIA3;
              }

           if(timer1_count==10)
           {

                  Irms0=MaxIA0*1000/1841;                  Irms1=MaxIA1*1000/1630.75;               Irms2=MaxIA2*1000/1630.75;
            Irms3=MaxIA3*1000/1630.75;
            MaxIA0=0;
            MaxIA1=0;
            MaxIA2=0;
            MaxIA3=0;  
            timer1_count=0;   
           }                                                
          }
                 PieCtrl.PIEACK.bit.ACK1=1;                           //ÏàÓ¦PIEͬ×éÖжÏ
 AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;                        //Çå³ýADÖжϱê־λ
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1;
// AdcRegs.ADCTRL2.bit.RST_SEQ1=1;                         //¸´Î»ÐòÁз¢ÉúÆ÷SEQ
    AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;  //Á¢¼´Æô¶¯ÏÂÒ»´Îת»»
 EINT;
  // ×¢ÒâÍ˳öÖжϺ¯ÊýʱÐèÒªÏÈÊÍ·ÅPIE£¬Ê¹µÃPIEÄܹ»ÏìӦͬ×éÆäËûÖжϠ // PieCtrl.PIEACK.all = PIEACK_GROUP1;
   // ÏÂÃæÁ½ÐÐÖ»ÊÇΪÁ˱àÒë¶øдµÄ£¬²åÈë´úÂëºóÇ뽫Æäɾ³ý
   // ÖжϺ¯Êý´úÂë
  //   asm ("      ESTOP0");
  //   for(;;);

  // ·µ»Ø;
}

 

我的ADC采集总是不稳定,信号是50hz的交流电流

zhaogong zhao:

回复 Johnson Chen1:

结果是跳动比较厉害。我的信号是通过放大器,把交流50hz的电流信号,抬高到y轴正半轴上。我把互感器短接,就相当于电流的0点,读出此时的码值,这个值波动也挺大,有时为2137,有时为2361,然后每次读出的值减去这个码值,就相当于真实的电流码值,再半波取绝对值,找出最大值,这个最大值也是波动挺大,有时为292,有时为430.

赞(0)
未经允许不得转载:TI中文支持网 » 2812的ADC
分享到: 更多 (0)