cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ADC Vrefint monitoring.

EAlek.11
Associate II

Hello. A have my custom board with STM32G431CBU microcontroller. Power domain on my board are shown in the picture:

0693W000008wB9HQAU.pngI want to measure the voltage on Vref+ pin. The analog domain settings of CubeMX are:

0693W000008wBAeQAM.png0693W000008wB9DQAU.pngThe code for single ADC acquisition:

HAL_ADC_Start(&hadc1);
osDelay(1000);
ADC_Data[0] = hadc1.Instance->DR;
Vbat = ((float) __HAL_ADC_CALC_VREFANALOG_VOLTAGE(ADC_Data[0], ADC_RESOLUTION_12B)) / 1000;

And it works, but the value of calculated Vbat is more then real value that i have measured by multimeter. The value of measuring error have direct dependency of measuring voltage:

real Vref+_______measured Vref+

2.2______________2.30

3.3______________3.45

I tryed to set VREFBUF mode to "External reference", but this does not change anything. On both ("External reference" and "Disable") options the value of VREFBUF_CSR register is 0x2.

I would be grateful if you can help me figure it out.

1 ACCEPTED SOLUTION

Accepted Solutions

Do you perform ADC calibration as outlined in RM?

Do you observe the time needed after enabling VREFINT, and the minimum sampling time, as given by DS?

JW

View solution in original post

6 REPLIES 6

Do you perform ADC calibration as outlined in RM?

Do you observe the time needed after enabling VREFINT, and the minimum sampling time, as given by DS?

JW

EAlek.11
Associate II

Is it necessary to perform the calibration before each ADC start manualy? It should carried out automatically or by HAL driver after ADC initialization, isnt it?

After start and initialization of all periferial i insert delay 1 s. I think this is enough to set the VREFINT value. I seted the maximum posible sampling time (640.5 cycles), ADC clock prescaler is 2 (as mentioned in the picture above). SYSCLK on input of ADC is 16 MHz.

> It should carried out automatically or by HAL driver after ADC initialization, isnt it?

I don't know, I don't use Cube/HAL.

But it's open source, so you can check yourself, if it performs the calibration in any initialization code, before using ADC. I am not sure it does.

Also, read the errata, especially erratum Wrong ADC result if conversion done late after calibration or previous conversion.

Also, you may want to read AN5346.

JW

Igor Cesko
ST Employee

This is very large error in real VREF+ calculation. We should check where is problem:

Can you please read the VREFINT calibration value (VREFINT_CAL) stored in device at address 0x1FFF 75AA - 0x1FFF 75AB .

This VREFINT_CAL should be the ADC data value while reading VREFINT channel if the VREF+ voltage is VREF+ = 3.0V (+/-10mV). This value is stored into address 0x1FFF 75AA - 0x1FFF 75AB during factory calibration.

Then please check if this stored value corresponds to allowed VREFINT range in datasheet:

VREFINT: min: 1.182V typ: 1.212V max: 1.232V

VREFINT_real = VREFINT_CAL * 3.0V / 4095

VREFINT_real value should be in the allowed VREFINT range: 1.182V ... 1.232V

If VREFINT_real value is within this range then mistake will be somewhere else: firmware computation or some noise during ADC measurement of VREFINT.

Let me know your results for next step of investigation. Thanks.

Igor

EAlek.11
Associate II

I have done the calibration manually and now all is working fine! (function: HAL_ADCEx_Calibration_Start).

Thank's all! I didnt know that manually calibration is needed. On other STM32 microcontrollers all worked without this.

P.S. I founded another interesting bug in HAL API:

Macro __HAL_ADC_CALC_VREFANALOG_VOLTAGE rezults hard fault if you put 0 as first argument. Is it really bug or feature for "error maximization"? =)

@EAlek.1​ ,

Good to know that you resolved your problem. I'll select Jan's first reply as Best Answer (clicking on "Select as Best") in this case.

Regarding the HAL API __HAL_ADC_CALC_VREFANALOG_VOLTAGE: the hardfault occurs because of a division by zero in case ADC conversion data is 0 (when calling __LL_ADC_CALC_VREFANALOG_VOLTAGE).

I'll share your feedback with our development team.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.