1
\$\begingroup\$

I am using atmega328p for my project. I have to read my battery voltage and display it in my cloud. For that, i am using ADC. Now I am getting the ADC value for input voltage applied. But i need to convert the ADC to voltage.

When I go to datasheet, I observed the following equation here

So to convert ADC, Vin=(ADC/1024)*Vref.

But When i searched the google I found another equation and it is

Vin=(ADC/1023)*Vref

Now I doubt that which equation is to use?

If we use 1024, ADC value will be 0001 when the input voltage is equal to 1LSB voltage(Vref/1024).

If we use 1023(second equation), ADC value will be 0000 when the input voltage is equal to 1LSB voltage (Vref/1024)

\$\endgroup\$
1
\$\begingroup\$

First let me quote the picture which already has the answer : "0x000 represents analog ground, and 0x3FF represents the selected reference voltage minus one LSB". That would mean to represent the reference voltage Vref, one LSB count more would be needed so the result would be 0x400 or 1024. So a voltage equaling Vref just cannot be represented as a result, it is a special case. For all other voltages that are at least 0.5 step below Vref (between 1022.5 and 1023.5) the result is valid.

Atmel has an ADC application note for AVRs that explains how the successive ADC works, and it is not obvious but helps to understand which one is correct. There are also a lot of threads on AVRFreaks about which one is correct. And armed with that information, 1024 is correct and there is no error in the datasheet.

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, as you rarely need accuracy of 1 count out of 1024 at the Vin=Vref extreme case anyway.

\$\endgroup\$
  • \$\begingroup\$ So taking 1023 will give a false value right? \$\endgroup\$ – mcv Nov 16 '18 at 9:38
  • \$\begingroup\$ Yes. 1023 is wrong, because 1024 is right. But the error is below 0.098%. \$\endgroup\$ – EX-AVRFREAK Nov 19 '18 at 8:43
  • \$\begingroup\$ What will be the ADC value when vref=5v and vin=4.375 for 3bit adc? whether the SAR ADC will produce 110? \$\endgroup\$ – mcv Nov 21 '18 at 7:20
1
\$\begingroup\$

10 bit ADC means, that you can represent input as number from 0-1023, therefore correct answer is to use 1023, not 1024. It seems like there is a mistake in datasheet, since 0x3FF is 1023, not 1024.

\$\endgroup\$
  • 2
    \$\begingroup\$ But they have mentioned that 0x3FF is Vref-1LSB voltage \$\endgroup\$ – mcv Nov 15 '18 at 11:05
1
\$\begingroup\$

when we consider an n bit ADC. It will read the reference voltage as (2^n - 1),

but, when we are talking about steps it is ((2^n - 1) + 1 (and also counting zero value))

example: when you start counting some thing from "zero". if you got a total count of lets say 81 ...but its really not 81, it will be 82 (including 0 as one value)

so in your case you are talking about 10bit ADC so...maximum refernce volatge it can read is as (2^10 - 1) = 1023

but it has maximum steps of 1023 + 1 = 1024

so you have to take 1024..

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.