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.
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:
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.
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: AVR-Tutorials.com */ #include<avr/io.h> #include<avr/interrupt.h> ISR(ANA_COMP_vect) { 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(1) { 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.