2023-09-17 05:51 PM
HI.
I would like to use the battery voltage monitoring feature.
I am reading the ADC by connecting a DC source and adjusting the value from 2.6V to 3.6V. We tested 10 boards and they all had different ADC values.
The biggest difference was over 100.
PCLK is set to 64Mhz.
The ADC setting values were as follows.
/* ADC code */
There are two questions I would like to ask.
1. Is the setting method correct?
2. I thought it was wrong and looked for an example of battery voltage monitoring, but couldn't find one. Can you please share?
thanks.
2023-09-17 06:41 PM
> hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_3CYCLES_5;
Increase your sampling time to maximum to improve accuracy on DC signals.
Also, the ADC must be calibrated before being used. The reference manual has more details on this.
2023-09-17 11:47 PM
I had suggest 3 things to increase ADC Precision.
but you need to change sampling time, ADC_SAMPLETIME_3CYCLES_5 - it's too low which it should be over 19.5 cycles.
1. before start running ADC you should be run HAL_ADCEx_Calibration_Start to Calibrate it.
2. you should calculate millivolt per ADC bits from Vref which reference voltage is about 1,212 millivolt because you never know what exactly VDDA so you need to calculate it from where you really know and you can use this constant value to calculate thee VBat voltage.
and the last one
3. you can use over sampling to reduce a ripple from your supply on VDDA or use some digital filter technique to reduce effect from them.
but even you do all of them, you 'll got a stable value but it will difference from measure by multimeter about 30-40 mV so if you want more accurate, you should add linear regression to calibrate it with linear equation which the error can be down to less than 10mV compare to your multimeter.