Microchip® Advanced Software Framework

ac_example.c File Reference

AVR XMEGA analog comparator example.

Copyright (c) 2010-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"

Functions

static void example_ac_update_single_leds (uint8_t channel, enum ac_status_t status)
 Update LEDs used for feedback from analog comparator channel in single trigger level mode. More...
 
static void example_ac_update_window_leds (enum ac_status_t status)
 Update LEDs used for feedback from analog comparator in window mode. More...
 
static void example_aca_interrupt_callback (AC_t *ac, uint8_t channel, enum ac_status_t status)
 Analog comparator A interrupt callback function. More...
 
static void example_acb_interrupt_callback (AC_t *ac, uint8_t channel, enum ac_status_t status)
 Analog comparator B interrupt callback function. More...
 
int main (void)
 Main function. More...
 
static void mdelay (uint16_t ms)
 delay for ms milliseconds More...
 

Variables

static struct ac_config aca0_config
 Analog comparator A channel 0 configuration. More...
 
static struct ac_config aca1_config
 Analog comparator A channel 1 configuration. More...
 
static struct ac_config acb_config
 Analog comparator B window configuration. More...
 

static void example_ac_update_single_leds ( uint8_t  channel,
enum ac_status_t  status 
)
static

Update LEDs used for feedback from analog comparator channel in single trigger level mode.

This function will set the LEDs appropriately for the channel that caused the interrupt. See the Description of the example section for additional details.

Parameters
channelThe analog comparator channel to update status for
statusAnalog comparator channel status given by a ac_status_t value

References AC_STATUS_ABOVE, gpio_set_pin_high, gpio_set_pin_low, LED4_GPIO, LED5_GPIO, LED6_GPIO, and LED7_GPIO.

Referenced by example_aca_interrupt_callback(), and main().

static void example_ac_update_window_leds ( enum ac_status_t  status)
static

Update LEDs used for feedback from analog comparator in window mode.

This function will set the LEDs appropriately status of the window. See the Description of the example section for additional details.

Parameters
statusAnalog comparator window status given by a ac_status_t value

References AC_STATUS_ABOVE, AC_STATUS_INSIDE, gpio_set_pin_high, gpio_set_pin_low, LED0_GPIO, LED1_GPIO, LED2_GPIO, and LED3_GPIO.

Referenced by example_acb_interrupt_callback(), and main().

static void example_aca_interrupt_callback ( AC_t *  ac,
uint8_t  channel,
enum ac_status_t  status 
)
static

Analog comparator A interrupt callback function.

This function is called when an interrupt has occurred on a channel in analog comparator A.

Parameters
acPointer to the analog comparator (AC) base address which caused the interrupt
channelThe analog comparator channel that caused the interrupt
statusAnalog comparator channel status given by a ac_status_t value

References example_ac_update_single_leds().

Referenced by main().

static void example_acb_interrupt_callback ( AC_t *  ac,
uint8_t  channel,
enum ac_status_t  status 
)
static

Analog comparator B interrupt callback function.

This function is called when an interrupt has occurred on a channel in analog comparator B.

Parameters
acPointer to the analog comparator (AC) base address which caused the interrupt
channelThe analog comparator channel that caused the interrupt
statusAnalog comparator window status given by a ac_status_t value

References ac_disable(), ac_enable(), AC_INT_MODE_INSIDE_WINDOW, AC_INT_MODE_OUTSIDE_WINDOW, ac_set_interrupt_mode(), AC_STATUS_INSIDE, ac_write_config(), acb_config, and example_ac_update_window_leds().

Referenced by main().

static void mdelay ( uint16_t  ms)
static

delay for ms milliseconds

Parameters
msnumber of milliseconds to busy wait

References sysclk_get_cpu_hz().

Referenced by main().

struct ac_config aca0_config
static
Initial value:
= {
.acctrl = ((uint8_t)AC_INTMODE_BOTHEDGES_gc |
(uint8_t)AC_INTLVL_MED_gc | (uint8_t)AC_HSMODE_bm),
.acmuxctrl = ((uint8_t)AC_MUXNEG_BANDGAP_gc |
(uint8_t)AC_MUXPOS_PIN0_gc),
}

Analog comparator A channel 0 configuration.

This struct is intentionally just defined, not declared. The example code will use the helper functions to setup the channel configuration.

struct ac_config aca1_config
static
Initial value:
= {
.acctrl = ((uint8_t)AC_INTMODE_BOTHEDGES_gc |
(uint8_t)AC_INTLVL_MED_gc | (uint8_t)AC_HSMODE_bm),
.acmuxctrl = ((uint8_t)AC_MUXNEG_BANDGAP_gc |
(uint8_t)AC_MUXPOS_PIN2_gc),
}

Analog comparator A channel 1 configuration.

This struct configures the an analog comparator channel with the following settings:

  • Falling edge interrupt mode
  • Medium interrupt level
  • High-speed mode
  • No hysteresis
  • PIN2 as negative input to the multiplexer
  • Bandgap as positive input to the multiplexer
struct ac_config acb_config
static

Analog comparator B window configuration.

This struct is intentionally just defined, not declared. The example code will use the helper functions to setup the analog comparator in window mode.

Referenced by example_acb_interrupt_callback(), and main().