Microchip® Advanced Software Framework

Quick Start Guide for SAM4L Analog Comparator Driver

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

  1. Set system clock source as DFLL:
    #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
  2. Set DFLL source as OSC32K:
    #define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
  3. 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
struct ac_config module_cfg;
ac_get_config_defaults(&module_cfg);
ac_init(&ac_device, ACIFC, &module_cfg);
struct ac_ch_config ch_cfg;
ch_cfg.always_on = true;
ch_cfg.fast_mode = true;

Workflow

  1. Get the default configuration and initialize the module:
    struct ac_config module_cfg;
    ac_get_config_defaults(&module_cfg);
    ac_init(&ac_device, ACIFC, &module_cfg);
  2. Enable the module:
  3. Get the default configuration to initialize channel 0:
    #define EXAMPLE_AC_CHANNEL 0
    struct ac_ch_config ch_cfg;
    ch_cfg.always_on = true;
    ch_cfg.fast_mode = true;
  4. Start a single comparison:
  5. Check if the comparison has completed: