This is an extract of the official ATMEGA328p data sheet page 261:
As the documentation say
Vin * 1024
ADC = ----------
Vref
What I don't understand is an analog pin can provide us 10bits. That's mean a value between 0x0 and 0x3ff (1023)
So I don't understand why the documentation say Vin * 1024
and not 1023. Because for me 0v = 0 and 5v = 1023?
The value is obtained by dividing the sampled analog input voltage by the reference voltage and them multiplying by the number of digital codes. The resolution of converter is set by the number of binary bits in the output code. An ADC carries out two processes, sampling and quantization.
The Atmel ATmega328P microcontroller used on the Arduino Uno has an analog-to-digital conversion (ADC) module capable of converting an analog voltage into a 10-bit number from 0 to 1023 or an 8-bit number from 0 to 255. The input to the module can be selected to come from any one of six inputs on the chip.
ADCs follow a sequence when converting analog signals to digital. They first sample the signal, then quantify it to determine the resolution of the signal, and finally set binary values and send it to the system to read the digital signal. Two important aspects of the ADC are its sampling rate and resolution.
The Arduino has a built-in analog-to-digital converter (ADC) that measures the value of analog signals. The ADC converts the analog voltage into a digital value. The function used in order to obtain the value of an analog signal is analogRead(pin).
0 counts as a valid reading. 1..1023 is 1023 steps and plus 0 that makes 1024. 0x000 represents analog ground, and 0x3FF represents the selected reference voltage minus one LSB. In reality, ADCs are not perfect as results can have more than 1 count of error and it really does not matter much if 1023 or 1024 is used. In theory using 1024 is more accurate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With