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

How to fix items on particular positions in an array with usort?

php arrays usort

What is the correct algorithm for placing some items in an array to their predefined positions? Assuming integer values would represent the positions, my code is:

Changing the url while loading different language

php function url-rewriting

I have this test website where there are 3 language options.