Professional Documents
Culture Documents
AVR ADC Interrupt Feature
AVR ADC Interrupt Feature
This tutorial will look at writing a simple program that utilizes the interrupt feature of the
Analog-to-Digital Converter (ADC) of the ATMega16 AVR microcontroller.
In this example we will use the ADC of the AVR ATMega16 microcontroller to convert
an analog voltage presented on channel ADC0 to its binary value and output that value
to portD of the microcontroller. The input voltage to ADC0 is varied using the variable
resistor. Below is the circuit diagram to achieve this task. The AVR C program follows
the circuit diagram followed by a video.
Below is the AVR C code for the ATMega16 Interrupt feature example discussed
above. This code was written in AVR Studio 5.
Important Note: In order for our example to work the internal oscillator of the
ATMega16 AVR microcontroller must be enabled and set to 1MHz.
/*
* Author: AVR Tutoruals
* Website: www.AVR-Tutorials.com
*
* Written in AVR Studio 5
* Compiler: AVR GNU C Compiler (GCC)
*/
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
DDRD = 0xFF; // Configure PortD as output
DDRA = 0x00; // Configure PortA as input
// PA0 is ADC0 input