Trying to read VREFINT using STM32F103C8t6 (Blue pill) and getting wrong value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 5: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);
}
- Labels:
-
ADC
-
STM32F1 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 5: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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 5: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 6: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 ... ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 8: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-14 9: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.
