How to correctly convert an ADC digital value into Volt? By divison the with (2^n) or with (2^n -1)?
STM32L152 has 12-bit ADC. How to convert the ADC's digital value into Volt, if there is a 'Vref' reference voltage, and Vref- is grounded?
I met two common solution for such ADC conversion:
(1) V = CODE / 2^n * Vref
(2) V = CODE / (2^n -1) * Vref
(CODE means the digital value, read from ADC register, n is the ADC's resolution)
CODE's range is 0...2^n -1, so its maximum value is (2^n -1) (4095 in case of 12-bit ADC).
In (1) case, the maximum code value corresponds to one step less voltage than Vref.
In (2) case, the maximum measureble voltage is just Vref.
For some other ADC's I used before (e.g. ATtiny25), the correct form was always (1).
But I am not sure about STM32L152. The formula on Page 287 of RM0038 Reference manual suggests the (2) form, as FULL_SCALE is 4095. But this formula is for the case where Vdda is the reference.
I also read "VREF+ is the highest voltage, represented by the full scale value". This also suggest (2).
There is a related thread, but the responses are contradictory:
https://community.st.com/s/question/0D50X00009XkeSr/stm32f407-adc-measurement-to-voltage
Its mainly a theoretical example, as the difference between the results of (1) and (2) are very small.
