How to use internal ADC of AVR microcontroller using interrupts

Summary of How to use internal ADC of AVR microcontroller using interrupts


This article continues the discussion on AVR interrupts, focusing specifically on internal interrupts generated by peripherals like timers and ADCs. It details how to enable these interrupts using specific bits (ADIE) in registers like ADCSRA and the global interrupt enable bit (I-bit) in SREG. The text explains the advantages of using ADC interrupts over polling for efficient multitasking. Additionally, it describes auto-triggering modes where the ADC automatically starts a new conversion upon completion, configured via the ADATE and ADTS bits.

Parts used in the AVR Internal Interrupts Project:

  • AVR Microcontroller
  • ADC Peripheral
  • Timer Peripheral
  • ADCSRA Register
  • SREG Status Register
  • SFIOR Register

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.
How to use internal ADC of AVR microcontroller using interrupts

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.
How to use internal ADC of AVR microcontroller using interrupts schematic
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.

Quick Solutions to Questions related to AVR Internal Interrupts:

  • What are the two types of interrupts in an AVR microcontroller?
    The two types are external interrupts and internal interrupts.
  • How many internal interrupts do AVR microcontrollers have?
    AVR microcontrollers have seventeen internal interrupts.
  • Which bit activates global interrupts in the SREG register?
    Bit 7, known as the I bit or Global interrupt Enable, must be set to high.
  • What command is used to enable global interrupts?
    The sei command is used to enable global interrupts.
  • Why is the interrupt method preferred over polling for ADC?
    The interrupt method allows the microcontroller to perform other tasks while waiting for conversion.
  • Which bit enables ADC interrupts in the ADCSRA register?
    The ADIE bit in the ADCSRA register enables ADC interrupts.
  • How does auto-triggering mode work for ADC?
    In auto-triggering mode, the ADSC bit is automatically cleared after conversion and set high again for the next conversion.
  • Which bit activates the auto-triggering mode in the ADCSRA register?
    The ADATE bit in the ADCSRA register activates auto-triggering mode.
  • Where are the ADC triggering options selected?
    Various triggering options are selected by configuring the ADTS bits in the SFIOR register.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top