When using the STM32 ADC for the detection voltage must be back to the calculation of the voltage value, in order to obtain more efficient voltage, there are now the following three ways:
You get the result that the voltage value on your current ad pin is converted to a number relative to 3.3V and 4096.
If you get the ad result is ADC_DR this variable, they have the following relationship:
adc_dr/Current Voltage value = 4096/3300 MV If you want the current voltage value in the reverse process, you can calculate it as follows:
unsigned long Voltage;
Voltage = ADC_DR;
---Assume that the ad results you get are stored in the ADC_DR variable;
Voltage = (Voltage * 3300)/4096; ----you get the correct voltage result, Unit is MV
As a general rule of efficiency, I will numerator myself:
Voltage = (Voltage * 825)/1024; ----you get the correct voltage result, Unit is MV
and further, the efficiency will be higher:
Voltage = (Voltage * 825) >>10; ----you get the correct voltage result, Unit is MV
STM32 AD sample Voltage calculation formula