Microchip® Advanced Software Framework

Quick Start Guide for the ACC driver

This is the quick start guide for the SAM3S/4E/4S/V71/V70/S70/E70 Analog Comparator Controller (ACC) Driver, with step-by-step instructions on how to configure and use the driver for a specific use case.

The code examples can be copied into e.g. the main application loop or any other function that will need to control the ACC module.

Use Cases

ACC Basic Usage

This use case will demonstrate how to initialize the ACC module in interrupt mode.

Setup Steps

Prerequisites

This module requires the following service:

Setup Code

Add this to your main application C-file:

void ACC_Handler(void)
{
} 

Add this to the main loop or a setup function:

Workflow

  1. Initialize the ACC module so that:
    • ADC channel 5 is connected to its positive input
    • DAC channel 0 is connected to its negative input
    • Generate an interrupt on either edge of the output
    • Disable the ACC module output inversion
      acc_init(ACC, ACC_MR_SELPLUS_AD5, ACC_MR_SELMINUS_DAC0,
      ACC_MR_EDGETYP_ANY, ACC_MR_INV_DIS);
  2. Enable the ACC module interrupt:
    NVIC_EnableIRQ(ACC_IRQn);

Usage Steps

Usage Code

In the ACC_Handler() function, check if the output result is available by:

if ((ul_status & ACC_ISR_CE) == ACC_ISR_CE) {
} 

In the ACC_Handler() function, check if ADC channel 5 is greater than DAC channel 0 by:

if (acc_get_comparison_result(ACC)) {
    do_something_with_a_greater_result();
} 

In the ACC_Handler() function, check if ADC channel 5 is less than DAC channel 0 by:

if (!acc_get_comparison_result(ACC)) {
    do_something_with_a_lesser_result();
}