Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM4L Analog Comparator Interface Controller (ACIFC) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Analog Comparator Interface Controller functionality.

The Analog Comparator Interface controls eight Analog Comparators (AC) with identical behavior. Each Analog Comparator compares two voltages, yielding an output that depends on the result of the comparison.

Devices from the following series can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The Analog Comparator Interface (ACIFC) controls a number of Analog Comparators (AC) with identical behavior. Each Analog Comparator compares two voltages and gives a compare output depending on the results of this comparison.

The ACIFC module can be configured in normal mode, in which each comparator is used independently, or in window mode, which uses defined comparator pairs. The comparators do not all have to be in the same mode; some comparators may be in normal mode, while others are in window mode. There are, however, restrictions on which ACs can be grouped together in window mode.

Special Considerations

I/O Lines

The ACIFC pins are multiplexed with other peripherals. The user application must therefore configure the GPIO Controller, to give the ACIFC module control of the associated pins.

Power Management

The ACIFC stops functioning when the system enters a sleep mode that disables its clock. However, the ACIFC module can resume its operation if the system enters the SleepWalking mode and the ACIFC clock is started by the Peripheral Event System. During this time, if the ACIFC module generates an interrupt, the system will wake-up from sleep mode and normal system operation resumes.

Clocks

The clock for ACIFC (CLK_ACIFC) is generated by the Power Manager (PM). It can be manually disabled, through the Power Manager, or may be automatically disabled when the system enters a sleep mode that disables the clocks to the peripheral bus modules.

Interrupts

The ACIFC interrupt request line is connected to the Nested Vectored Interrupt Controller (NVIC). Using the ACIFC interrupt requires that the NVIC be configured beforehand.

Peripheral Events

The ACIFC peripheral events are connected via the Peripheral Event System.

Debug Operation

When an external debugger forces the CPU into debug mode, the ACIFC module continues normal operation. If the ACIFC module is configured in a way that requires it to be periodically serviced by the CPU through interrupts (or similar), debugging may result in improper operation or data loss.

Extra Information

For extra information, see Extra Information for Analog Comparator Interface Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for Analog Comparator Interface.

API Overview

Data Structures

struct  ac_ch_config
 ACIFC channel configuration structure. More...
 
struct  ac_config
 ACIFC module configuration structure. More...
 
struct  ac_dev_inst
 ACIFC driver structure. More...
 
struct  ac_win_config
 ACIFC window configuration structure. More...
 

Typedefs

typedef void(* ac_callback_t )(void)
 ACIFC interrupt callback type. More...
 
typedef enum ac_interrupt_source ac_interrupt_source_t
 ACIFC interrupt configuration type. More...
 

Enumerations

enum  ac_ch_interrupt_setting {
  AC_CH_IS_VINP_GT_VINN = 0,
  AC_CH_IS_VINP_LT_VINN,
  AC_CH_IS_OUTPUT_TGL,
  AC_CH_IS_COMP_DONE
}
 ACIFC channel interrupt setting. More...
 
enum  ac_comparator_mode {
  AC_COMPARATOR_OFF = 0,
  AC_COMPARATOR_CONTINUOUS,
  AC_COMPARATOR_USER_TRIGGERED,
  AC_COMPARATOR_EVENT_TRIGGERED
}
 ACIFC comparator mode. More...
 
enum  ac_hysteresis_voltage {
  AC_HYSTERESIS_0_MV = 0,
  AC_HYSTERESIS_25_MV,
  AC_HYSTERESIS_50_MV,
  AC_HYSTERESIS_75_MV
}
 ACIFC hysteresis voltage. More...
 
