Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

How to use internal ADC of AVR microcontroller using interrupts


Developed By: 
Akshay Daga
This article is in continuation to AVR interrupts. There are two types of interrupts external and internal in AVR microcontroller. The aforesaid article covers external interrupts. AVR microcontrollers have seventeen internal interrupts. These internal interrupts are generated by the internal peripherals of Microcontroller like Timer, ADC etc. The internal interrupts are used for efficient operation of the internal peripherals. This article explains the internal interrupts using the example of an ADC interrupt.


Internal ADC interrupts of AVR Microcontroller (Atmega16)


Each internal peripheral system consists of one IE (interrupt Enable) bit which activates the internal interrupts of that peripheral. For example, in-built ADC of AVR consists of ADIE (ADC interrupt Enable) bit in ADCSRA register.
In addition, the I-bit of SREG is also activated to activate interrupts. SREG is a status register of AVR microcontroller which contains information about the result of most recently executed arithmetic instructions.
SREG (Status Register):
Bit 7-I: (Global interrupt Enable):
To activate Global Interrupts this bit must be set to high. If this bit is not enabled, none of the interrupts will work. “sei ()” command is used to enable the Global Interrupt, and “cli()” command is used to disable global interrupt.
For better clarification of internal interrupts, ADC interrupts is explained below:
ADC interrupts:
In the article of AVR ADC, polling method is used to receive converted value. During the polling of a signal, microcontroller cannot perform another task. Hence, it is better to use interrupt method. ADC system consists of ADIE bit in ADCSRA register. ADIE bit is enabled to use ADC interrupts.
ADC in auto-triggering mode:
In A/D conversion ADSC bit remains high till the conversion is not completed. As soon as the, conversion gets completed, ADSC automatically gets cleared by hardware. Before starting the next conversion, ADSC must be set high again. Alternatively, auto triggering can be used to enable the ADSC bit after each conversion. The ADATE (ADC Auto Triggering Enable) bit in ADCSRA register is used to activate auto-triggering mode. There are various triggering options available in AVR ADC, which can be selected by configuring ADTS (ADC Triggering Select) bits in SFIOR register.
SFIOR (Special Function I/O register):
The following table shows the combination of ADTS [2:0] bits to select triggering source:

Objective: A/D conversion using interrupt method and display 10-bit digital output on LCD as integer form.
Programming steps:
To initiate ADC:
1. Set the value in ADMUX register according to the ADC channel and the reference voltage.
2. Set the Prescaler bits accordingly in ADCSRA register.
3. Set the ADEN bit to enable the ADC.
4. Set ADIE bit to enable ADC interrupt.
5. Set ADATE bit to enable auto triggering.
6. Set ADSC bit to start conversion.
7. Configure SFIOR register to select trigger source. 

void adc_init()// ADC configuration
// ADSC=1 ADC Enable
// ADPS[2:0]=111, prescaler=128
// ADIE=1, ADC interrupt Enable
//ADATE=1, ADC Auto Triggering Enable
//ADTS[2:0]= 100 , Timer0 overflow select as trigger source


To read converted value:
1. Start Trigger Source for auto-triggering of ADC.  
2. Enable I-bit of SREG register to enable global Interrupt.
3. Store 10-bit converted data into 16-bit variable.
4. Convert the digital value to its corresponding ASCII value.
5. Display the converted value on LCD.


Circuit Diagram



This Code is only visible to Registered users. Please Login/Register



16 x 2 LCD | 16x2 Character LCD Module


LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments...

ATmega16 AVR Microcontroller
ATmega16 is an 8-bit high performance microcontroller of Atmel’s Mega AVR family with low power consumption. Atmega16 is based on enha...

Free TI Design & Simulation Tools


WEBENCH Design Center

WEBENCH Design Environments are unique and powerful software tools that deliver customized power, lighting, filtering, clocking and sensing designs in seconds. These easy-to-use tools help you generate, optimize and simulate designs that conform to your unique specifications. They allow you to make value-based tradeoffs at a design, system and supply chain level before your design is committed to production.

Design & Simulation Tools

Power Design


Sensors, Filter, Clock and Amplifier Design

Download Tools, Models and Symbols



You are here