Analog To Digital Converter Using AVR


Most of the sensors and transducers are analog such as temperature, humidity, pressure. To interface these sensors to micro-controllers we need to convert the analog output of these sensors to digital.

  • Some microcontroller have inbuilt analog to digital converter.
  • Microcontrollers that don’t have internal ADC, external ADC is used.
  • External ADC : ADC0808,ADC0804.
  • Convert analog pulses to digital i.e., binary 0s and 1s.
  • Types of ADC
    1.Digital Ramp ADC.
    2.Successive Approximation ADC.
    3.Flash ADC.


  • ATmega16 has an inbuilt 10 bit,8-channel ADC system.
  • 131 Powerfull Instructions – Most Single Clock Cycle Execution: 32X8 General Purpose Working Registers.
  • 8 Channels.
  • 10-bit Resolution.
  • Input voltage range of 0 to Vcc.
  • Selectable 2.56V of the internal reference voltage source.
  • AREF pin for External Reference voltage.
  • ADC Conversion Complete interrupt.
  • In Atmega16 ADC channels are multiplexed with PORTA from pin 33 to pin40 (ADC0-ADC7).
  • The voltage on AREF (pin 32) acts as the reference voltage for ADC conversion.
  • External reference voltage source can be used at the AREF pin.
  • A VCC is the supply voltage pin for the A/D Converter, D/A Converter, Current source. It should be externally connected to VCC, even if the ADC, DAC are not used. If the ADC is used, it should be connected to VCC through a low-pass filter.

ADC Registers

  • Registers need to be configured to access ADC peripheral of Atmega16.
  • ADMUX (ADC Multiplexer And Selection Register).
  • ADCSRA (ADC Control and Status Register).
  • ADCH and ADCL (ADC Data Registers).

ADMUX:-ADC Multiplexer And Selection Register

  • REFS[0:1]: determine the source of reference voltage whether it is internal or the external voltage source connected to the AREF pin.
  • ADLAR bit, when set to 1, gives the left adjusted result in data registers ADCH and ADCL.
  • MUX[4:0]: It is used to select between the channels which will provide data to ADC for conversion.

ADCSRA:-ADC Control and Status Register

  • ADEN: ADC Enable, this bit must be set to 1 for turning ADC on.
  • ADSC: ADC Start Conversion,this bit is set to 1 to start ADC conversion, when the conversion is completed this bit is set to 0.
  • ADATE: ADC Auto Trigger Enable, this bit is set to 1 to enable auto triggering of ADC conversion.
  • ADIF: ADC Interrupt Flag, this bit is set to 1 when ADC conversion gets complete.
  • ADIE: ADC Interrupt Enable, this bit is set to 1 to activate the ADC conversion complete interrupt.
  • ADPS[0:2]: ADC Prescaler, these bits are used to set the ADC clock frequency, the configuration of these bits determine the division factor by which the microcontroller clock frequency is divided to get the ADC clock frequency.

ADCH and ADCL: -ADC Data Registers

  • ADC conversion is complete, the data is stored in these two registers (ADCH and ADCL).
  • The data configuration depends on the ADLAR bit value of the ADMUX register.
  • ADLAR=0, data is right adjusted.
  • ADLAR=1, data is left adjusted.
  • Always read ADCL first and then ADCH.

Programing ADC

  • STEP1: Initialize ADC
    1.Set the value in the ADMUX register according to the ADC channel and the reference voltage.
    2.Set the Prescaler bits accordingly in the ADCSRA register.
    3.Set the ADEN bit to enable the ADC.
  • STEP-2: To read the analog value
    1. Put the channel value in ADMUX.
    2. Start the [=]
  • conversion by setting the ADSC bit.
    3. Monitor the ADIF bit for conversion complete.
    4. Clear the conversion bit ADIF by writing it 1.
    5. Digital converted result is now available in ADCH and ADCL registers.