atmega164p free running mode

Here's how to setup an Atmega164p (new version of Atmega16) for free running mode:

//::ADC SETUP:://

    // PRESCALER 64
    ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (0 << ADPS0);

    // AUTO TRIGGER ENABLE
    ADCSRA |= (1 << ADATE);

    // AVCC with external capacitor at AREF pin
    ADMUX |= (0 << REFS1) | (1 << REFS0);

    // RIGHT ADJUST
    ADMUX |= (0 << ADLAR);

    // CHANNEL 0
    ADMUX |= (0 << MUX4) | (0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0);

    // FREE RUNNING MODE
    ADCSRB |= (0 << ADTS2) | (0 << ADTS1) | (0 << ADTS0);

    // ENABLE ADC
    ADCSRA |= (1 << ADEN);

    //ADC INTERRUPT ENABLE
    ADCSRA |= (1 << ADIE);

    sei();

    // START A2D
    ADCSRA |= (1 << ADSC);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License