Search code examples
atmegaadc

Is it possible to hard code the AREF instead of using a pin?


Is it possible to hard code the reference value instead of using the pin 21 (AREF) on the ATMEGA168?


Solution

  • Since the majority of ADC principles rely on comparision of voltage, current or charge you always need a physical reference that cannot be bypassed by hardcoding. In this case a reference voltage is needed. On the ATmega 168 you can either use the external reference pin AREF, or the controllers power supply voltage AVcc, or a built-in 1.1 V voltage reference diode 'Vref`.

    You can set the reference source by programming ADMUX (ADC multiplexer selection register) as stated in the ATmega48/88/168 data sheet page 261:

    //using avrgcc:
    //select internal 1.1 V ADC reference
    ADMUX |= 0b11000000;