Introduction

Author: Egil Rotevatn, Microchip Technology Inc.

The External High-Frequency Oscillator (XOSCHF) enables the use of an external crystal or an external clock signal up to 32 MHz. This can be used as a clock source for the Main Clock (CLK_MAIN), the Real-Time Counter (RTC), and the 12-Bit Timer/Counter Type D (TCDn).

The Clock Failure Detection (CFD) feature can be used to detect if the output from a clock source stops, and can switch the Main Clock to a different clock source to continue operation or shutdown operation safely. This feature is most useful in applications where XOSCHF is in use, for instance to allow safe shutdown of a Functional Safety application.

This technical brief describes how the XOSCHF and CFD is used on the AVR® DB family of microcontrollers and covers the following use cases:

  • XOSCHF with External Crystal:

    Initialize XOSCHF for external crystal and change the main clock source to XOSCHF.

  • XOSCHF with External Clock:

    Initialize XOSCHF for external clock signal and change the main clock source to XOSCHF.

  • RTC with XOSCHF:

    Use XOSCHF as clock source for the RTC.

  • TCD with XOSCHF:

    Use XOSCHF as clock source for TCD0.

  • TCD with XOSCHF and PLL:

    Initialize the PLL with XOSCHF as clock source and use the PLL as clock source for TCD0.

  • CFD on XOSCHF:

    Initialize the CFD to monitor XOSCHF, enable the interrupt, and toggle an LED if the clock source fails.

  • CFD on Main Clock with NMI:

    Initialize the CFD to monitor Main Clock with XOSCHF as clock source, enable the interrupt as a Non-Maskable Interrupt (NMI), and toggle an LED with frequency derived from Main Clock.

The code examples are available in GitHub: