Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AC Example for xplain Documentation

Introduction

This example demonstrates how to use the analog comparator driver.

Main Files

  • ac.c analog comparator driver implementation
  • ac.h analog comparator driver definitions
  • ac_example.c example application

drivers/ac/ac.h driver

The analog comparator driver is described in the Analog Comparator (AC) section.

Device Info

All AVR XMEGA devices with an analog comparator (AC) can be used. This example has been tested with the following setup:

  • Xplain evaluation kit

Description of the example

The example will configure the analog comparator B in window mode and compare the input value from PIN1 (PB1) with the bandgap voltage as lower reference and a scaled VCC as upper reference. The upper value has been chosen by best fit to match the potmeter output from ground to VCC / 2 (1.65 V).

In addition the example configures the analog comparator A two channels in single trigger level mode. On the Xplain evaluation kit these channels are available on the spare ADC/DAC/AC header.

Summary of analog comparator configuration:

  • ACA channel 0: single mode comparing PIN0 (PA0) against bandgap voltage
  • ACA channel 1: single mode comparing PIN2 (PA2) against bandgap voltage
  • ACB: window mode comparing PIN1 (PB1) against bandgap voltage (low) and scaled VCC (high)

This example uses the on-board LEDs to provide user feedback, the output from the LEDs are as follows:

  • LED0: analog comparator B is above window
  • LED1 and LED2: analog comparator B is inside window
  • LED3: analog comparator B is below window
  • LED4: analog comparator A channel 0 is above bandgap voltage
  • LED5: analog comparator A channel 0 is below bandgap voltage
  • LED6: analog comparator A channel 1 is above bandgap voltage
  • LED7: analog comparator A channel 1 is below bandgap voltage

Dependencies

This example depends on the following modules:

Compilation Info

This software was written for the GNU GCC and IAR for AVR. Other compilers may or may not work.

Contact Information

For further information, visit Microchip.