enum  ac_interrupt_source {
  AC_INTERRUPT_CONVERSION_COMPLETED_0 = 0,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_0,
  AC_INTERRUPT_CONVERSION_COMPLETED_1,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_1,
  AC_INTERRUPT_CONVERSION_COMPLETED_2,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_2,
  AC_INTERRUPT_CONVERSION_COMPLETED_3,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_3,
  AC_INTERRUPT_CONVERSION_COMPLETED_4,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_4,
  AC_INTERRUPT_CONVERSION_COMPLETED_5,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_5,
  AC_INTERRUPT_CONVERSION_COMPLETED_6,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_6,
  AC_INTERRUPT_CONVERSION_COMPLETED_7,
  AC_INTERRUPT_STARTUP_TIME_ELAPSED_7,
  AC_INTERRUPT_WINDOW_0,
  AC_INTERRUPT_WINDOW_1,
  AC_INTERRUPT_WINDOW_2,
  AC_INTERRUPT_WINDOW_3
}
 ACIFC interrupt configuration type. More...
 
enum  ac_negative_input { AC_NEGTIVE_INPUT_EXTERNAL = 0 }
 ACIFC negative input. More...
 
enum  ac_win_event_source {
  AC_WIN_EVENT_ACWOUT_RISING_EDGE = 0,
  AC_WIN_EVENT_ACWOUT_FALLING_EDGE,
  AC_WIN_EVENT_ACWOUT_ON_ANY_EDGE,
  AC_WIN_EVENT_INSIDE_WINDOW,
  AC_WIN_EVENT_OUTSIDE_WINDOW,
  AC_WIN_EVENT_MEASURE_DONE
}
 ACIFC window event output configuration. More...
 
enum  ac_win_interrupt_setting {
  AC_WIN_IS_VINP_INSIDE_WINDOW = 0,
  AC_WIN_IS_VINP_OUTSIDE_WINDOW,
  AC_WIN_IS_WINDOW_OUTPUT_TGL,
  AC_WIN_IS_WINDOW_COMP_DONE,
  AC_WIN_IS_VINP_ENTER_WINDOW,
  AC_WIN_IS_VINP_LEAVE_WINDOW
}
 ACIFC window interrupt settings. More...
 

Functions

static void ac_ch_get_config_defaults (struct ac_ch_config *const cfg)
 Initializes an ACIFC channel configuration structure to default values. More...
 
void ac_ch_set_config (struct ac_dev_inst *const dev_inst, uint32_t channel, struct ac_ch_config *cfg)
 Configure the specified ACIFC channel. More...
 
static void ac_clear_interrupt_status (struct ac_dev_inst *const dev_inst, uint32_t status)
 Write to the ACIFC interrupt status. More...
 
void ac_disable (struct ac_dev_inst *const dev_inst)
 Disable the ACIFC Module. More...
 
void ac_disable_interrupt (struct ac_dev_inst *const dev_inst, ac_interrupt_source_t source)
 Disable the specified ACIFC interrupt source. More...
 
void ac_enable (struct ac_dev_inst *const dev_inst)
 Enable the ACIFC module. More...
 
void ac_enable_interrupt (struct ac_dev_inst *const dev_inst, ac_interrupt_source_t source)
 Enable the specified ACIFC interrupt source. More...
 
static void ac_get_config_defaults (struct ac_config *const cfg)
 Initialize an ACIFC configuration structure to default values. More...
 
static uint32_t ac_get_interrupt_mask (struct ac_dev_inst *const dev_inst)
 Get the ACIFC interrupt mask. More...
 
static uint32_t ac_get_interrupt_status (struct ac_dev_inst *const dev_inst)
 Get the ACIFC interrupt status. More...
 
static uint32_t ac_get_status (struct ac_dev_inst *const dev_inst)
 Get the ACIFC status. More...
 
enum status_code ac_init (struct ac_dev_inst *const dev_inst, Acifc *const ac, struct ac_config *const cfg)
 Initialize the ACIFC module. More...
 
static bool ac_is_comparison_done (struct ac_dev_inst *const dev_inst)
 Check if the ACIFC comparison is done. More...
 
void ac_set_callback (struct ac_dev_inst *const dev_inst, ac_interrupt_source_t source, ac_callback_t callback, uint8_t irq_level)
 Set the ACIFC interrupt callback. More...
 
static void ac_user_trigger_single_comparison (struct ac_dev_inst *const dev_inst)
 Start a single ACIFC comparison. More...
 
static void ac_win_get_config_defaults (struct ac_win_config *const cfg)
 Initializes an ACIFC window configuration structure to default values. More...
 
