2022-04-14 05:22 AM
Hey,
I'm trying to read VREFINT value using internal ADC channel for vrefint, I'm converting data from ADC to voltage and getting 1.34-1.38 V. Datasheet says it should be 1.2-1.24 V. Why my reading has such error ? I'm using 238.5 sampling time for 8 MHz ADC clock, here is data reading code :
void ADC_VAL () {
HAL_ADC_PollForConversion(&hadc1,1);
ADC_VAL=HAL_ADC_GetValue(&hadc1);
voltage = (ADC_VAL*3.3/4095);
}
2022-04-14 05:48 AM
a) Your calculations are based on the 3.3V supply voltage. Are you sure that supply voltage is exactly 3.3V ?
b) Blue pill is often equiped with fake/clone STM chip and its internal reference does not have to be in specified limit.
c) ... some mistake in code (sampling time is not what you think etc.)
2022-04-14 05:51 AM
Then you divide by 4095, presumably because you set the ADC to 12bit, right? But why 4095 if it is 12bit, i.e. 2^12=4096?
Furthermore, did you perform a calibration as recommended by RM0008 in section 11.4?
It is recommended to perform a calibration after each power-up.
Regards
/Peter
2022-04-14 06:06 AM
ad: "4095" vs "4096":
STM32F030x reference manual, page 205
VCHANNELx = VDDA / FULL_SCALE * ADC_DATAx
FULL_SCALE = 4095
and now what's right ... ?
2022-04-14 06:13 AM
It should be 4096, however that's well within the noise in this example.
My guess is your VREF+ is not 3.3V or you haven't calibrated it after startup.
2022-04-14 08:17 AM
I'm using ST_LINK to power mcu and it is 3.3V . It might be fake chip but I quite trust shop where i bought this board. And what about mistakes in code? Why sampling time is wrong?
2022-04-14 08:20 AM
I didn't initiated calibration but changing time period in HAL_ADC_PollForConversion function to max delay time seemed to fixed it, now I'm getting 1.2-1.24 V.
2022-04-14 09:57 AM
I dont mean to say that your sampling time is wrong, but just mention that it can be also your software bug. Just take voltmeter and measure "blue pill" VDD (VREF+) to rule out a). To rule out b) take some another board with same chip, like discovery or nucleo board where you can be sure that chip is genuine. Run your program and look for results.