AVR Tutorials
The Best AVR Microcontroller Tutorials on the Web

AVR Analog Comparator Interrupt Feature

Hardware/Software Example Utilizing the AVR Analog Comparator Interrupt Feature

This tutorial will look at writing a simple program that utilizes the interrupt feature provided Analog Comparator of the ATMega8515 AVR microcontroller. Before you start this tutorial it is recommended that you go through the analog comparator introductory tutorial, paying special attention to the ACSR register referred to in that tutorial.

In this example we will use the interrupt feature of the Analog Comparator provided with the Atmel AVR ATMega8515 microntroller in the implementation of the control unit for an Semi-Automated filling Machine.

Semi-Automated Filling Machine

System Hardware Description

The figure below gives a simple schematic diagram for the embedded control system of a semi-automated filling machine. The filling machine is used to fill bags with commodity such as rice, flour, sugar, etc.

The embedded control system monitors three (3) inputs on pins 3, 4 and 35 and performs one (1) action outputted on pin 39 of the ATMega8515 microcontroller. The system operates as follows:

  1. When a bag is placed on an electronic weight scale the system detects the bag through the bag sensor, the system then turns on the nozzle to fill the bag with the commodity to a weight specified by the input on pin 4 of the microcontroller.
  2. When the bag is filled to the specific weight the system then turns off the nozzle.
  3. Someone then removes the filled bag and replaces it with an empty bag.
  4. The process is then repeated to fill the new bag.

Important Note: Notice that with this example we are using an external clock. Also in this example we are making use of the interrupt feature provided with the ATMega8515 microcontroller.

The Software Description

Below are two(2) codes, written for the ATMega8515 microcontroller, that accomplish this task. Software I is written in Assembly language and Software II is written in C language.

Software I - The Assembly Control Program for the ATMega8515

; coming soon

Software II - The C Control Program for ATMega8515

*  Written in AVR Studio 5
*  Compiler: AVR GNU C Compiler (GCC)
*  Author: AVR Tutorials
*  Website: www.AVR-Tutorials.com
	PORTA &= 0xFE;		// Turn Nozzle OFF 
	while(PINA & 0x10); 	// Wait for filled bag to be removed  
int main()
	DDRD |= 0x01;		// Set PD0 as output
	PORTA &= 0xFE;		// Turn Nozzle OFF
	ACSR = 0x0B; 		// Configured the Analog Comparator 
				// Enable ACIE and set interrupt to 
				// trigger whenever AC0 go high. That 
				// is both ACIS1 and ACIS0 are set to 1.
	sei();			// Enable Global Interrupt
		while(!(PINA & 0x10)) 	// Keep Nozzle OFF until bag  
			PORTA &= 0xFE;	// is placed under Nozzle
		PORTA |= 0x01;	// Turn ON Nozzle to fill the bag
	return 0;

AVR Tutorials hope this tutorial on the AVR Analog Comparator Interrupt feature was benificial to you and looks forward to your next visit.