Microchip® Advanced Software Framework

SAM ADC Sleepwalking Example

Overview:

Introduction

This application demonstrates how to configure the ADC in a sleepwalking operation, where the input voltage is measured at a fixed interval, but the device is not woken from sleep until the measured value is below a given threshold; in this application 0.5 Volts.

This application has been tested on following boards:

  • SAM D20/D21/R21/D11/L21/L22/C21/R30 Xplained Pro

Hardware Setup

This application use AIN0 as ADC input channel. When the measured voltage is lower than 0.5V, then the device will start toggling the led pin to signal that the low voltage condition has happened. Connect the PA02(EXT3 pin3) to GND in SAM D20/D21 Xplained Pro to trigger it. Connect the PA06(EXT1 pin3) to GND in SAM R21 Xplained Pro to trigger it. Connect the PA02(EXT1 pin3) to GND in SAM D10/D11 Xplained Pro to trigger it. Connect the PA03(EXT1 pin4) to GND in SAM L21/L22 Xplained Pro to trigger it. Connect the PA03_ADC_DAC_VREF(J701 pin4) to GND in SAM C21 Xplained Pro to trigger it. Connect the PA04(EXT1 pin14) to GND in SAM R30 Xplained Pro to trigger it.

If debugging it is also possible to start a debug session and place a breakpoint in the window callback that will trigger whenever the voltage has gone below the defined threshold.

The application can easily be modified to monitor other voltages by changing the input source and threshold values in the adc_setup function.

Implementation Details

ADC Configuration

The ADC is configured to perform hardware averaging on the measured value, where the ADC will sample the signal 16 times and find the average value in hardware. This smooths out high frequency noise.

Sample timing

To trigger the ADC conversions, the RTC is setup in 32-bit counter mode, clocked by the internal 32kHz oscillator divided by 32, giving a 1kHz input clock. A compare value of 1000 is used to trigger the ADC conversion every second.

Event Routing

The Event system is setup to route the compare match interrupt from the RTC to the ADC, and the ADC is configured to start a new conversion on an event input. The event channel is configured as an asynchronous channel, so no clock is needed for the event channel during sleep.

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.