cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 ADC Measuring VREF+

afr_e2
Associate II

Good morning,

I would like to measure the supply voltage on an STM32H573RI. To do this, I measure VREFINT and then want to calculate the supply voltage.

My approach (simplified):

sConfig.Channel      = ADC_CHANNEL_VREFINT;
sConfig.Rank         = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.SingleDiff   = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset       = 0;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);

while (!__HAL_ADC_GET_FLAG(&hadc1, ADC_FLAG_EOC));

return HAL_ADC_GetValue(&hadc1);

 

Using the ADC value of VREFINT, I calculate the supply voltage as follows:

static uint16_t Calc_VREF(uint16_t adc_value)
{
    uint16_t vrefint_cal = (uint16_t) (*(uint16_t *) (0x08FFF810));
    uint16_t vrefint_voltage = 3300;
    return (uint16_t)(vrefint_voltage * vrefint_cal / adc_value);
}

 

My ADC delivers a value of 1.562 digits for VREFINT, while the calibration value is 1.503 digits. According to my calculations, the reference voltage is therefore 3.175 V. However, VDD / VDDA/VREF+ / VBAT are at 3.358 V (VSS / VSSA/VREF- = GND).

This means that all measurements taken by the ADC are subject to error. Is there an explanation for why the measurements are so inaccurate? How can I ensure that I can obtain accurate measurements with the ADC?

Many thanks.

Andreas

1 ACCEPTED SOLUTION

Accepted Solutions

Did you perform calibration during ADC initialization ?

View solution in original post

2 REPLIES 2

Did you perform calibration during ADC initialization ?

Hi Michal,

there was no calibration done. After calibration, the measurements are good. Thank you for you assistance.!

Andreas