# 16/20MHz Oscillator (OSC20M)

This oscillator can operate at multiple frequencies, selected by the value of the Frequency Select bits (FREQSEL) in the Oscillator Configuration fuse (FUSE.OSCCFG). The center frequencies are:
• 16MHz
• 20MHz

After a System Reset, FUSE.OSCCFG determines the initial frequency of CLK_MAIN.

During Reset the calibration values for the OSC20M are loaded from fuses . There are two different calibration bit fields. The Calibration bit field (CAL20M) in the Calibration A register (CLKCTRL.OSC20MCALIBA) enables calibration around the current center frequency. The Oscillator Temperature Coefficient Calibration bit field (TEMPCAL20M) in the Calibration B register (CLKCTRL.OSC20MCALIBB) enables adjustment of the slope of the temperature drift compensation.

For applications requiring more fine-tuned frequency setting than the oscillator calibration provides, factory stored frequency error after calibrations are available. There are 4 errors, measured at different settings, available in Signature Row as signed byte values.

• SIGROW.OSC16ERR3V is the frequency error from 16MHz measured at 3V
• SIGROW.OSC16ERR5V is the frequency error from 16MHz measured at 5V
• SIGROW.OSC20ERR3V is the frequency error from 20MHz measured at 3V
• SIGROW.OSC20ERR5V is the frequency error from 20MHz measured at 5V

The example code below, demonstrates how to apply this value for more accurate USART baud rate:

  /* Baud rate compensated with factory stored frequency error */
/* Synchronous communication without Auto-baud (Sync Field)  */
/* 16MHz Clock, 3V and 600 BAUD                              */

int8_t  sigrow_value  = SIGROW.OSC16ERR3V;   // read signed error
int32_t baud          = 600;                 // ideal baud rate

baud *= (1024 + sigrow_value);               // sum resolution + error
baud /=  1024;                               // divide by resolution
USART0.BAUD = (int16_t) baud;                // set adjusted baud rate

The oscillator calibration can be locked by the Oscillator Lock (OSCLOCK) fuse (FUSE.OSCCFG). When this fuse is '1', it is not possible to change the calibration. The calibration is also locked if this oscillator is used as Main Clock source and the Lock Enable bit (LOCKEN) in the Control B register (CLKCTRL.OSC20MCALIBB) is '1'.

The calibration bits are also protected by the Configuration Change Protection Mechanism, requiring a timed write procedure for changing the Main Clock and Prescaler settings.

The start-up time of this oscillator is analog start-up time plus 4 oscillator cycles. Refer to Electrical Characteristics chapter for the start-up time.

When changing oscillator calibration value, the frequency may overshoot. If the oscillator is used as the main clock (CLK_MAIN) it is recommended to change the main clock prescaler so that the main clock frequency does not exceed ¼ of the maximum operation main clock frequency as described in the General Operating Ratings. The system clock prescaler can be changed back after the oscillator calibration value has been updated.