AT07899: SAM3S/4E/4S Analog Comparator Controller (ACC) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

Similar documents
DACC (Digital-to-Analog Converter Controller) The outline of this documentation is as follows: Module Overview. Special Considerations

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

CryptoAuth Xplained Pro

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

AT88CK490 Evaluation Kit

USER GUIDE EDBG. Description

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AT11805: Capacitive Touch Long Slider Design with PTC. Introduction. Features. Touch Solutions APPLICATION NOTE

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

SN 132 SNAPstick QUICK START GUIDE

SAMA5D2. Scope. Reference Documents. Atmel SMART ARM-based MPU ERRATA

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

AN3998 Application note

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN3332 Application note

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Wireless Subwoofer TI Design Tests

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AN AES encryption and decryption software on LPC microcontrollers. Document information

Open Source Used In Cisco Instant Connect for ios Devices 4.9(1)

AT09333: USB Host Interface (UHI) for Communication Class Device (CDC) Introduction. Atmel Microcontrollers APPLICATION NOTE

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN2680 Application note

GCLK (Generic Clock Management) PM (Power Management) SYSCTRL (Clock Source Control) The following devices can use this module:

APPLICATION NOTE. AT12405: Low Power Sensor Design with PTC. Atmel MCU Integrated Touch. Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

USER GUIDE. ZigBit USB Stick User Guide. Introduction

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

AT91SAM ARM-based Flash MCU. Application Note

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

Dell One Identity Cloud Access Manager How to Configure vworkspace Integration

General Porting Considerations. Memory EEPROM XRAM

Third Party Software Used In PLEK500 (Utility for Win) v1.x.xx.xxx

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

SAM4 Real-Time Clock (RTC)

Dell Migration Manager for Enterprise Social What Can and Cannot Be Migrated

ES_LPC4357/53/37/33. Errata sheet LPC4357/53/37/33. Document information

Spotlight Management Pack for SCOM

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

RSA Two Factor Authentication

Scanning Comparator (ScanComp) Features. General Description. Input/Output Connections. When to Use a Scanning Comparator. clock - Digital Input* 1.

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Using the RS232 serial evaluation boards on a USB port

BlackBerry Business Cloud Services. Version: Release Notes

TTL to RS232 Adapter User Guide

AN3354 Application note

Microsoft SharePoint

Introducing a platform to facilitate reliable and highly productive embedded developments

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Atmel SMART ARM Core-based Embedded Microprocessors

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

MDM Zinc 3.0 End User License Agreement (EULA)

System Center Virtual Machine Manager 2012 R2 Plug-In. Feature Description

COM Port Stress Test

Temperature & Humidity SMS Alert Controller

Dell Spotlight on Active Directory Server Health Wizard Configuration Guide

AN11008 Flash based non-volatile storage

Spotlight Management Pack for SCOM

CKEditor for Drupal License Agreement

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

Upgrading Intel AMT 5.0 drivers to Linux kernel v2.6.31

Dell InTrust Preparing for Auditing Cisco PIX Firewall

UM Vertical Alignment (VA) displays and NXP LCD drivers

Measuring Resistance Using Digital I/O

Pervasive Software Inc. Pervasive PSQL v11 Insurance License Agreement

BlackBerry Web Desktop Manager. Version: 5.0 Service Pack: 4. User Guide

Transcription:

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

Table of Contents Introduction...1 1. Software License... 4 2. Prerequisites...5 3. Module Overview...6 4. Special Considerations...7 4.1. Configuration Changes...7 4.2. I/O Lines... 7 4.3. Power Management... 7 4.4. Interrupt... 7 4.5. Fault Output...7 5. Extra Information... 8 6. Examples...9 7. API Overview...10 7.1. Macro Definitions...10 7.1.1. Hysteresis Levels...10 7.2. Function Definitions...10 7.2.1. Function acc_disable()...10 7.2.2. Function acc_disable_interrupt()... 10 7.2.3. Function acc_enable()...11 7.2.4. Function acc_enable_interrupt()... 11 7.2.5. Function acc_get_comparison_result()...11 7.2.6. Function acc_get_interrupt_status()...11 7.2.7. Function acc_get_writeprotect_status()...12 7.2.8. Function acc_init()... 12 7.2.9. Function acc_reset()... 14 7.2.10. Function acc_set_input()... 14 7.2.11. Function acc_set_output()... 15 7.2.12. Function acc_set_writeprotect()...16 8. Extra Information for Analog Comparator Controller... 17 8.1. Acronyms...17 8.2. Dependencies...17 8.3. Errata...17 8.4. Module History...17 9. Examples for Analog Comparator Controller...18 9.1. Quick Start Guide for the ACC driver... 18 9.1.1. Use Cases... 18 9.1.2. ACC Basic Usage... 18 2

