See Quick start guide for the XMEGA AC driver.
This is a driver for configuring, enabling, disabling and use of the on-chip analog comparator (AC).
The analog comparator depends on the following modules:
See Quick start guide for the XMEGA AC driver
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Analog Comparator (AC). | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the Analog Comparator (AC). | |
Data Structures | |
struct | ac_config |
Analog comparator channel configuration struct. More... | |
Typedefs | |
typedef void(* | ac_callback_t )(AC_t *ac, uint8_t channel, enum ac_status_t status) |
Interrupt event callback function type. More... | |
Enumerations | |
enum | ac_int_level_t { AC_INT_LVL_OFF = 0x00, AC_INT_LVL_LO = 0x01, AC_INT_LVL_MED = 0x02, AC_INT_LVL_HI = 0x03 } |
Analog comparator interrupt levels. More... | |
enum | ac_interrupt_mode_t { AC_INT_MODE_BOTH_EDGES = AC_INTMODE_BOTHEDGES_gc, AC_INT_MODE_FALLING_EDGE = AC_INTMODE_FALLING_gc, AC_INT_MODE_RISING_EDGE = AC_INTMODE_RISING_gc, AC_INT_MODE_ABOVE_WINDOW = AC_WINTMODE_ABOVE_gc, AC_INT_MODE_INSIDE_WINDOW = AC_WINTMODE_INSIDE_gc, AC_INT_MODE_BELOW_WINDOW = AC_WINTMODE_BELOW_gc, AC_INT_MODE_OUTSIDE_WINDOW = AC_WINTMODE_OUTSIDE_gc } |
Analog comparator interrupt modes. More... | |
enum | ac_mode_t { AC_MODE_SINGLE, AC_MODE_WINDOW } |
Analog comparator modes. More... | |
enum | ac_status_t { AC_STATUS_ABOVE = AC_WSTATE_ABOVE_gc, AC_STATUS_BELOW = AC_WSTATE_BELOW_gc, AC_STATUS_INSIDE = AC_WSTATE_INSIDE_gc } |
Analog comparator status values. More... | |
Management functions | |
void | ac_write_config (AC_t *ac, uint8_t channel, struct ac_config *config) |
Write analog comparator configuration to hardware. More... | |
void | ac_read_config (AC_t *ac, uint8_t channel, struct ac_config *config) |
Read analog comparator configuration from hardware. More... | |
enum ac_status_t | ac_get_status (AC_t *ac, uint8_t channel) |
Get analog compare channel status. More... | |
void | ac_enable (AC_t *ac, uint8_t channel) |
Enable an analog comparator channel. More... | |
void | ac_disable (AC_t *ac, uint8_t channel) |
Disable an analog comparator channel. More... | |
Interrupt management functions | |
void | ac_set_interrupt_callback (AC_t *ac, ac_callback_t callback) |
Set interrupt callback function. More... | |
static void | ac_set_interrupt_mode (struct ac_config *config, enum ac_interrupt_mode_t mode) |
Set analog comparator channel interrupt mode. More... | |
static void | ac_set_interrupt_level (struct ac_config *config, enum ac_int_level_t level) |
Set analog comparator channel interrupt level. More... | |
Configuration helper functions | |
static void | ac_set_mode (struct ac_config *config, enum ac_mode_t mode) |
Set analog comparator mode. More... | |
static void | ac_set_positive_reference (struct ac_config *config, AC_MUXPOS_t reference) |
Set analog comparator reference for positive line. More... | |
static void | ac_set_negative_reference (struct ac_config *config, AC_MUXNEG_t reference) |
Set analog comparator reference for negative line. More... | |
static void | ac_set_hysteresis (struct ac_config *config, AC_HYSMODE_t hysteresis) |
Set analog comparator hysteresis. More... | |
static void | ac_set_voltage_scaler (struct ac_config *config, uint8_t scale) |
Set analog comparator voltage scale. More... | |
typedef void(* ac_callback_t)(AC_t *ac, uint8_t channel, enum ac_status_t status) |
Interrupt event callback function type.
The interrupt handler can be configured to do a function callback upon a compare interrupt, the callback function must match the ac_callback_t type.
Example:
Then add this callback function to the analog comparator interrupt routine by setting it in the driver.
enum ac_int_level_t |
enum ac_interrupt_mode_t |
Analog comparator interrupt modes.
enum ac_mode_t |
enum ac_status_t |
void ac_disable | ( | AC_t * | ac, |
uint8_t | channel | ||
) |
Disable an analog comparator channel.
ac | Pointer to the analog comparator (AC) base address |
channel | Number of analog comparator (AC) channel to disable |
References ac_aca_opened, ac_acb_opened, cpu_irq_restore(), cpu_irq_save(), SLEEPMGR_IDLE, sleepmgr_unlock_mode(), SYSCLK_AC, sysclk_disable_module(), SYSCLK_PORT_A, and SYSCLK_PORT_B.
Referenced by example_acb_interrupt_callback().
void ac_enable | ( | AC_t * | ac, |
uint8_t | channel | ||
) |
Enable an analog comparator channel.
ac | Pointer to the analog comparator (AC) base address |
channel | Number of analog comparator (AC) channel to enable |
References ac_aca_opened, ac_acb_opened, cpu_irq_restore(), cpu_irq_save(), SLEEPMGR_IDLE, sleepmgr_lock_mode(), SYSCLK_AC, sysclk_enable_module(), SYSCLK_PORT_A, and SYSCLK_PORT_B.
Referenced by example_acb_interrupt_callback(), and main().
enum ac_status_t ac_get_status | ( | AC_t * | ac, |
uint8_t | channel | ||
) |
Get analog compare channel status.
This function will get the current analog compare status from the given channel.
ac | Pointer to the analog comparator (AC) base address |
channel | Number of analog comparator (AC) channel to get status from |
Analog | comparator status given by a ac_status_t value |
References AC_STATUS_ABOVE, and AC_STATUS_BELOW.
Referenced by main().
void ac_read_config | ( | AC_t * | ac, |
uint8_t | channel, | ||
struct ac_config * | config | ||
) |
Read analog comparator configuration from hardware.
This function will read the hardware configuration and put it into the config argument.
ac | Pointer to the analog comparator (AC) base address |
channel | Number of analog comparator (AC) channel |
config | Pointer to a ac_config variable |
References ac_config::acctrl, ac_config::acmuxctrl, cpu_irq_restore(), cpu_irq_save(), ac_config::ctrlb, and ac_config::winctrl.
Referenced by main().
|
inlinestatic |
Set analog comparator hysteresis.
This function helps the caller setting the analog comparator hysteresis for a channel configuration. The hysteresis are defined in the toolchain header files in the form of AC_HYSMODE_*_gc, where * represents NONE, SMALL and LARGE.
config | Pointer to an ac_config variable |
hysteresis | Analog comparator hysteresis config |
References ac_config::acctrl.
Referenced by main().
void ac_set_interrupt_callback | ( | AC_t * | ac, |
ac_callback_t | callback | ||
) |
Set interrupt callback function.
This function allows the caller to set and change the interrupt callback function. Without setting a callback function the interrupt handler in the driver will only clear the interrupt flags.
ac | Pointer to the analog comparator (AC) base address |
callback | Reference to a callback function |
References ac_aca_callback, and ac_acb_callback.
Referenced by main().
|
inlinestatic |
Set analog comparator channel interrupt level.
This function allows the caller to set the analog comparator channel interrupt level. The interrupt levels are defined by the
config | Pointer to an ac_config variable |
level | Analog comparator interrupt level |
References ac_config::acctrl, and ac_config::winctrl.
Referenced by main().
|
inlinestatic |
Set analog comparator channel interrupt mode.
This function allows the caller to set which analog comparator channel interrupt mode should cause an interrupt to trigger.
config | Pointer to an ac_config variable |
mode | Interrupt mode given by an ac_interrupt_mode_t value |
References ac_config::acctrl, and ac_config::winctrl.
Referenced by example_acb_interrupt_callback(), and main().
Set analog comparator mode.
This function helps the caller setting the analog comparator mode for a channel configuration. For AVR XMEGA this can be normal where it will trigger at a defined value, or window mode, where two analog comparators are combined to make two limits and three operating areas. The modes are defined in the ac_mode_t type.
config | Pointer to an ac_config variable |
mode | Analog comparator mode given by a ac_mode_t value |
References AC_MODE_SINGLE, and ac_config::winctrl.
Referenced by main().
|
inlinestatic |
Set analog comparator reference for negative line.
This function helps the caller setting the analog comparator reference source for the negative line, for a given channel configuration. The references are defined in the toolchain header files in the form of AC_MUXNEG_*_gc, where * represents the various available references.
config | Pointer to an ac_config variable |
reference | Analog comparator negative reference |
References ac_config::acmuxctrl.
Referenced by main().
|
inlinestatic |
Set analog comparator reference for positive line.
This function helps the caller setting the analog comparator reference source for the positive line, for a given channel configuration. The references are defined in the toolchain header files in the form of AC_MUXPOS_*_gc, where * represents the various available references.
config | Pointer to an ac_config variable |
reference | Analog comparator positive reference |
References ac_config::acmuxctrl.
Referenced by main().
|
inlinestatic |
Set analog comparator voltage scale.
This function helps the caller setting the analog comparator voltage scaler for a channel configuration, the voltage scale is a numeric value.
config | Pointer to an ac_config variable |
scale | Numeric value of the voltage scale |
References Assert, and ac_config::ctrlb.
Referenced by main().
void ac_write_config | ( | AC_t * | ac, |
uint8_t | channel, | ||
struct ac_config * | config | ||
) |
Write analog comparator configuration to hardware.
This function will write a ac_config struct to the selected analog comparator hardware and channel.
ac | Pointer to the analog comparator (AC) base address |
channel | Number of analog comparator (AC) channel |
config | Pointer to a ac_config variable |
References ac_aca_opened, ac_acb_opened, ac_config::acctrl, ac_config::acmuxctrl, cpu_irq_restore(), cpu_irq_save(), ac_config::ctrlb, SYSCLK_AC, sysclk_disable_module(), sysclk_enable_module(), SYSCLK_PORT_A, SYSCLK_PORT_B, and ac_config::winctrl.
Referenced by example_acb_interrupt_callback(), and main().