void ac_win_set_config (struct ac_dev_inst *const dev_inst, uint32_t window, struct ac_win_config *cfg)
 Configure the specified ACIFC window. More...
 

typedef void(* ac_callback_t)(void)

ACIFC interrupt callback type.

ACIFC interrupt configuration type.

ACIFC channel interrupt setting.

Enumerator
AC_CH_IS_VINP_GT_VINN 

Interrupt when VINP > VINN

AC_CH_IS_VINP_LT_VINN 

Interrupt when VINP < VINN

AC_CH_IS_OUTPUT_TGL 

Interrupt on toggle of ACOUT.

AC_CH_IS_COMP_DONE 

Interrupt when comparison of VINP and VINN is done.

ACIFC comparator mode.

Enumerator
AC_COMPARATOR_OFF 

Off.

AC_COMPARATOR_CONTINUOUS 

Continuous measurement mode.

AC_COMPARATOR_USER_TRIGGERED 

User triggered single measurement mode.

AC_COMPARATOR_EVENT_TRIGGERED 

Peripheral event triggered single measurement mode.

ACIFC hysteresis voltage.

Enumerator
AC_HYSTERESIS_0_MV 

0mV of hysteresis

AC_HYSTERESIS_25_MV 

25mV of hysteresis

AC_HYSTERESIS_50_MV 

50mV of hysteresis

AC_HYSTERESIS_75_MV 

75mV of hysteresis

ACIFC interrupt configuration type.

Enumerator
AC_INTERRUPT_CONVERSION_COMPLETED_0 

Conversion completed on channel 0.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_0 

Start-up time elapsed on channel 0.

AC_INTERRUPT_CONVERSION_COMPLETED_1 

Conversion completed on channel 1.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_1 

Start-up time elapsed on channel 1.

AC_INTERRUPT_CONVERSION_COMPLETED_2 

Conversion completed on channel 2.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_2 

Start-up time elapsed on channel 2.

AC_INTERRUPT_CONVERSION_COMPLETED_3 

Conversion completed on channel 3.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_3 

Start-up time elapsed on channel 3.

AC_INTERRUPT_CONVERSION_COMPLETED_4 

Conversion completed on channel 4.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_4 

Start-up time elapsed on channel 4.

AC_INTERRUPT_CONVERSION_COMPLETED_5 

Conversion completed on channel 5.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_5 

Start-up time elapsed on channel 5.

AC_INTERRUPT_CONVERSION_COMPLETED_6 

Conversion completed on channel 6.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_6 

Start-up time elapsed on channel 6.

AC_INTERRUPT_CONVERSION_COMPLETED_7 

Conversion completed on channel 7.

AC_INTERRUPT_STARTUP_TIME_ELAPSED_7 

Start-up time elapsed on channel 7.

AC_INTERRUPT_WINDOW_0 

Window 0 interrupt.

AC_INTERRUPT_WINDOW_1 

Window 1 interrupt.

AC_INTERRUPT_WINDOW_2 

Window 2 interrupt.

AC_INTERRUPT_WINDOW_3 

Window 3 interrupt.

ACIFC negative input.

Enumerator
AC_NEGTIVE_INPUT_EXTERNAL 

ACANx (ACBNx) pin selected.

ACIFC window event output configuration.

Enumerator
AC_WIN_EVENT_ACWOUT_RISING_EDGE 

ACWOUT rising edge.

AC_WIN_EVENT_ACWOUT_FALLING_EDGE 

ACWOUT falling edge.

AC_WIN_EVENT_ACWOUT_ON_ANY_EDGE 

ACWOUT rising or falling edge.

AC_WIN_EVENT_INSIDE_WINDOW 

Inside window.

AC_WIN_EVENT_OUTSIDE_WINDOW 

Outside window.

AC_WIN_EVENT_MEASURE_DONE 

Measurement done.

ACIFC window interrupt settings.

Enumerator
AC_WIN_IS_VINP_INSIDE_WINDOW 

Window interrupt as soon as the common input voltage is inside the window.

