cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, guys! I have problem with STM32L0 ADC. I measure VrefInt voltage but the behaviour of the ADC is not stable - it reports corect values(4095) alongside with incorrect values (1950)?! Would you please help me.

LMehm
Associate II
  1. Initialization:

static void MX_ADC_Init(void)

{

 ADC_ChannelConfTypeDef sConfig;

  /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

  */

 hadc.Instance = ADC1;

 hadc.Init.OversamplingMode = DISABLE;

 hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;

 hadc.Init.Resolution = ADC_RESOLUTION_12B;

 hadc.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

 hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

 hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

 hadc.Init.ContinuousConvMode = DISABLE;

 hadc.Init.DiscontinuousConvMode = DISABLE;

 hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc.Init.DMAContinuousRequests = DISABLE;

 hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc.Init.LowPowerAutoWait = DISABLE;

 hadc.Init.LowPowerFrequencyMode = DISABLE;

 hadc.Init.LowPowerAutoPowerOff = DISABLE;

 HAL_ADC_Init(&hadc);

 HAL_ADC_Init(&hadc);

/* if (HAL_ADC_Init(&hadc) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }*/

  /**Configure for the selected ADC regular channel to be converted.

  */

 sConfig.Channel = ADC_CHANNEL_17;

 sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

/* if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }*/

 HAL_ADC_ConfigChannel(&hadc, &sConfig);

 __HAL_RCC_ADC1_CLK_ENABLE();

}

2. Measurement:

void MeasureVDD(void)

{

#define VREFINT_CAL_ADDR 0x1FF80078

uint16_t vrefint_cal;

vrefint_cal= *((uint16_t*)VREFINT_CAL_ADDR);

uint32_t adcVal;

float vddVal;

HAL_ADC_Start(&hadc);

HAL_ADC_PollForConversion(&hadc, 50);

adcVal=HAL_ADC_GetValue(&hadc);

HAL_ADC_Stop(&hadc);

vddVal=(3.3*vrefint_cal)/adcVal;

PRINTF("ADC value:%d\r\n",adcVal);

}

2 REPLIES 2
BK??s
Associate

I have the same situation but I am not sure if it is a incorrect value. Actually it is there is no wrong value for this kind of cases. Because it is the internal referance. That means whatever you measure, it is the internal referance value. You can measure the vdd with the formula : 4096(for12 bit ADC) * CALIB_VAL / (Measured adc level). you can get the CALIB_VAL from device datasheet.

AvaTar
Lead

By definition, an ADC measures a voltage in relation to the reference voltage. If one tries to measure Vref, the expected result is 1 (or 4095 for 12 bit).

But with an erraneous ADC configuration (sampling time too short), it is quite possible to achieve results somewhere in between 0 and Vref. I would expect the internal reference to not be of particular low impedance.