If you have a 12 bit adc, as the one in STM32F437, which of the following formulas do you use to calculate the analog value?
V = ADC_sample / 4095 * 3.3
or
V = ADC_sample / 4096 * 3.3
My question is similar to this one, however, I find the answers somewhat conflicting:
https://stackoverflow.com/q/892723/7689257
One answer linked to "The Data Conversion Handbook" and said that it should be the latter equation.
https://stackoverflow.com/a/7895054/7689257
The consensus in the answers dictate that you should refer to the datasheet of the adc, which is where I fail. I have tried to find the answers in the datasheet and reference manual:
https://www.st.com/resource/en/datasheet/DM00077036.pdf
I understand that the difference has no practical difference and perhaps not even measurable, but I want to understand the theory. Not only for the stm32f4 but with other adc's as well.
Update: Thank you for all answers, I am still not quite sure what to make of this. The comment from Scott Seidman on Ron Beyers anwser says that:
Many ADC's can only go up to Vref-1LSB. If Vref is 3.3, the ADC has no code for 3.3V -- it is out of range."
How can you tell if the ADC goes to Vref or Vref-1LSB?
A post by Adrian S. Nastase, states that an ADC will never go to Vref:
https://masteringelectronicsdesign.com/an-adc-and-dac-least-significant-bit-lsb/
Update 2 After searching some more I found an application note for STM32 microcontroller ADCs (AN2834):
Under section 2.2.1 it is explained about reference voltage noise, and the following equation is used to calculate the digital value if the input is 1 volt.
(1/3.3) * 4095 = 0x4D9
And with the same formula instead have a 3.3v input would give:
(3.3/3.3) * 4095 = (1) * 4095 = 4095
And the answer to this question is therefore(?):
V = ADC_sample / 4095 * 3.3
Because this is how the ADC works on STM32 microcontrollers, which is/might be different on other vendors.