There are several possible external clock sources, all sharing the XTAL1 and XTAL2 pins. Of course, this means that only one source can be enabled at any given time. Hardware makes sure that no two external sources are enabled simultaneously, and attempts to do so will be disregarded.
An exception to this is the Real-time Counter Oscillator using the TOSC1 and TOSC2 pins with an external watch crystal as a source to the Real-time Clock module. The Real-time Counter Oscillator can be used as a system clock source directly, but not the 1kHz prescaled signal as this only goes to the RTC. Refer to the application note “AVR1314: Using the XMEGA Real-time Counter” for more details on the RTC.
The XTAL1 and XTAL2 pins are input and output, respectively, of an inverting amplifier that serves as an on-chip oscillator using external crystals or resonators from 0.4MHz to 16MHz. This Crystal Oscillator (XOSC) can be configured for one the following options:
Actually, this is implemented as two crystal oscillators, one for 32.768kHz crystals and one for high-frequency crystals.
When using external 32kHz watch crystals, the 32kHz Crystal Oscillator Low-power Mode bit (X32KLPM) in the External Oscillator Control register (OSC.XOSCCTRL) enables low-power mode. This only applies to 32kHz watch crystals and should only be used with high quality crystals.
The External Oscillator Selection bitfield (XOSCSEL) in the External Oscillator Control register (OSC.XOSCCTRL) selects the external oscillator type and start-up time.
The External Oscillator Enable bit (XOSCEN) in the Oscillator Control register (OSC.CTRL) controls this oscillator, while the External Oscillator Ready bit (XOSCRDY) in the Oscillator Status register (OSC.STATUS) can be polled to check if it is stable and ready to be used as a system clock source.
The oscillator must be configured before enabling it and the configuration cannot be changed without disabling it first. Hardware will disregard any attempts to change configuration while it is enabled.
How to connect external crystals and the recommended capacitor values are shown in the figure and table below.
Frequency range | Capacitor value (C1 and C2) |
---|---|
0.4 – 2MHz | 100pF |
2 – 9MHz | 15pF |
9 – 12MHz | 15pF |
12 – 16MHz | 10pF |
If the hardware design provides an external clock signal, this can be connected to the XTAL1 pin and the on-chip crystal oscillator can be disabled. External clock is one of the possible selections in the External Oscillator Selection bitfield (XOSCSEL) in the External Oscillator Control register (OSC.XOSCCTRL) and always use a startup time of six clock cycles before being reported to be stable with the External Oscillator Ready bit (XOSCRDY) in the Oscillator Status register (OSC.STATUS).
The figure below shows how to connect an external clock signal. To ensure correct operation, the clock frequency should not change more than 2% from one cycle to another. If the clock frequency needs to change more rapidly, the XMEGA should be kept in a reset state during the change.