5 Configure OSCHF to Run at 4 MHz and Activate/Deactivate the Auto-Tune Feature

The default frequency value setting for the internal high-frequency oscillator is 4 MHz.

The following line of code configures the OSCHF to run at 4 MHz:

_PROTECTED_WRITE (CLKCTRL.OSCHFCTRLA, CLKCTRL_FREQSEL_4M_gc);

The following line of code enables the auto-tune feature:

_PROTECTED_WRITE (CLKCTRL.OSCHFCTRLA, ((CLKCTRL_FREQSEL_4M_gc)|(CLKCTRL_AUTOTUNE_bm)));
Figure 5-1. 4 MHz Clock Without Tuning
Figure 5-2. 4 MHz Clock After Auto-Tune

As can be observed from the figures, the error is too small for the auto-tune feature to correct. The value in the tuning register is 0x00, the default at which it starts.

Note: The 4 MHz frequency is calibrated during fabrication. The higher values are derived from the 4 MHz one and are also calibrated.