Microchip® Advanced Software Framework

SAM D21 Analog Comparator Examples

Overview:

Introduction

This example demonstrates the different functional modes of Analog Comparator (AC) module in SAM D21 devices.

Analog comparator is configured in different modes like level crossing detector, window mode detector, false spike avoider or SleepWalking one at a time by commenting / uncommenting the macro AC_MODE in the application example.

This application has been tested on following board:

  • SAM D21 Xplained Pro

Hardware Setup

A sine wave signal should be applied on pin PA04 in the SAM D21 Xplained pro board. More details on analog input signal specification can be found in application note 'Analog Comparator Application Examples'. The device's analog comparator output pin (PA12) should be connected to an oscilloscope so that the generated waveform can be monitored.

Usage

The waveform selection macro AC_MODE should be set to required AC example.

The application will first configure the system clock and then configures the analog comparator based on selected example mode. In level crossing application, the output pin PA12 will be set when the analog input is above a threshold level. In window mode application, the output pin will be set whenever the input signal goes out of a window with two threshold levels. In false spike avoider application, hysteresis and filter mode are enabled which avoid frequent toggling of AC output when the analog input oscillates around the detect threshold. In SleepWalking mode, the analog comparator is configured in single shot mode which performs comparison every 10ms which is timed from RTC and triggered through Event System that reduces the overall current consumption of the system.

Compilation Info

This software was written for the GNU GCC and IAR for ARM. Other compilers may or may not work.

Contact Information

For further information, visit http://www.microchip.com.