AC_WIN_IS_VINP_OUTSIDE_WINDOW 

Window interrupt as soon as the common input voltage is outside the window.

AC_WIN_IS_WINDOW_OUTPUT_TGL 

Window interrupt on toggle of ACWOUT.

AC_WIN_IS_WINDOW_COMP_DONE 

Window interrupt when evaluation of common input voltage is done.

AC_WIN_IS_VINP_ENTER_WINDOW 

Window interrupt when the common input voltage enters the window (e.g.

the rising-edge of ACWOUT)

AC_WIN_IS_VINP_LEAVE_WINDOW 

Window interrupt when the common input voltage leaves the window (e.g.

the falling-edge of ACWOUT)

static void ac_ch_get_config_defaults ( struct ac_ch_config *const  cfg)
inlinestatic

Initializes an ACIFC channel configuration structure to default values.

Note
This function should be called to prepare all new instances of ACIFC channel configuration structures before they are further modified by the user application.

The default configuration is as follows:

  • Hysteresis voltage = 0mV
  • ACIFC is disabled between measurements
  • Fast mode is disabled
  • No output peripheral event when ACOUT is zero or one
  • Negative input from the external pin
  • User triggered single measurement mode
  • Interrupt enabled when the comparison is done
Parameters
[out]cfgACIFC channel configuration structure pointer

References AC_CH_IS_COMP_DONE, AC_COMPARATOR_USER_TRIGGERED, AC_HYSTERESIS_0_MV, AC_NEGTIVE_INPUT_EXTERNAL, ac_ch_config::always_on, Assert, ac_ch_config::comparator_mode, ac_ch_config::event_negative, ac_ch_config::event_positive, ac_ch_config::fast_mode, ac_ch_config::hysteresis_voltage, ac_ch_config::interrupt_setting, and ac_ch_config::negative_input.

Referenced by run_ac_test().

void ac_ch_set_config ( struct ac_dev_inst *const  dev_inst,
uint32_t  channel,
struct ac_ch_config cfg 
)

Configure the specified ACIFC channel.

Parameters
[in]dev_instDriver structure pointer
[in]channelACIFC channel number (range 0 to 7 inclusive)
[in]cfgACIFC channel configuration structure pointer

References ac_ch_config::always_on, Assert, ac_ch_config::comparator_mode, ac_ch_config::event_negative, ac_ch_config::event_positive, ac_ch_config::fast_mode, ac_dev_inst::hw_dev, ac_ch_config::hysteresis_voltage, ac_ch_config::interrupt_setting, and ac_ch_config::negative_input.

Referenced by run_ac_test().

static void ac_clear_interrupt_status ( struct ac_dev_inst *const  dev_inst,
uint32_t  status 
)
inlinestatic

Write to the ACIFC interrupt status.

Parameters
[in]dev_instDriver structure pointer
[in]statusInterrupt status to be clear

References ac_dev_inst::hw_dev.

Referenced by set_int_flag().

void ac_disable ( struct ac_dev_inst *const  dev_inst)

Disable the ACIFC Module.

Parameters
[in]dev_instDriver structure pointer

References ac_dev_inst::hw_dev, SLEEPMGR_BACKUP, and sleepmgr_unlock_mode().

void ac_enable ( struct ac_dev_inst *const  dev_inst)

Enable the ACIFC module.

Parameters
[in]dev_instDriver structure pointer

References ac_dev_inst::hw_dev, SLEEPMGR_BACKUP, and sleepmgr_lock_mode().

Referenced by run_ac_test().

static void ac_get_config_defaults ( struct ac_config *const  cfg)
inlinestatic

Initialize an ACIFC configuration structure to default values.

Note
This function should be called to prepare all new instances of ACIFC configuration structures before they are further modified by the user application.

The default configuration is as follows:

  • Peripheral event trigger is disabled
Parameters
[out]cfgACIFC configuration structure pointer

References Assert, and ac_config::event_trigger.

Referenced by run_ac_test().

static uint32_t ac_get_interrupt_mask ( struct ac_dev_inst *const  dev_inst)
inlinestatic

