Microchip® Advanced Software Framework

Advanced use case - DFLL auto-calibration (XMEGA)

Advanced use case - DFLL auto-calibration (XMEGA)

This section will present a more advanced use case for the System Clock Management service. This use case will configure the main system clock to 2MHz, using the internal 2MHz RC oscillator calibrated against the internal 32KHz oscillator. The peripheral bus clocks will run at the same speed as the CPU clock, and the USB clock will be configured to use the internal 32MHz (nominal) RC oscillator calibrated to 48MHz with the USB Start-of-Frame as the calibration reference.

Prerequisites

  • None

Initialization code

Add to the application initialization code:

Workflow

  1. Configure the system clocks according to the settings in conf_clock.h:

Example code

Add or uncomment the following in your conf_clock.h header file, commenting out all other definitions of the same symbol(s):

#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC2MHZ
#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC OSC_ID_RC32KHZ
#define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC
#define CONFIG_OSC_RC32_CAL 48000000UL
#define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC OSC_ID_USBSOF

Workflow

  1. Configure the main system clock to use the internal 2MHz RC oscillator as its source:
    #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC2MHZ
  2. Configure the 2MHz DFLL auto-calibration to use the internal 32KHz RC oscillator:
    #define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC OSC_ID_RC32KHZ
    Note
    For auto-calibration it's typically more relevant to use an external 32KHz crystal. So if that's the case use OSC_ID_XOSC instead.
  3. Configure the USB module clock to use the internal fast (32MHz) RC oscillator:
    #define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC
  4. Configure the internal fast (32MHz) RC oscillator to calibrate to 48MHz using the USB Start of Frame (SOF) as the calibration reference:
    #define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC
    #define CONFIG_OSC_RC32_CAL 48000000UL
    #define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC OSC_ID_USBSOF