
436
SAM G51 [DATASHEET]
11209C–ATARM–20-Dec-13
The counter is cleared when the slow RC oscillator clock signal is low and enabled when the signal is high. Thus the
failure detection time is 1 slow RC oscillator clock period. If, during the high level period of the slow RC oscillator clock
signal, less than 8 fast crystal oscillator clock periods have been counted, then a failure is reported.
If a failure of the main oscillator is detected, bit CFDEV in PMC_SR indicates a failure event and generates an interrupt if
the corresponding interrupt source is enabled. The interrupt remains active until a read occurs in PMC_SR. The user can
know the status of the clock failure detection at any time by reading the CFDS bit in PMC_SR.
Figure 23-4.
Clock Failure Detection (Example)
If the main oscillator is selected as the source clock of MAINCK (MOSCSEL in CKGR_MOR = 1), and if the master clock
source is PLLACK (CSS = 2), a clock failure detection automatically forces MAINCK to be the source clock for the master
clock (MCK).Then, regardless of the PMC configuration, a clock failure detection automatically forces the fast RC
oscillator to be the source clock for MAINCK. If the fast RC oscillator is disabled when a clock failure detection occurs, it
is automatically re-enabled by the clock failure detection mechanism.
It takes 2 slow RC oscillator clock cycles to detect and switch from the main oscillator, to the fast RC oscillator if the
source master clock (MCK) is main clock (MAINCK), or three slow clock RC oscillator cycles if the source of MCK is
PLLACK.
The user can know the status of the clock failure detector at any time by reading the FOS bit in PMC_SR.
This fault output remains active until the defect is detected and until it is cleared by the bit FOCLR in the PMC Fault
Output Clear Register (PMC_FOCR).
23.13 Programming Sequence
1.
If the fast crystal oscillator is not required, the PLL and divider can be directly configured (
Step 6.) else the fast
crystal oscillator must be started
(Step 2.).
2.
Enable the fast crystal oscillator:
The fast crystal oscillator is enabled by setting the MOSCXTEN field in CKGR_MOR. The user can define a start-
up time. This can be achieved by writing a value in the MOSCXTST field in CKGR_MOR. Once this register has
been correctly configured, the user must wait for MOSCXTS field in PMC_SR to be set. This can be done either by
polling MOSCXTS in PMC_SR, or by waiting for the interrupt line to be raised if the associated interrupt source
(MOSCXTS) has been enabled in PMC_IER.
3.
Switch the MAINCK to the main crystal oscillator by setting MOSCSEL in CKGR_MOR.
4.
Wait for the MOSCSELS to be set in PMC_SR to ensure the switchover is complete.
5.
Check the main clock frequency:
This main clock frequency can be measured via CKGR_MCFR.
Read CKGR_MCFR until the MAINFRDY field is set, after which the user can read the MAINF field in
CKGR_MCFR by performing an additional read. This provides the number of main clock cycles that have been
counted during a period of 16 slow clock cycles.
Main Crytal Clock
SLCK
Note: ratio of clock periods is for illustration purposes only
CDFEV
CDFS
Read PMC_SR