This is the quick start guide for the SAM4L Analog Comparator Interface Controller (ACIFC) Driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.
Basic Use Case
In this basic use case ACIFC channel 0 is configured to compare the inputs from ACAP0 and ACAN0.
Prerequisites
Setup Steps
Example Code
Enable the following macros in the header file conf_clock.h:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
Add the following code to your application C-file:
Workflow
- Set system clock source as DFLL:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
- Set DFLL source as OSC32K:
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
- Initialize the system clock:
Usage Steps
Example Code
Add the following to, for example, the main loop in your application C-file:
#define EXAMPLE_AC_CHANNEL 0
ch_cfg.always_on = true;
ch_cfg.fast_mode = true;
Workflow
- Get the default configuration and initialize the module:
- Enable the module:
- Get the default configuration to initialize channel 0:
#define EXAMPLE_AC_CHANNEL 0
ch_cfg.always_on = true;
ch_cfg.fast_mode = true;
- Start a single comparison:
- Check if the comparison has completed: