[MSP430] ADC的采样误差很大问题

2019-03-24 09:03发布


用的是TI的例程进行采样,参考电压为3.3V,12位,计算公式为:采样电压 = (ADC采样数据 / 4096 ) * 3.3 V


在例程中用单步调试采3.3V电压看数据,数据总是在3700-3800之间起伏,距离4096还有一段距离,也就是误差很大,请问关于误差这点需要怎么消除呢?

已通过采20次电压取平均值,结果也在3700-3800之间起伏。

下面是例程
  1. #include "driverlib.h"

  2. uint16_t Value_AD = 0;
  3. uint16_t ADC_Get_Value = 0; // ADC采到的原始数据
  4. uint16_t ADV_Get_Aver_Value = 0; //用于计算采ADC的平均值


  5. void main(void)
  6. {
  7.     // Stop WDT
  8.     WDT_A_hold(WDT_A_BASE);

  9.     //Set P1.0 as an output pin.
  10.     /*

  11.      * Select Port 1
  12.      * Set Pin 0 as output
  13.      */
  14.     GPIO_setAsOutputPin(
  15.         GPIO_PORT_P1,
  16.         GPIO_PIN0
  17.         );

  18.     //Set P1.0 as Output Low.
  19.     /*

  20.      * Select Port 1
  21.      * Set Pin 0 to output Low.
  22.      */
  23.     GPIO_setOutputLowOnPin(
  24.         GPIO_PORT_P1,
  25.         GPIO_PIN0
  26.         );
  27.     //Set P1.1 as Ternary Module Function Output.
  28.     /*

  29.      * Select Port 1
  30.      * Set Pin 1 to output Ternary Module Function, (A1, C1, VREF+, VeREF+).
  31.      */


  32.     GPIO_setAsPeripheralModuleFunctionOutputPin(
  33.         GPIO_PORT_P3,
  34.         GPIO_PIN0,
  35.         GPIO_TERNARY_MODULE_FUNCTION
  36.         );

  37.     /*
  38.      * Disable the GPIO power-on default high-impedance mode to activate
  39.      * previously configured port settings
  40.      */
  41.     PMM_unlockLPM5();

  42.     //Initialize the ADC12B Module
  43.     /*
  44.      * Base address of ADC12B Module
  45.      * Use internal ADC12B bit as sample/hold signal to start conversion
  46.      * USE MODOSC 5MHZ Digital Oscillator as clock source
  47.      * Use default clock divider/pre-divider of 1
  48.      * Not use internal channel
  49.      */
  50.     ADC12_B_initParam initParam = {0};
  51.     initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
  52.     initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
  53.     initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
  54.     initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
  55.     initParam.internalChannelMap = ADC12_B_NOINTCH;
  56.     ADC12_B_init(ADC12_B_BASE, &initParam);

  57.     //Enable the ADC12B module
  58.     ADC12_B_enable(ADC12_B_BASE);

  59.     /*
  60.      * Base address of ADC12B Module
  61.      * For memory buffers 0-7 sample/hold for 64 clock cycles
  62.      * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
  63.      * Disable Multiple Sampling
  64.      */
  65.     ADC12_B_setupSamplingTimer(ADC12_B_BASE,
  66.                                ADC12_B_CYCLEHOLD_16_CYCLES,
  67.                                ADC12_B_CYCLEHOLD_4_CYCLES,
  68.                                ADC12_B_MULTIPLESAMPLESDISABLE);

  69.     //Configure Memory Buffer
  70.     /*
  71.      * Base address of the ADC12B Module
  72.      * Configure memory buffer 0
  73.      * Map input A1 to memory buffer 0
  74.      * Vref+ = AVcc
  75.      * Vref- = AVss
  76.      * Memory buffer 0 is not the end of a sequence
  77.      */
  78.     ADC12_B_configureMemoryParam configureMemoryParam = {0};
  79.     configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
  80.     configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A12;
  81.     configureMemoryParam.refVoltageSourceSelect =
  82.         ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
  83.     configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
  84.     configureMemoryParam.windowComparatorSelect =
  85.         ADC12_B_WINDOW_COMPARATOR_DISABLE;
  86.     configureMemoryParam.differentialModeSelect =
  87.         ADC12_B_DIFFERENTIAL_MODE_DISABLE;
  88.     ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

  89.     ADC12_B_clearInterrupt(ADC12_B_BASE,
  90.                            0,
  91.                            ADC12_B_IFG0
  92.                            );

  93.     //Enable memory buffer 0 interrupt
  94.     ADC12_B_enableInterrupt(ADC12_B_BASE,
  95.                             ADC12_B_IE0,
  96.                             0,
  97.                             0);

  98.     while(1)
  99.     {
  100.         __delay_cycles(5000);

  101.         //Enable/Start sampling and conversion
  102.         /*
  103.          * Base address of ADC12B Module
  104.          * Start the conversion into memory buffer 0
  105.          * Use the single-channel, single-conversion mode
  106.          */
  107.         ADC12_B_startConversion(ADC12_B_BASE,
  108.                                 ADC12_B_MEMORY_0,
  109.                                 ADC12_B_SINGLECHANNEL);




  110.         __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_B_ISR will force exit
  111.         __no_operation();                       // For debugger
  112.     }
  113. }

  114. #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
  115. #pragma vector=ADC12_VECTOR
  116. __interrupt
  117. #elif defined(__GNUC__)
  118. __attribute__((interrupt(ADC12_VECTOR)))
  119. #endif
  120. void ADC12_ISR(void)
  121. {
  122.     switch(__even_in_range(ADC12IV,12))
  123.     {
  124.     case  0: break;                         // Vector  0:  No interrupt
  125.     case  2: break;                         // Vector  2:  ADC12BMEMx Overflow
  126.     case  4: break;                         // Vector  4:  Conversion time overflow
  127.     case  6: break;                         // Vector  6:  ADC12BHI
  128.     case  8: break;                         // Vector  8:  ADC12BLO
  129.     case 10: break;                         // Vector 10:  ADC12BIN
  130.     case 12:                                // Vector 12:  ADC12BMEM0 Interrupt

  131.              Value_AD =  ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);

  132.                 ADC_Get_Value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);

  133.                 if (ADV_Get_Aver_Value == 0) {
  134.                         ADV_Get_Aver_Value = ADC_Get_Value;
  135.                 }

  136.                 ADC_Get_Value = (ADV_Get_Aver_Value + ADC_Get_Value) / 2;
  137.                 ADV_Get_Aver_Value = ADC_Get_Value;


  138.         if(ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0) >= 0x7ff)
  139.         {
  140.             //Set P1.0 LED on
  141.             /*

  142.              * Select Port 1
  143.              * Set Pin 0 to output high.
  144.              */
  145.             GPIO_setOutputHighOnPin(
  146.                 GPIO_PORT_P1,
  147.                 GPIO_PIN0
  148.                 );
  149.         }
  150.         else
  151.         {
  152.             //Set P1.0 LED off
  153.             /*

  154.              * Select Port 1
  155.              * Set Pin 0 to output high.
  156.              */
  157.             GPIO_setOutputLowOnPin(
  158.                 GPIO_PORT_P1,
  159.                 GPIO_PIN0
  160.                 );
  161.         }
  162.         __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU
  163.         break;                              // Clear CPUOFF bit from 0(SR)
  164.     case 14: break;                         // Vector 14:  ADC12BMEM1
  165.     case 16: break;                         // Vector 16:  ADC12BMEM2
  166.     case 18: break;                         // Vector 18:  ADC12BMEM3
  167.     case 20: break;                         // Vector 20:  ADC12BMEM4
  168.     case 22: break;                         // Vector 22:  ADC12BMEM5
  169.     case 24: break;                         // Vector 24:  ADC12BMEM6
  170.     case 26: break;                         // Vector 26:  ADC12BMEM7
  171.     case 28: break;                         // Vector 28:  ADC12BMEM8
  172.     case 30: break;                         // Vector 30:  ADC12BMEM9
  173.     case 32: break;                         // Vector 32:  ADC12BMEM10
  174.     case 34: break;                         // Vector 34:  ADC12BMEM11
  175.     case 36: break;                         // Vector 36:  ADC12BMEM12
  176.     case 38: break;                         // Vector 38:  ADC12BMEM13
  177.     case 40: break;                         // Vector 40:  ADC12BMEM14
  178.     case 42: break;                         // Vector 42:  ADC12BMEM15
  179.     case 44: break;                         // Vector 44:  ADC12BMEM16
  180.     case 46: break;                         // Vector 46:  ADC12BMEM17
  181.     case 48: break;                         // Vector 48:  ADC12BMEM18
  182.     case 50: break;                         // Vector 50:  ADC12BMEM19
  183.     case 52: break;                         // Vector 52:  ADC12BMEM20
  184.     case 54: break;                         // Vector 54:  ADC12BMEM21
  185.     case 56: break;                         // Vector 56:  ADC12BMEM22
  186.     case 58: break;                         // Vector 58:  ADC12BMEM23
  187.     case 60: break;                         // Vector 60:  ADC12BMEM24
  188.     case 62: break;                         // Vector 62:  ADC12BMEM25
  189.     case 64: break;                         // Vector 64:  ADC12BMEM26
  190.     case 66: break;                         // Vector 66:  ADC12BMEM27
  191.     case 68: break;                         // Vector 68:  ADC12BMEM28
  192.     case 70: break;                         // Vector 70:  ADC12BMEM29
  193.     case 72: break;                         // Vector 72:  ADC12BMEM30
  194.     case 74: break;                         // Vector 74:  ADC12BMEM31
  195.     case 76: break;                         // Vector 76:  ADC12BRDY
  196.     default: break;
  197.     }
  198. }
复制代码









此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
4条回答
数码小叶
2019-03-24 16:59
 精彩回答 2  元偷偷看……0人看过

一周热门 更多>

相关问题

    相关文章