Microchip® Advanced Software Framework

SAM XOSC32K Runtime Failure Detector

Overview:

Introduction

This application demonstrates a runtime XOSC32K (external 32KHz crystal oscillator) failure detector, using hardware timer peripherals and the SAM event system.

A pair of timers are linked together; one with a clock source from the XOSC32K 32.768KHz external clock, and another from the OSC32K 32.768KHz internal RC clock source. Each time the XOSC32K timer reaches a configurable count value, a hardware event resets the second timer using the OSC32K clock source.

If the OSC32K clocked timer reaches a configurable count value before it is reset by the XOSC32K timer, the XOSC32K clock source is considered failed and a callback function is executed. If instead the XOSC32K closed clocked timer resets the OSC32K clocked timer, the oscillator is considered OK and another callback function is executed.

In the example application, the DFLL reference clock is automatically switched between the internal and external 32KHz clock sources depending on the external reference availability.

This application has been tested on following boards:

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

Usage

Connect an oscilloscope to PA28 of the SAM D20/D21 or PB22 of SAMR21 or PA08 of SAM D10/D11 or PA27 of SAML21 or PA14 of SAMR30 Xplained Pro. Run the example application, and press and hold the board button to turn off the external XOSC32K crystal clock source to observe the fail-over to the internal clock source. Releasing the button will re-enable the external crystal.

The board LED will be turned on when the external crystal is used, and will be turned off when the internal RC is used due to a crystal failure detection.

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.