cancel
Showing results for 
Search instead for 
Did you mean: 

ADC, sampled values shows large changes if sampled continuously

aamirali641989
Associate II
Posted on June 20, 2013 at 13:24

I am using PB0 - ADC2-IN8, as analog input with 10K source impdence. I have configured the pin and sampled continuosly. Values shown shows gradual decrease if delay not added b/w two samples. I am using software control/single conversion method.

below is my code:

main()

{

    GPIO_InitTypeDef        GPIO_InitStruct;

    ADC_CommonInitTypeDef   ADC_CommonInitStruct;    

    ADC_InitTypeDef         ADC_InitStruct;

    

/* Configure ADC2 for keypad adc, PB0 (IN8) */    

    /* Enable clock to ADC2 */     

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);           

    /*Enable  the AHB1 peripheral clock for portB & configure for ADC */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOB, &GPIO_InitStruct);    

    

/* configure global parameters */    

    ADC_CommonInitStruct.ADC_Mode              =  ADC_Mode_Independent;         /* ADC1,ADC2,ADC3 operate independently */

    ADC_CommonInitStruct.ADC_Prescaler         =  ADC_Prescaler_Div2;           /* ADC freq = 30Mhz                     */

    ADC_CommonInitStruct.ADC_DMAAccessMode     =  ADC_DMAAccessMode_Disabled;   /* No DMA access                        */

    ADC_CommonInitStruct.ADC_TwoSamplingDelay  =  ADC_TwoSamplingDelay_5Cycles; /* time b/w two conversion, not used    */

    ADC_CommonInit(&ADC_CommonInitStruct);

/* ADC2 Init */

    ADC_InitStruct.ADC_Resolution           = ADC_Resolution_12b;           /* 12 bit resolution                                  */

    ADC_InitStruct.ADC_ScanConvMode         = DISABLE;                      /* Disable the scan conversion so we do one at a time */

    ADC_InitStruct.ADC_ContinuousConvMode   = DISABLE;                      /* Single conversion                                  */

    ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;/* No external conversion                             */

    ADC_InitStruct.ADC_ExternalTrigConv     = ADC_ExternalTrigConv_T1_CC1;  /* Assign value, but not used                         */

    ADC_InitStruct.ADC_DataAlign            = ADC_DataAlign_Right;          /* data align right                                   */

    ADC_InitStruct.ADC_NbrOfConversion      = 1;                            /* Number of channled to scan = 1                     */ 

    ADC_Init(ADC2, &ADC_InitStruct);                                        /* Init the ADC                                       */

  

    ADC_RegularChannelConfig(ADC2 , 8 , 1, ADC_SampleTime_15Cycles);    

/* Enable ADC2 */

  ADC_Cmd(ADC2, ENABLE);    

    

    cnt = 0;

    while(1)

    {

        ADC_SoftwareStartConv(ADC2);

        while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);

        adc_val = ADC_GetConversionValue(ADC2);

        my_arr_1[cnt++] = adc_val;

        configure_tim3_wait(1000);    /* Delay added here */

               

        if( cnt == 4800 )

        {

            __NOP(); 

            while(1);

        }    

    } 

}

Case 1:

Without using delay, when I sampled 4800 values, I saw gradual decrease from 4095(full scale) to 4000(approx) at last values.

I am writing every 500th values for reference:

my_arr_1[0]       = 4089

my_arr_1[500]   = 4029

my_arr_1[1000] = 4019

my_arr_1[1500] = 4027

my_arr_1[2000] = 4013

my_arr_1[2500] = 4063

my_arr_1[3500] = 3997

my_arr_1[4799] = 4021

case 2:

If delay is added as I marked , then values don't vary like this

 
12 REPLIES 12
frankmeyer9
Associate II
Posted on June 21, 2013 at 11:31

I tried by 28 cycles, but same results were obtained. 

 

That is not much of a difference, better try >100 cycles instead.

From the first post, it seems the variation is not very large, roughly +-40LSB.

Can you confirm that the input voltage source is really stable ?

Does your statement of ''10k impedance'' include the output impedance of the source ?

Could it be an EMI problem ?

aamirali641989
Associate II
Posted on June 22, 2013 at 12:27

I took 4800 samples & min & max values I noted.

case 1:   115 cycles sampling time & no delay added after conversion done

             min value = 4042

            max value = 4095

case 2:   115 cycles sampling time & 1ms delay added after conversion done

             min value = 4065

            max value = 4095

case 3:   15 cycles sampling time & 1ms delay added after conversion done

             min value = 4069

            max value = 4095

case 4:   15 cycles sampling time & no delay added after conversion done

             min value = 3997

            max value = 4093

case 5:   28 cycles sampling time & no delay added after conversion done

             min value = 4010

            max value = 4095

case 6:   28 cycles sampling time & 1ms delay added after conversion done

             min value = 4070

            max value = 4095

frankfrank956
Associate III
Posted on June 22, 2013 at 13:53

Your measured range may be bigger than you think. The results include 4095 so you do not know if there are any values larger than this present.

Try measuring something nearer the middle of the range.