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:

include

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

and this is the output of the proteus simulation

Answers


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

Compact Framework - OpenNetCf.Net FTP Samples?

c# compact-framework ftp windows-mobile-5.0 opennetcf

I am trying to get the OpenNetCF.Net FTP Components working with my PDA application. I am struggling to get it doing any more than connecting to the server and wondered if anyone knew of any sample...

Dynamically generated Linkbutton does not fire Onclick event VB.Net

asp.net vb.net webforms linkbutton

I have followed some of the instructions to create a new LinkButton at runtime with an event trigger and add an event handler for the LinkButton generated. I have no idea why the new LinkButton doe...