cancel
Showing results for 
Search instead for 
Did you mean: 

Have: STM32L151C8xxA Get VREFINT trouble (VREFINT voltage drifts depended on external power supply), how to get REAL input voltage?

AlexandrX
Associate III

Code for prepare MCU AD

hadc.Instance = ADC1;
  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
	hadc.Init.LowPowerAutoWait = ADC_AUTOWAIT_DISABLE;
  hadc.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE;
  hadc.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
  hadc.Init.ContinuousConvMode = DISABLE;
  hadc.Init.NbrOfConversion = 1;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.DMAContinuousRequests = DISABLE;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    Error_Handler();
  }

Code for read ADC data:

void ADC_Select_Channel(uint32_t ADCChannel)
{
	ADC_ChannelConfTypeDef conf =
	{
			.Channel = ADCChannel,
			.Rank = 1,
			.SamplingTime = ADC_SAMPLETIME_192CYCLES
	};
	if (HAL_ADC_ConfigChannel(&hadc, &conf) != HAL_OK)
	{
			Error_Handler();
	}
}
 
uint32_t ADC_ReadChannel(uint32_t ADCChannel)
{
	ADC_Select_Channel(ADCChannel);
	HAL_ADC_Start(&hadc);
	HAL_ADC_PollForConversion(&hadc, 100);
	uint32_t RetVal = HAL_ADC_GetValue(&hadc);
	HAL_ADC_Stop(&hadc);
	return RetVal;
}

Code for get data:

// Wait for reference ready
while (__HAL_PWR_GET_FLAG(PWR_FLAG_VREFINTRDY) == RESET) {}
// Get the VREF in mV value
uint32_t VREF = __LL_ADC_CALC_VREFANALOG_VOLTAGE(ADC_ReadChannel(ADC_CHANNEL_VREFINT), LL_ADC_RESOLUTION_12B);
// Out VREF + calc temp
ipf("MCU VREF: %u mV\n\r", VREF);
ipf("MCU Temp: %u C\n\r", __LL_ADC_CALC_TEMPERATURE(VREF, ADC_ReadChannel(ADC_CHANNEL_TEMPSENSOR), LL_ADC_RESOLUTION_12B));

Results:

On lab power supply setted to 2.8V:

MCU VREF: 1792 mV
MCU Temp: 25 C

On 3.6V:

MCU VREF: 2509 mV
MCU Temp: 26 C

1792mV & 2509mV, but datasheet is ~1.22V, how to get REAL input Voltage???

7 REPLIES 7
AlexandrX
Associate III

__LL_ADC_CALC_VREFANALOG_VOLTAGE - what is it? if the internal ref that his calc value must be a stable value ~1220 (1.22V datasheet).

Interesting temp is correct on all input V (2.8 .. 3.6)

How get the 2800 on 2.8V input & 3600 on 3.6V input?

Simon.T
ST Employee

Hello @AlexandrX​,

The calculation of Vrefint or temperature uses variable which is calibrated at VDDA=VREF+=3.0V. So to get the right value with a VDDA=/=3V you need to normalize the value.

It is explained page 6 of the AN3964 :"STM32L1x temperature sensor example".

Best regards,

Simon

I always try this formula. Not works.

I setted 3.000V (same as factory calibration) on lab power supply and VALUE of VREFINT (ADC channel) is 1670, but! - VERFINT_CAL value (stored in MCU) is 1520. My MCU is broken???

P.S.: room temp is 23 C, addr for refcal value:

VREFINT_CAL_ADDR -> VREFINT_CAL_ADDR_CMSIS -> 0x1FF80078 (as uint16_t).

Why temp correct, but VDDA calc is wrong?

> I setted 3.000V (same as factory calibration) on lab power supply and VALUE of VREFINT (ADC channel) is 1670, but! - VERFINT_CAL value (stored in MCU) is 1520.

Are sure you have observed all required timing (mainly TVREFINT Internal reference startup time and the required sampling time TS_vrefint (3) ADC sampling time when reading the internal reference voltage as specified in datasheet?

> Why temp correct

Its calculation may be ratiometric i.e. exclude dependence on VREF+/VDDA and/or the value used at factory calibration. I'm not going to check in the Cube functions/macros you are using.

JW

PS. @Amel NASRI​  , it looks like this is a case where the datasheet shows the wrong value of VDDA/VREF+ used for factory calibration, it appears that it's 3.3V instead of 3.0V - can this please be checked?

AlexandrX
Associate III

> Are sure you have observed all required timing (mainly TVREFINT Internal reference startup time and the required sampling time TS_vrefint (3) ADC sampling time when reading the internal reference voltage as specified in datasheet?

Configured ADC_SAMPLETIME_192CYCLES

> In datasheet says 3.0V (MCU: STM32L151CBT6A, Datasheet for STM32L151x6/8/B-A STM32L152x6/8/B-A, page 59, table 16).

3.3V not works - wrong value.

In case 3.0 setted for example lab 2.8 -> 2.72 calcs, 0.06..0.08...

Take another same MCU and all OK, �?ould I overheat the MCU when soldering? :|

> Take another same MCU and all OK,

Do you mean, the VERFINT_CAL value (stored in MCU) in the another mcu is not around 1520?

JW

> Take another same MCU and all OK,

Do you mean, the VERFINT_CAL value (stored in MCU) in the another mcu is not around 1520?

JW