2017-01-04 10:51 AM
Hi,
My vdd calculates to 3.49V but I measure it to 3.30V with a voltmeter.
The Vrefint calibration value at 0x1FFFF7BA is 1550.
The ADC value I read is 1465, fluctuating +/- 1.
Calculation is 3.3V * VrefintCalValue / AdcValue = 3.49V
I'm guessing it's my adc read value that is off, not the factory calibration value?
MCU is STM32F042G6Ux. ADC code is done in CubeMX.
ADC is clocked with a prescaler of /4 and sampletime is 239.5 cycles. So all signals should have plenty of time to settle between samples.
Code is inside this link ->
Solved! Go to Solution.
2017-11-13 03:32 AM
Hi!
VREFINT_CAL is the result of conversion of 3.0 V by the ADC. So you should use 3.0 instead of 3.3 in you calculations.
I have the following formula in the reference manual for stm32l476:
VDDA = 3.0 V x VREFINT_CAL / VREFINT_DATA
2017-01-04 11:47 AM
Getting somewhere. Found this piece of code inside the HAL:
/**
* @brief Perform an ADC automatic self-calibration * Calibration prerequisite: ADC must be disabled (execute this * function before HAL_ADC_Start() or after HAL_ADC_Stop() ). * @note Calibration factor can be read after calibration, using function * HAL_ADC_GetValue() (value on 7 bits: from DR[6;0]). * @param hadc: ADC handle * @retval HAL status */HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc).. and I used it in the ADC init routine.
Now I'm reading 1526, which is much nearer the calibration value and vdd calculates to 3.35V.
That is only 50mV offset from reality. Can I expect to get any closer than this?
2017-01-15 01:48 PM
Funny thing is that all though vdd readout is high (some 50mV off), other ADC readings that use the corrected vdd reading is close to spot on (1 or 2 mV off).
2017-03-05 06:04 AM
Hi
I am looking at this in interest as I am new to STM32 and am starting to look at the A/D side. I am concerned with the accuracy of the a/d as the chip I am using doesnt have VREF+ input. Hope you dont mind me asking , in your calculation above, is the 3.3v because that is what you are reading on your volt meter, or is? I am thinking of running from a 3.6v battery , so the voltage will slightly drop as time goes by, and want to keep the same accuracy. Can anything be done with the VREFINT and keep the accuracy?
Many Thanks
Scott
2017-03-05 08:24 AM
Expect that the calibration value is computed from a sample and current temperature. Don't expect it to come from long term thermal testing, or over a wide range of voltage or temperature. You might want to do some more thorough testing and profiling in your own test/calibration process, and over temperature.
You could apply your own reference voltage to the part via another ADC pin during test.
The reference is nominally 1.25V, as I recall, check the documentation for your specific part. VREF+ will be bonded to VDDA if it is not brought to it's own pin.
2017-03-05 10:06 AM
Use the chip temperature measurement in the interpolated vdd calculations. I guess that when some STM32 consumes 100mA or more, the junction temperature should be compensated for possibly higher precision. If the vdd measurement need come for precise analog input measurements, then also consider an STM32 with differential input support.
2017-03-05 11:07 AM
Clives expectations are correct, I measured 3.30... something volts manually.
2017-03-19 03:16 AM
Hi
I understand that the value of VREFINT at precisely
3.3V
is stored in memory during manufacture time. I know this is a silly question, but I assume the value read in from the VREFINT to calculate the chip voltage is not like a standard voltage reference in the sense it always stays the same same value? As if it did there would be no way of calculating the vdd. I am planning to run the processor at 2.5v , so I assume the value of VREFINT will change accordingly so the accurate value of the vdd can be calculated?Many thanks from a beginner on th STM32
Scott
2017-03-19 04:12 AM
Hi Scott,
You should read the sub-chapter of Temperature sensor and Internal voltage reference in ADC chapter of Reference Manual for the device you're using. Maybe you understand it better than I do, but this is what you can read from RM0091 for 'STM32F0x1/STM32F0x2/STM32F0x8 advanced ARM ® -based 32-bit MCUs':
The internal voltage reference (V REFINT ) provides a stable (bandgap) voltage output for the
ADC and Comparators. V REFINT is internally connected to the ADC_IN17 input channel. Theprecise voltage of V REFINT is individually measured for each part by ST during productiontest and stored in the system memory area.Calculating the actual V DDA voltage using the internal reference voltageThe V DDA power supply voltage applied to the microcontroller may be subject to variation ornot precisely known. The embedded internal voltage reference (VREFINT) and itscalibration data acquired by the ADC during the manufacturing process at V DDA = 3.3 V canbe used to evaluate the actual V DDA voltage level.The following formula gives the actual V DDA voltage supplying the device:V DDA = 3.3 V x VREFINT_CAL / VREFINT_DATAWhere:ï‚· VREFINT_CAL is the VREFINT calibration valueï‚· VREFINT_DATA is the actual VREFINT output value converted by ADCWhat I think is funny is that nowhere is it mentioned what Vrefint actually is. I know it doesn't matter, as long as you multiply the Vrefint/Vrefint_cal ratio by 3.3. If I had my project running rigth now I could tell you the value.
2017-03-19 04:56 AM
Hi Henrik
Thanks for your reply. I am about to start on the ADC , and also have been looking at
http://letanphuc.net/2016/07/stm32f0-adc/
which explains the VREFINT too. I at first thought VREFINT was a voltage reference like an external voltage reference chip, where there was a constant value. But understand that it must vary depending on the supply voltage, I just couldnt find where it says this. Unless 'bandgap' means this I dont know what this is.Scott