Xmega Application Note | |||||
This file contains an example application that demonstrates the Analog comparator (AC) driver. It shows how to set up the AC to use interrupt and window mode. The example compares pin 0 to the range indicated by pin 1 (low side) and pin 2 (high side). First, the code waits for the window midpoint to be above the window range, then to get below the range again, then repeating.
The recommended test setup for this application is to connect three 10k resistors in series between GND and AVCC and connect the low-side resistor junction to analog input ACA1 and high-side resistor junction to analog input ACA2. In addition, connect a 10k potentiometer between GND and AVCC and connect the wiper terminal to analog input ACA0.
Copyright (c) 2008, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file AC_example_window_and_interrupt.c.
#include "avr_compiler.h"
#include "ac_driver.h"
Go to the source code of this file.
Defines | |
#define | AC ACA |
Functions | |
ISR (ACA_ACW_vect) | |
int | main (void) |
Variables | |
volatile bool | above |
#define AC ACA |
Definition at line 63 of file AC_example_window_and_interrupt.c.
ISR | ( | ACA_ACW_vect | ) |
Interrupt handler that alternate the window mode settings between "midpoint below window" and "midpoint above window".
Definition at line 113 of file AC_example_window_and_interrupt.c.
References above, AC, and AC_EnableWindowMode().
00114 { 00115 if(above){ 00116 /* Enable window mode with event on "midpoint below window". */ 00117 AC_EnableWindowMode(&AC, AC_WINTMODE_BELOW_gc, AC_WINTLVL_LO_gc); 00118 above = false; 00119 }else{ 00120 /* Enable window mode with event on "midpoint above window". */ 00121 AC_EnableWindowMode(&AC, AC_WINTMODE_ABOVE_gc, AC_WINTLVL_LO_gc); 00122 above = true; 00123 } 00124 }
int main | ( | void | ) |
Definition at line 69 of file AC_example_window_and_interrupt.c.
References above, AC, AC_ConfigMUX(), AC_Enable(), AC_EnableWindowMode(), AC_GetWindowState(), ANALOG_COMPARATOR0, and ANALOG_COMPARATOR1.
00070 { 00071 /* Enable window mode with event on "midpoint above window". */ 00072 AC_EnableWindowMode(&AC, AC_WINTMODE_ABOVE_gc, AC_WINTLVL_LO_gc); 00073 above = true; 00074 00075 /* Set up MUXes to sense pin 1 and 2, with pin 0 as midpoint. */ 00076 AC_ConfigMUX(&AC, ANALOG_COMPARATOR0, AC_MUXPOS_PIN0_gc, AC_MUXNEG_PIN1_gc); 00077 AC_ConfigMUX(&AC, ANALOG_COMPARATOR1, AC_MUXPOS_PIN0_gc, AC_MUXNEG_PIN3_gc); 00078 00079 00080 /* Enable both comparators in low power mode. */ 00081 AC_Enable(&AC, ANALOG_COMPARATOR0, false); 00082 AC_Enable(&AC, ANALOG_COMPARATOR1, false); 00083 00084 00085 /* Enable output on PORTD. */ 00086 PORTD.DIRSET = 0xFF; 00087 PORTD.OUT = 0xFF; 00088 00089 /* Enable PMIC interrupt level low. */ 00090 PMIC.CTRL |= PMIC_LOLVLEX_bm; 00091 00092 /* Enable global interrupts. */ 00093 sei(); 00094 00095 do { 00096 /* Wait for interrupts. To check the if interrupts occur, put a breakpoint in 00097 * the interrupt handler.*/ 00098 if( AC_GetWindowState(&AC) == AC_WSTATE_ABOVE_gc){ 00099 PORTD.OUT = 0xFB; 00100 }else if( AC_GetWindowState(&AC) == AC_WSTATE_INSIDE_gc){ 00101 PORTD.OUT = 0xFD; 00102 }else if( AC_GetWindowState(&AC) == AC_WSTATE_BELOW_gc){ 00103 PORTD.OUT = 0xFE; 00104 } 00105 00106 } while(true); 00107 }
volatile bool above |
Generated on Tue Apr 22 15:13:26 2008 for AVR1302 Using the XMEGA Analog Comparator by ![]() |