Xmega Application Note | |||||
This file contains an example application that demonstrates the Analoge comparator (AC) driver. It shows how to set up the AC using hysteresis. The example uses pin 0 (low side) and pin 1 (high side). The code waits until the AC output has toggled four times, then it disables the AC.
The recommended test setup for this application is to connect pin 0 to a voltage between GND and VCC and connect a 10k potentiometer between GND and AVCC and connect the wiper terminal to pin 1.
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_polled.c.
#include "ac_driver.h"
Go to the source code of this file.
Defines | |
#define | AC ACA |
Functions | |
int | main (void) |
#define AC ACA |
int main | ( | void | ) |
Definition at line 60 of file AC_example_polled.c.
References AC, AC_ConfigHysteresis(), AC_ConfigMUX(), AC_Disable(), AC_Enable(), AC_WaitForComparator_Blocking(), and ANALOG_COMPARATOR0.
00061 { 00062 /* Enable Analog comparator submodule 0. */ 00063 AC_Enable(&AC, ANALOG_COMPARATOR0, false); 00064 00065 /* By defalut the Analog comparators interupt flag triggers on changes on 00066 * both edges. If another trigger setting (INTMODE) is preferd use the 00067 * AC_ConfigInterrupt function to change the settings. */ 00068 00069 /* Set up MUXes to sense pin 0 and 1. */ 00070 AC_ConfigMUX(&AC, ANALOG_COMPARATOR0, AC_MUXPOS_PIN0_gc, AC_MUXNEG_PIN1_gc); 00071 00072 /* Set up AC with a small hysteresis. */ 00073 AC_ConfigHysteresis(&AC, ANALOG_COMPARATOR0, AC_HYSMODE_SMALL_gc); 00074 00075 /* Sense for 4 changes on comparator output. */ 00076 for(uint8_t i=0; i < 4; i++){ 00077 /* Wait for Comparator to change value. */ 00078 AC_WaitForComparator_Blocking(&AC, ANALOG_COMPARATOR0); 00079 } 00080 00081 /* Disable submodule 0. */ 00082 AC_Disable(&ACA, ANALOG_COMPARATOR0); 00083 00084 do{ 00085 /* Stop here. */ 00086 }while(true); 00087 }
Generated on Tue Apr 22 15:13:26 2008 for AVR1302 Using the XMEGA Analog Comparator by ![]() |