22
SMART ARM-based Microcontrollers AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver APPLICATION NOTE Introduction This driver for Atmel ® | SMART ARM ® -based microcontrollers provides an interface for the configuration and management of the device's Analog Comparator Controller functionality. The Analog Comparator compares two voltages, and the result of this comparison gives a compare output. The user application can select whether to use a high-speed or a low-power option as well as selecting the hysteresis level, edge detection, and polarity. Devices from the following series can use this module: Atmel | SMART SAM3S Atmel | SMART SAM4E Atmel | SMART SAM4S The outline of this documentation is as follows: Prerequisites Module Overview Special Considerations Extra Information Examples API Overview Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

SAM3S/4E/4S Analog Comparator Controller (ACC) Driverww1.microchip.com/downloads/en/AppNotes/Atmel... · The ACC module is clocked through the Power Management Controller ... Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application

Embed Size (px)

Citation preview

  • SMART ARM-based Microcontrollers

    AT07899: SAM3S/4E/4S Analog ComparatorController (ACC) Driver

    APPLICATION NOTE

    Introduction

    This driver for Atmel | SMART ARM-based microcontrollers provides aninterface for the configuration and management of the device's AnalogComparator Controller functionality.

    The Analog Comparator compares two voltages, and the result of thiscomparison gives a compare output. The user application can selectwhether to use a high-speed or a low-power option as well as selecting thehysteresis level, edge detection, and polarity.

    Devices from the following series can use this module: Atmel | SMART SAM3S Atmel | SMART SAM4E Atmel | SMART SAM4S

    The outline of this documentation is as follows: Prerequisites Module Overview Special Considerations Extra Information Examples API Overview

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

  • Table of Contents

    Introduction......................................................................................................................1

    1. Software License....................................................................................................... 4

    2. Prerequisites..............................................................................................................5

    3. Module Overview.......................................................................................................6

    4. Special Considerations..............................................................................................74.1. Configuration Changes.................................................................................................................74.2. I/O Lines....................................................................................................................................... 74.3. Power Management..................................................................................................................... 74.4. Interrupt........................................................................................................................................ 74.5. Fault Output..................................................................................................................................7

    5. Extra Information....................................................................................................... 8

    6. Examples...................................................................................................................9

    7. API Overview...........................................................................................................107.1. Macro Definitions........................................................................................................................10

    7.1.1. Hysteresis Levels.........................................................................................................107.2. Function Definitions....................................................................................................................10

    7.2.1. Function acc_disable().................................................................................................107.2.2. Function acc_disable_interrupt()................................................................................. 107.2.3. Function acc_enable()..................................................................................................117.2.4. Function acc_enable_interrupt().................................................................................. 117.2.5. Function acc_get_comparison_result()........................................................................117.2.6. Function acc_get_interrupt_status().............................................................................117.2.7. Function acc_get_writeprotect_status().......................................................................127.2.8. Function acc_init()....................................................................................................... 127.2.9. Function acc_reset().................................................................................................... 147.2.10. Function acc_set_input()............................................................................................. 147.2.11. Function acc_set_output()........................................................................................... 157.2.12. Function acc_set_writeprotect()...................................................................................16

    8. Extra Information for Analog Comparator Controller............................................... 178.1. Acronyms....................................................................................................................................178.2. Dependencies.............................................................................................................................178.3. Errata..........................................................................................................................................178.4. Module History............................................................................................................................17

    9. Examples for Analog Comparator Controller...........................................................189.1. Quick Start Guide for the ACC driver......................................................................................... 18

    9.1.1. Use Cases................................................................................................................... 189.1.2. ACC Basic Usage........................................................................................................ 18

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    2

  • 9.1.3. Setup Steps................................................................................................................. 189.1.4. Usage Steps................................................................................................................ 19

    9.2. Analog Comparator Controller - Example Interrupt Event Generation....................................... 199.2.1. Purpose....................................................................................................................... 199.2.2. Requirements.............................................................................................................. 199.2.3. Description...................................................................................................................199.2.4. Main Files.................................................................................................................... 199.2.5. Compilation Information...............................................................................................209.2.6. Usage.......................................................................................................................... 20

    10. Document Revision History..................................................................................... 21

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    3

  • 1. Software LicenseRedistribution and use in source and binary forms, with or without modification, are permitted providedthat the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this list of conditions and thefollowing disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and thefollowing disclaimer in the documentation and/or other materials provided with the distribution.

    3. The name of Atmel may not be used to endorse or promote products derived from this software withoutspecific prior written permission.

    4. This software may only be redistributed and used in connection with an Atmel microcontroller product.

    THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESSFOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLYDISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ORBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OFSUCH DAMAGE.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    4

  • 2. PrerequisitesThere are no prerequisites for this module.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    5

  • 3. Module OverviewThe Analog Comparator Controller configures the Analog Comparator, and generates an interruptaccording to the user application's settings. The analog comparator embeds 8 to 1 multiplexers on bothits plus and minus inputs.

    The Analog Comparator compares two voltages, and the result of this comparison gives a compareoutput and an interrupt can be generated accordingly. The user application can select a high-speed orlow-power option, the hysteresis level, edge detection, and polarity.

    The ACC can also generate a comparison event that can be used by the Pulse Width Modulation (PWM)module.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    6

  • 4. Special Considerations

    4.1. Configuration ChangesAs soon as the analog comparator settings are modified, the output of the analog comparator is maskedfor the time that its output may be invalid. Depending on the user application the following function callsmay require the comparator output to be valid before continuing:

    acc_enable() acc_set_input() acc_set_output()

    The following code may be used to check if the comparator output is valid before continuing:* while ((acc_get_interrupt_status(ACC) & ACC_ISR_MASK) == ACC_ISR_MASK) {* }

    4.2. I/O LinesThe analog input pins (AD0-AD7 and DAC0-1) are multiplexed with general-purpose input/output (GPIO)lines. The assignment of these pins to ACC module inputs is automatically done when the correspondinginput is assigned to the comparator's plus/minus inputs by the user application performing a write to themodule's Mode Register.

    4.3. Power ManagementThe ACC module is clocked through the Power Management Controller (PMC), thus the user applicationmust first configure the PMC, in order to enable the Analog Comparator Controller clock.

    Note: The voltage regulator must be activated before the Analog Comparator module is used.

    4.4. InterruptThe ACC module has an interrupt line connected to the Nested Vectored Interrupt Controller (NVIC).Handling the ACC interrupt requires that the NVIC is configured before configuring the ACC.

    4.5. Fault OutputThe ACC module has a FAULT output that is connected to the FAULT input of the PWM module. Refer to"fault mode" and the implementation of the PWM in the device-specific datasheet.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    7

  • 5. Extra InformationFor extra information, see Extra Information for Analog Comparator Controller. This includes:

    Acronyms Dependencies Errata Module History

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    8

  • 6. ExamplesFor a list of examples related to this driver, see Examples for Analog Comparator Controller.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    9

  • 7. API Overview

    7.1. Macro Definitions

    7.1.1. Hysteresis Levels

    Refer to the "Analog Comparator Characteristics" table in the "Electrical Characteristics" chapter of thedevice-specific datasheet.

    7.1.1.1. Macro ACC_ACR_HYST_0mv_max

    #define ACC_ACR_HYST_0mv_max

    7.1.1.2. Macro ACC_ACR_HYST_50mv_max

    #define ACC_ACR_HYST_50mv_max

    7.1.1.3. Macro ACC_ACR_HYST_90mv_max

    #define ACC_ACR_HYST_90mv_max

    7.2. Function Definitions

    7.2.1. Function acc_disable()

    Disable the ACC module.

    void acc_disable( Acc * p_acc)

    Table 7-1Parameters

    Data direction Parameter name Description

    [in, out] p_acc Module hardware register base address pointer

    7.2.2. Function acc_disable_interrupt()

    Disable the ACC comparison edge interrupt.

    void acc_disable_interrupt( Acc * p_acc)

    Table 7-2Parameters

    Data direction Parameter name Description

    [out] p_acc Module hardware register base address pointer

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    10

  • 7.2.3. Function acc_enable()

    Enable the ACC module.

    void acc_enable( Acc * p_acc)

    Table 7-3Parameters

    Data direction Parameter name Description

    [in, out] p_acc Module hardware register base address pointer

    7.2.4. Function acc_enable_interrupt()

    Enable the ACC comparison edge interrupt.

    void acc_enable_interrupt( Acc * p_acc)

    Table 7-4Parameters

    Data direction Parameter name Description

    [out] p_acc Module hardware register base address pointer

    7.2.5. Function acc_get_comparison_result()

    Get the ACC comparison result.

    uint32_t acc_get_comparison_result( Acc * p_acc)

    Table 7-5Parameters

    Data direction Parameter name Description

    [in] p_acc Module hardware register base address pointer

    ReturnsThe ACC comparison result.

    Table 7-6Return Values

    Return value Description

    0 Comparator minus input is greater than its plus input (inn>inp)

    1 Comparator plus input is greater than its minus input (inp>inn)

    7.2.6. Function acc_get_interrupt_status()

    Get the ACC comparison edge interrupt status.

    uint32_t acc_get_interrupt_status( Acc * p_acc)

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    11

  • Table 7-7Parameters

    Data direction Parameter name Description

    [in] p_acc Module hardware register base address pointer

    ReturnsThe ACC comparison edge interrupt status.

    7.2.7. Function acc_get_writeprotect_status()

    Get the ACC register write-protection status.

    uint32_t acc_get_writeprotect_status( Acc * p_acc)

    Table 7-8Parameters

    Data direction Parameter name Description

    [in] p_acc Module hardware register base address pointer

    ReturnsThe ACC register write-protection status.

    Table 7-9Return Values

    Return value Description

    0 No write-protection error

    ACC_WPSR_WPROTERR Write-protection error

    7.2.8. Function acc_init()

    Initialize the ACC module.

    void acc_init( Acc * p_acc, uint32_t ul_select_plus, uint32_t ul_select_minus, uint32_t ul_edge_type, uint32_t ul_invert)

    Note: This function performs a software reset on the ACC module prior to its initialization.

    Table 7-10Parameters

    Data direction Parameter name Description

    [in, out] p_acc Module hardware register base address pointer

    [in] ul_select_plus Selection for the plus comparator input (inp)

    [in] ul_select_minus Selection for the minus comparator input (inn)

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    12

  • Data direction Parameter name Description

    [in] ul_edge_type Comparison flag triggering mode

    [in] ul_invert Invert the comparator output mode

    Where the input parameter ul_select_plus is one of the following:

    Parameter Value Description

    ACC_MR_SELPLUS_AD0 Select AD0 as the plus input

    ACC_MR_SELPLUS_AD1 Select AD1 as the plus input

    ACC_MR_SELPLUS_AD2 Select AD2 as the plus input

    ACC_MR_SELPLUS_AD3 Select AD3 as the plus input

    ACC_MR_SELPLUS_AD4 Select AD4 as the plus input

    ACC_MR_SELPLUS_AD5 Select AD5 as the plus input

    ACC_MR_SELPLUS_AD6 Select AD6 as the plus input

    ACC_MR_SELPLUS_AD7 Select AD7 as the plus input

    Where the input parameter ul_select_minus is one of the following:

    Parameter Value Description

    ACC_MR_SELMINUS_TS Select TS as the minus input

    ACC_MR_SELMINUS_ADVREF Select ADVREF as the minus input

    ACC_MR_SELMINUS_DAC0 Select DAC0 as the minus input

    ACC_MR_SELMINUS_DAC1 Select DAC1 as the minus input

    ACC_MR_SELMINUS_AD0 Select AD0 as the minus input

    ACC_MR_SELMINUS_AD1 Select AD1 as the minus input

    ACC_MR_SELMINUS_AD2 Select AD2 as the minus input

    ACC_MR_SELMINUS_AD3 Select AD3 as the minus input

    Where the input parameter ul_edge_type is one of the following:

    Parameter Value Description

    ACC_MR_EDGETYP_RISING Rising edge of comparator output

    ACC_MR_EDGETYP_FALLING Falling edge of comparator output

    ACC_MR_EDGETYP_ANY Any edge of comparator output

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    13

  • Where the input parameter ul_invert is one of the following:

    Parameter Value Description

    ACC_MR_INV_DIS Comparator output is directly processed

    ACC_MR_INV_EN Comparator output is inverted prior to being processed

    7.2.9. Function acc_reset()

    Software reset the ACC module.

    void acc_reset( Acc * p_acc)

    Table 7-11Parameters

    Data direction Parameter name Description

    [out] p_acc Module hardware register base address pointer

    7.2.10. Function acc_set_input()

    Set the ACC comparator plus/minus input sources.

    void acc_set_input( Acc * p_acc, uint32_t ul_select_minus, uint32_t ul_select_plus)

    Table 7-12Parameters

    Data direction Parameter name Description

    [in, out] p_acc Module hardware register base address pointer

    [in] ul_select_minus Selection for the minus comparator input (inn)

    [in] ul_select_plus Selection for the plus comparator input (inp)

    Where the input parameter ul_select_minus is one of the following:

    Parameter Value Description

    ACC_MR_SELMINUS_TS Select TS as the minus input

    ACC_MR_SELMINUS_ADVREF Select ADVREF as the minus input

    ACC_MR_SELMINUS_DAC0 Select DAC0 as the minus input

    ACC_MR_SELMINUS_DAC1 Select DAC1 as the minus input

    ACC_MR_SELMINUS_AD0 Select AD0 as the minus input

    ACC_MR_SELMINUS_AD1 Select AD1 as the minus input

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    14

  • Parameter Value Description

    ACC_MR_SELMINUS_AD2 Select AD2 as the minus input

    ACC_MR_SELMINUS_AD3 Select AD3 as the minus input

    Where the input parameter ul_select_plus is one of the following:

    Parameter Value Description

    ACC_MR_SELPLUS_AD0 Select AD0 as the plus input

    ACC_MR_SELPLUS_AD1 Select AD1 as the plus input

    ACC_MR_SELPLUS_AD2 Select AD2 as the plus input

    ACC_MR_SELPLUS_AD3 Select AD3 as the plus input

    ACC_MR_SELPLUS_AD4 Select AD4 as the plus input

    ACC_MR_SELPLUS_AD5 Select AD5 as the plus input

    ACC_MR_SELPLUS_AD6 Select AD6 as the plus input

    ACC_MR_SELPLUS_AD7 Select AD7 as the plus input

    7.2.11. Function acc_set_output()

    Set the ACC output.

    void acc_set_output( Acc * p_acc, uint32_t ul_invert, uint32_t ul_fault_enable, uint32_t ul_fault_source)

    Table 7-13Parameters

    Data direction Parameter name Description

    [in, out] p_acc Module hardware register base address pointer

    [in] ul_invert Invert comparator output

    [in] ul_fault_enable Fault enable

    [in] ul_fault_source Selection of fault source

    Where the input parameter ul_invert is one of the following:

    Parameter Value Description

    ACC_MR_INV_DIS Comparator output is directly processed

    ACC_MR_INV_EN Comparator output is inverted prior to being processed

    Where the input parameter ul_fault_enable is one of the following:

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    15

  • Parameter Value Description

    ACC_MR_FE_DIS The FAULT output is tied to 0

    ACC_MR_FE_EN The FAULT output is driven by ul_fault_source

    Where the input parameter ul_fault_source is one of the following:

    Parameter Value Description

    ACC_MR_SELFS_CF The CF flag is used to drive the FAULT output

    ACC_MR_SELFS_OUTPUT The output of the Analog Comparator flag is used to drive the FAULToutput

    7.2.12. Function acc_set_writeprotect()

    Set the ACC register write-protection.

    void acc_set_writeprotect( Acc * p_acc, uint32_t ul_enable)

    Table 7-14Parameters

    Data direction Parameter name Description

    [out] p_acc Module hardware register base address pointer

    [in] ul_enable 1 to enable, 0 to disable

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    16

  • 8. Extra Information for Analog Comparator Controller

    8.1. AcronymsBelow is a table listing the acronyms used in this module, along with their intended meanings.

    Acronym Definition

    AD Analog to Digital

    DAC Digital to Analog Converter

    GPIO General Purpose Input Output

    NVIC Nested Vectored Interrupt Controller

    PMC Power Management Controller

    PWM Pulse Width Modulator

    QSG Quick Start Guide

    8.2. DependenciesThis driver has the following dependencies:

    None

    8.3. ErrataThere are no errata related to this driver.

    8.4. Module HistoryAn overview of the module history is presented in the table below, with details on the enhancements andfixes made to the module since its first release. The current version of this corresponds to the newestversion in the table.

    Changelog

    Initial document release

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    17

  • 9. Examples for Analog Comparator ControllerThis is a list of the available Quick Start guides (QSGs) and example applications for SAM3S/4E/4SAnalog Comparator Controller (ACC) Driver. QSGs are simple examples, with step-by-step instructions toconfigure and use this driver in a selection of use cases. Note that a QSG can be compiled as astandalone application or be added to the user application.

    Quick Start Guide for the ACC driver Analog Comparator Controller - Example Interrupt Event Generation

    9.1. Quick Start Guide for the ACC driver

    This is the quick start guide for the SAM3S/4E/4S 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 examplescan be copied into e.g. the main application loop or any other function that will need to control the ACCmodule.

    9.1.1. Use Cases

    ACC Basic Usage

    9.1.2. ACC Basic Usage

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

    9.1.3. Setup Steps

    9.1.3.1. Prerequisites

    This module requires the following service: System Clock Management (sysclock)

    9.1.3.2. Setup Code

    Add this to your main application C-file:void ACC_Handler(void){}

    Add this to the main loop or a setup function:pmc_enable_periph_clk(ID_ACC);

    9.1.3.3. 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);

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    18

  • 2. Enable the ACC module interrupt:NVIC_EnableIRQ(ACC_IRQn);

    acc_enable_interrupt(ACC);

    9.1.4. Usage Steps

    9.1.4.1. 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();}

    9.2. Analog Comparator Controller - Example Interrupt Event Generation

    9.2.1. Purpose

    This example demonstrates how to use the ACC driver to perform a voltage comparison on a pair ofinputs and generate an interrupt.

    9.2.2. Requirements

    This example can be used on the following evaluation kits: SAM4S EK SAM4S EK2

    9.2.3. Description

    The DAC0 and AD5 signals are selected as the inputs to the analog comparator. The user can changethe output voltage of DAC0 and also change the voltage on AD5 by adjusting VR1 on the evaluation kit.

    The DAC0 output voltage can be adjusted between (1/6)*ADVREF and (5/6)*ADVREF in software, whilstthe input voltage on AD5 can vary between 0 and ADVREF.

    A comparison interrupt event is generated when the input voltages are no longer equal.

    9.2.4. Main Files

    acc.c: Analog Comparator Controller driver acc.h: Analog Comparator Controller driver header file acc_example.c: Analog Comparator Controller example application

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    19

  • 9.2.5. Compilation Information

    This software is written for GNU GCC and IAR Embedded Workbench for Atmel. Other compilers mayor may not work.

    9.2.6. Usage

    1. Build the program and download it into the evaluation board.2. On the computer, open, and configure a terminal application (e.g., HyperTerminal on Microsoft

    Windows) with these settings: 115200 baud 8 bits of data No parity 1 stop bit No flow control

    3. Start the application.4. In the terminal window, the following text should appear:

    -- ACC IRQ Example xxx ---- xxxxxx-xx-- Compiled: xxx xx xxxx xx:xx:xx --

    -- Menu Choices for this example---- s: Set new DAC0 output voltage.---- v: Get voltage on potentiometer.---- m: Display this menu again.--

    5. Enter a character on the terminal to select a menu option.6. Change the voltage on AD5 by adjusting VR1 on the evaluation kit in order. To see what

    comparison events occur.

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    20

  • 10. Document Revision HistoryDoc. Rev. Date Comments

    42292B 07/2015 Updated title of application note and added list of supported devices

    42292A 05/2014 Initial document release

    Atmel AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver [APPLICATIONNOTE]

    Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    21

  • Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 | www.atmel.com

    2015 Atmel Corporation. / Rev.: Atmel-42292B-SAM3S/4E/4S-Analog-Comparator-Controller-ACC-Driver_AT07899_Application Note-07/2015

    Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, and others are registered trademarks or trademarks of Atmel Corporation in U.S. andother countries. ARM, ARM Connected, and others are registered trademarks of ARM Ltd. Windows is a registered trademark of Microsoft Corporation in U.S.and or other countries. Other terms and product names may be trademarks of others.

    DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to anyintellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS ANDCONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIEDOR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESSINTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISEDOF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of thisdocument and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment toupdate the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotiveapplications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.

    SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with anyapplications where the failure of such products would reasonably be expected to result in significant personal injury or death (Safety-Critical Applications) withoutan Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for theoperation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environmentsunless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specificallydesignated by Atmel as automotive-grade.

    https://www.facebook.com/AtmelCorporationhttps://twitter.com/Atmelhttp://www.linkedin.com/company/atmel-corporationhttps://plus.google.com/106109247591403112418/postshttp://www.youtube.com/user/AtmelCorporationhttp://en.wikipedia.org/wiki/Atmelhttp://www.atmel.com

    IntroductionTable of Contents1.Software License2.Prerequisites3.Module Overview4.Special Considerations4.1.Configuration Changes4.2.I/O Lines4.3.Power Management4.4.Interrupt4.5.Fault Output

    5.Extra Information6.Examples7.API Overview7.1.Macro Definitions7.1.1.Hysteresis Levels7.1.1.1.Macro ACC_ACR_HYST_0mv_max7.1.1.2.Macro ACC_ACR_HYST_50mv_max7.1.1.3.Macro ACC_ACR_HYST_90mv_max

    7.2.Function Definitions7.2.1.Function acc_disable()7.2.2.Function acc_disable_interrupt()7.2.3.Function acc_enable()7.2.4.Function acc_enable_interrupt()7.2.5.Function acc_get_comparison_result()7.2.6.Function acc_get_interrupt_status()7.2.7.Function acc_get_writeprotect_status()7.2.8.Function acc_init()7.2.9.Function acc_reset()7.2.10.Function acc_set_input()7.2.11.Function acc_set_output()7.2.12.Function acc_set_writeprotect()

    8.Extra Information for Analog Comparator Controller8.1.Acronyms8.2.Dependencies8.3.Errata8.4.Module History

    9.Examples for Analog Comparator Controller9.1.Quick Start Guide for the ACC driver9.1.1.Use Cases9.1.2.ACC Basic Usage9.1.3.Setup Steps9.1.3.1.Prerequisites9.1.3.2.Setup Code9.1.3.3.Workflow

    9.1.4.Usage Steps9.1.4.1.Usage Code

    9.2.Analog Comparator Controller - Example Interrupt Event Generation9.2.1.Purpose9.2.2.Requirements9.2.3.Description9.2.4.Main Files9.2.5.Compilation Information9.2.6.Usage

    10.Document Revision History