9.1.3. Setup Steps... 18 9.1.4. Usage Steps... 19 9.2. Analog Comparator Controller - Example Interrupt Event Generation... 19 9.2.1. Purpose... 19 9.2.2. Requirements... 19 9.2.3....19 9.2.4. Main Files... 19 9.2.5. Compilation Information...20 9.2.6. Usage... 20 10. Document Revision History... 21 3

1. Software License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 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 without specific 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, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. 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; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4

2. Prerequisites There are no prerequisites for this module. 5

3. Module Overview The Analog Comparator Controller configures the Analog Comparator, and generates an interrupt according to the user application's settings. The analog comparator embeds 8 to 1 multiplexers on both its plus and minus inputs. The Analog Comparator compares two voltages, and the result of this comparison gives a compare output and an interrupt can be generated accordingly. The user application can select a high-speed or low-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. 6

4. Special Considerations 4.1. Configuration Changes As soon as the analog comparator settings are modified, the output of the analog comparator is masked for the time that its output may be invalid. Depending on the user application the following function calls may 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 Lines The 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 corresponding input is assigned to the comparator's plus/minus inputs by the user application performing a write to the module's Mode Register. 4.3. Power Management The ACC module is clocked through the Power Management Controller (PMC), thus the user application must 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. Interrupt The 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 Output The 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. 7

5. Extra Information For extra information, see Extra Information for Analog Comparator Controller. This includes: Acronyms Dependencies Errata Module History 8

