Microchip® Advanced Software Framework

SAM OSC8M Calibration Example

Overview:

Introduction

While some devices require exact timing, and therefore require an external calibration crystal or other high-accuracy clock source, other applications with looser accuracy requirements may use the internal RC Oscillator(s) for space and/or cost reasons. However, this can lead to unstable communication interfaces if the internal oscillator is not first calibrated against an accurate reference clock.

This application uses a known external reference frequency to calibrate the internal 8MHz (nominal) RC Oscillator, OSC8M, so that it is as close as possible to the desired 8MHz frequency.

This application has been tested on following boards:

  • SAM D20/D21 Xplained Pro

Usage Instructions

On startup, the application will immediately begin calibration of the OSC8M internal oscillator, against a 32.768KHz watch crystal attached to the device XOSC32K pins (see device datasheet). As the possible calibration values are cycled through, the board LED will turn on each time a better match is found, and turn off when an equal or lesser calibration value is tested. Once the best values are found, the results are printed to the device USART and the board LED will flash rapidly to signal the end of the calibration sequence.

Note
The calibration values are not stored to the device's non-volatile memory. The example execution time is depend on the configuration in conf_example file. It's about (2<<CONF_CALIBRATION_RESOLUTION) *(2<<CONF_FRANGE_CAL -1)*(2<<CONF_TEMP_CAL -1)*128/32768 seconds. To get more accurate result, we can increase the value of CONF_FRANGE_CAL, CONF_TEMP_CAL and CONF_CALIBRATION_RESOLUTION, but the execution time is also longer.

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.