Question
ADC, sampled values shows large changes if sampled continuously
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] = 4089my_arr_1[500] = 4029my_arr_1[1000] = 4019my_arr_1[1500] = 4027my_arr_1[2000] = 4013my_arr_1[2500] = 4063my_arr_1[3500] = 3997my_arr_1[4799] = 4021case 2:If delay is added as I marked , then values don't vary like this