Get the ACIFC interrupt mask.

Parameters
[in]dev_instDriver structure pointer
Returns
The ACIFC interrupt mask.

References ac_dev_inst::hw_dev.

Referenced by ac_interrupt_handler().

static uint32_t ac_get_interrupt_status ( struct ac_dev_inst *const  dev_inst)
inlinestatic

Get the ACIFC interrupt status.

Parameters
[in]dev_instDriver structure pointer
Returns
The ACIFC interrupt status.

References ac_dev_inst::hw_dev.

Referenced by ac_interrupt_handler().

static uint32_t ac_get_status ( struct ac_dev_inst *const  dev_inst)
inlinestatic

Get the ACIFC status.

Parameters
[in]dev_instDriver structure pointer
Returns
The ACIFC status.

References ac_dev_inst::hw_dev.

enum status_code ac_init ( struct ac_dev_inst *const  dev_inst,
Acifc *const  ac,
struct ac_config *const  cfg 
)

Initialize the ACIFC module.

Note
Enables the ACIFC module's source clock.
Parameters
[out]dev_instDriver structure pointer
[in]acModule hardware register base address pointer
[in]cfgModule configuration structure pointer
Returns
Status of initialization.
Return values
STATUS_OKModule initiated correctly
STATUS_ERR_DENIEDModule has already been enabled
STATUS_ERR_BUSYModule is busy performing a comparison

References _ac_set_config(), Assert, ac_dev_inst::hw_dev, STATUS_ERR_BUSY, STATUS_ERR_DENIED, STATUS_OK, and sysclk_enable_peripheral_clock().

Referenced by run_ac_test().

static bool ac_is_comparison_done ( struct ac_dev_inst *const  dev_inst)
inlinestatic

Check if the ACIFC comparison is done.

Parameters
[in]dev_instDriver structure pointer
Returns
The ACIFC comparison result.
Return values
falseACIFC comparison has not completed
trueACIFC comparison has completed

References ac_dev_inst::hw_dev.

void ac_set_callback ( struct ac_dev_inst *const  dev_inst,
ac_interrupt_source_t  source,
ac_callback_t  callback,
uint8_t  irq_level 
)

Set the ACIFC interrupt callback.

Parameters
[in]dev_instDriver structure pointer
[in]sourceACIFC interrupt source
[in]callbackInterrupt callback function pointer
[in]irq_levelInterrupt priority level

References ac_enable_interrupt(), and irq_register_handler.

Referenced by run_ac_test().

static void ac_user_trigger_single_comparison ( struct ac_dev_inst *const  dev_inst)
inlinestatic

Start a single ACIFC comparison.

Parameters
[in]dev_instDriver structure pointer

References ac_dev_inst::hw_dev.

Referenced by run_ac_test().

static void ac_win_get_config_defaults ( struct ac_win_config *const  cfg)
inlinestatic

Initializes an ACIFC window configuration structure to default values.

Note
This function should be called to prepare all new instances of ACIFC window configuration structures before they are further modified by the user application.

The default configuration is as follows:

  • Window mode is disabled
  • Peripheral event from ACWOUT is disabled
  • Generate the window peripheral event when the comparison is done
  • Window interrupt enabled when the evaluation of the common input voltage is done
Parameters
[out]cfgACIFC window configuration structure pointer

References AC_WIN_EVENT_MEASURE_DONE, AC_WIN_IS_WINDOW_COMP_DONE, Assert, ac_win_config::enable, ac_win_config::event_enable, ac_win_config::event_source, and ac_win_config::interrupt_setting.

void ac_win_set_config ( struct ac_dev_inst *const  dev_inst,
uint32_t  window,
struct ac_win_config cfg 
)

Configure the specified ACIFC window.

Parameters
[in]dev_instDriver structure pointer
[in]windowACIFC window number (range 0 to 3 inclusive)
[in]cfgACIFC window configuration structure

References Assert, ac_win_config::enable, ac_win_config::event_enable, ac_win_config::event_source, ac_dev_inst::hw_dev, and ac_win_config::interrupt_setting.