6. Examples For a list of examples related to this driver, see Examples for Analog Comparator Controller. 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 the device-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-1 Parameters Data direction Parameter name [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-2 Parameters Data direction Parameter name [out] p_acc Module hardware register base address pointer 10

7.2.3. Function acc_enable() Enable the ACC module. void acc_enable( Acc * p_acc) Table 7-3 Parameters Data direction Parameter name [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-4 Parameters Data direction Parameter name [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-5 Parameters Data direction Parameter name [in] p_acc Module hardware register base address pointer Returns The ACC comparison result. Table 7-6 Return Values Return value 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) 11

Table 7-7 Parameters Data direction Parameter name [in] p_acc Module hardware register base address pointer Returns The 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-8 Parameters Data direction Parameter name [in] p_acc Module hardware register base address pointer Returns The ACC register write-protection status. Table 7-9 Return Values Return value 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-10 Parameters Data direction Parameter name [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) 12

Data direction Parameter name [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 ACC_MR_SELPLUS_AD0 ACC_MR_SELPLUS_AD1 ACC_MR_SELPLUS_AD2 ACC_MR_SELPLUS_AD3 ACC_MR_SELPLUS_AD4 ACC_MR_SELPLUS_AD5 ACC_MR_SELPLUS_AD6 ACC_MR_SELPLUS_AD7 Select AD0 as the plus input Select AD1 as the plus input Select AD2 as the plus input Select AD3 as the plus input Select AD4 as the plus input Select AD5 as the plus input Select AD6 as the plus input Select AD7 as the plus input Where the input parameter ul_select_minus is one of the following: Parameter Value ACC_MR_SELMINUS_TS ACC_MR_SELMINUS_ADVREF ACC_MR_SELMINUS_DAC0 ACC_MR_SELMINUS_DAC1 ACC_MR_SELMINUS_AD0 ACC_MR_SELMINUS_AD1 ACC_MR_SELMINUS_AD2 ACC_MR_SELMINUS_AD3 Select TS as the minus input Select ADVREF as the minus input Select DAC0 as the minus input Select DAC1 as the minus input Select AD0 as the minus input Select AD1 as the minus input Select AD2 as the minus input Select AD3 as the minus input Where the input parameter ul_edge_type is one of the following: Parameter Value ACC_MR_EDGETYP_RISING ACC_MR_EDGETYP_FALLING ACC_MR_EDGETYP_ANY Rising edge of comparator output Falling edge of comparator output Any edge of comparator output 13

Where the input parameter ul_invert is one of the following: Parameter Value ACC_MR_INV_DIS ACC_MR_INV_EN Comparator output is directly processed 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-11 Parameters Data direction Parameter name [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-12 Parameters Data direction Parameter name [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 ACC_MR_SELMINUS_TS ACC_MR_SELMINUS_ADVREF ACC_MR_SELMINUS_DAC0 ACC_MR_SELMINUS_DAC1 ACC_MR_SELMINUS_AD0 ACC_MR_SELMINUS_AD1 Select TS as the minus input Select ADVREF as the minus input Select DAC0 as the minus input Select DAC1 as the minus input Select AD0 as the minus input Select AD1 as the minus input 14

Parameter Value ACC_MR_SELMINUS_AD2 ACC_MR_SELMINUS_AD3 Select AD2 as the minus input Select AD3 as the minus input Where the input parameter ul_select_plus is one of the following: Parameter Value ACC_MR_SELPLUS_AD0 ACC_MR_SELPLUS_AD1 ACC_MR_SELPLUS_AD2 ACC_MR_SELPLUS_AD3 ACC_MR_SELPLUS_AD4 ACC_MR_SELPLUS_AD5 ACC_MR_SELPLUS_AD6 ACC_MR_SELPLUS_AD7 Select AD0 as the plus input Select AD1 as the plus input Select AD2 as the plus input Select AD3 as the plus input Select AD4 as the plus input Select AD5 as the plus input Select AD6 as the plus input 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-13 Parameters Data direction Parameter name [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 ACC_MR_INV_DIS ACC_MR_INV_EN Comparator output is directly processed Comparator output is inverted prior to being processed Where the input parameter ul_fault_enable is one of the following: 15

Parameter Value 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 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 FAULT output 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-14 Parameters Data direction Parameter name [out] p_acc Module hardware register base address pointer [in] ul_enable 1 to enable, 0 to disable 16

8. Extra Information for Analog Comparator Controller 8.1. Acronyms Below is a table listing the acronyms used in this module, along with their intended meanings. Acronym AD DAC GPIO NVIC PMC PWM QSG Definition Analog to Digital Digital to Analog Converter General Purpose Input Output Nested Vectored Interrupt Controller Power Management Controller Pulse Width Modulator Quick Start Guide 8.2. Dependencies This driver has the following dependencies: None 8.3. Errata There are no errata related to this driver. 8.4. Module History An overview of the module history is presented in the table below, with details on the enhancements and fixes made to the module since its first release. The current version of this corresponds to the newest version in the table. Changelog Initial document release 17

9. Examples for Analog Comparator Controller This is a list of the available Quick Start guides (QSGs) and example applications for SAM3S/4E/4S Analog Comparator Controller (ACC) Driver. QSGs are simple examples, with step-by-step instructions to configure and use this driver in a selection of use cases. Note that a QSG can be compiled as a standalone 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 stepby-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. 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: 9.1.3.2. Setup Code System Clock Management (sysclock) 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); 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 of inputs 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. The DAC0 and AD5 signals are selected as the inputs to the analog comparator. The user can change the 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, whilst the 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 19

9.2.5. Compilation Information 9.2.6. Usage This software is written for GNU GCC and IAR Embedded Workbench for Atmel. Other compilers may or may not work. 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. 20

10. Document Revision History Doc. Rev. Date Comments 42292B 07/2015 Updated title of application note and added list of supported devices 42292A 05/2014 Initial document release 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, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other 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 any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR 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, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. 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 any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety-Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.