ADC digital data out is decreased by 1

I've been working in an ADC project on ATmega 32 my ADC is 10-bit resolution, Vref = 2.56V (internally from this information I can conclude that step size = 2.56/1024 = 2.5mV

then, if the input voltage is 2.5 volt, the Digital data output must be 2.5V /2.5mV = 1000 = 0b1111101000

I've made that code and make a simulation in proteus, but when the input voltage was 2.5V, the output was 999 (decimal) = 0b1111100111 instead of 1000 why??!!

Note: the digital data output is right adjusted

that's my code:


int main(void)
    DDRB = 0xFF;
    DDRD = 0xFF;
    DDRA = 0;
    ADCSRA = 0x87;          //ADC enable, clk/128
    ADMUX = 0xC0;           //Internal vref, single ended ADC0
    ADCSRA |=(1<<ADSC);     //start conversion
    while(ADCSRA & (1<<ADIF) == 0);
    return 0;

and this is the output of the proteus simulation


Your math is a little off. At 0V, the ADC output is 0, hence there are only 1023 steps to reach 2.56V.

2.5V / (2.56V / 1023) = 999.02344

Need Your Help

Angular array won't show nested array

javascript arrays angularjs

I am trying to show a nested array in AngularJS. However, I can't get it to work.

Determine attributes of an Schannel connection -> returns unknown value

windows network-programming schannel

After successfully Creating a Secure Connection Using Schannel, I am obtaining its connection attributes using QueryContextAttributes(), passing SECPKG_ATTR_CONNECTION_INFO.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.