how to use AD convertion in Atmega 1281
<p>hi guys im trying alot to make ADC as an input pin in my Atmega1281 controller but no success </p>

<p>all i want is to control a micro servo with a potentiometer </p>

<p>here is my code please assist me with this it wont work on my controller </p>

<pre><code>#define F_CPU 16000000 //16MHz
#include &lt;avr/io.h&gt;
#include &lt;util/delay.h&gt;
#include &lt;avr/interrupt.h&gt;
#include &lt;stdlib.h&gt;

//#include &lt;stdio.h&gt;
//#include "uart/uart.h"


#define PWM_PRESCALLER 64
#define ICR_MAX (long double)F_CPU/PWM_PRESCALLER/50
#define OCR_MIN ICR_MAX/20
#define OCR_MAX ICR_MAX/10

//char uart_s[150];
volatile unsigned long adc_val=0;
volatile unsigned long counter=0;
unsigned long curr_adc=0;

ISR (ADC_vect)
{
    adc_val += ADC;
    counter++;
}

int main(void)
{
    //uart_init(uart_calc_ubrr(F_CPU));

    DDRB |= (1&lt;&lt;DDB1);

    ICR1 = ICR_MAX;
    OCR1A = OCR_MIN;
    TCCR1A = (1 &lt;&lt; COM1A1) | (1&lt;&lt;WGM11);
    TCCR1B = (1&lt;&lt;WGM13) | (1&lt;&lt;WGM12) | (1&lt;&lt;CS11) | (1&lt;&lt;CS10);



    ADMUX = (1 &lt;&lt; REFS0);
    ADCSRA = (1 &lt;&lt; ADEN)|(1 &lt;&lt; ADFR)|(1 &lt;&lt; ADIE)|(1&lt;&lt;ADPS2)|(1&lt;&lt;ADPS1)|(1&lt;&lt;ADPS0);

    sei();

    ADCSRA |= (1&lt;&lt;ADSC);



    while(1)
    {
        if(counter &gt;= 500)
        {
            cli();

            unsigned long round_val = round(adc_val / counter);

            adc_val=0;
            counter=0;

            if(abs(round_val - curr_adc) &gt; 1)
            {
                curr_adc = round_val;
            }

            long double ocr = OCR_MIN + ((long double)curr_adc * (OCR_MAX - OCR_MIN)/1024);

            /*sprintf(uart_s, "ADC = %8lu, OCR = %f, rounded = %d\r\n", curr_adc, ocr, (int)round(ocr));
            uart_send_string((unsigned char*) uart_s);*/

            OCR1A = (int)round(ocr);

            //_delay_ms(100);
            sei();
        }
    }
}
</code></pre>