an_compare.c

Go to the documentation of this file.
00001 /*
00002 **
00003 ****************************************************************************
00004 **
00005 **
00006 **             Copyright (c) 2007 - Atmel Corporation
00007 **             Proprietaty Information
00008 **
00009 ** Project     : ATMEGA88 + ATA6824 High Temperature H-bridge System
00010 ** Module      : an_compare.c
00011 ** Description : Analog comparator is used to detect over-currents
00012 **                
00013 **
00014 ** Version :     Date:         Author:      Comment:
00015 **    1.0        05.03.2007    F.G.          Creation 
00016 **
00017 ** LICENSE -
00018 **
00019 ** ATMEL - 2007
00020 ** All software programs are provided 'as is' without warranty of any kind:
00021 ** Atmel does not state the suitability of the provided materials for any
00022 ** purpose. Atmel hereby disclaim all warranties and conditions with regard
00023 ** to the provided software, including all implied warranties, fitness for
00024 ** a particular purpose, title and non-infringement.In no event will Atmel
00025 ** be liable for any indirect or consequential damages or any damages
00026 ** whatsoever resulting from the usage of the software program.
00027 ****************************************************************************
00028 **
00029 */
00030 
00031 /*_____ I N C L U D E S ____________________________________________________*/
00032 #include "config.h"
00033 #include "an_compare.h"
00034 #include "Timer0_PWM.h"
00035 
00036 /*_____ M A C R O S ________________________________________________________*/
00037 
00038 /*_____ D E F I N I T I O N S ______________________________________________*/
00039 
00040 /*_____ P R O T O T Y P E S - D E C L A R A T I O N ________________________*/
00041 
00042 /*_____ G L O B A L S ______________________________________________________*/
00043 
00044 over_current_t over_current; 
00045 
00046 
00047 
00053 void AN_compare_init(void)
00054 {
00055   DIDR1 = (1<<AIN1D) | (1<<AIN0D);  // Disable digital buffers on AIN1 and AIN0
00056                                     // to reduce power consumption
00057   ACSR  = (1<<ACIE);                // Enable Analog comparator interrupts
00058                                     // on compare output toggle
00059 }
00060 
00061 
00071 #if defined(__ICCAVR__)             //IAR COMPILER USED
00072 #pragma vector= ANA_COMP_vect       //Analog comparator vector for ATmega88
00073 __interrupt void Over_current_ISR (void)
00074 
00075 #elif defined (__AVR__)             // Avr-gcc compiler used
00076 ISR(ANALOG_COMP_vect)
00077 #endif
00078 {
00079   if (ACSR & (1<<ACO))
00080   {                                 // Input max current reference > current
00081     RE_ENABLE_OCB0();               // Restore PWM output control
00082     over_current.status = false;
00083   }
00084   else                              // Over-current condition
00085   {                                 // Current > max current reference                  
00086     DISABLE_OCB0();                 // Release OCB0, PWM output
00087     over_current.occured = true;
00088     over_current.status = true;
00089   }
00090 }

Generated on Wed Mar 14 10:53:31 2007 for Mega88_&_ATA6824_High_temperature_H-Bridge_system by  doxygen 1.4.7