541
SAM4CP [DATASHEET]
43051E–ATPL–08/14
30.14 Slow Crystal Clock Frequency Monitor
The frequency of the slow clock crystal oscillator can be monitored by means of logic driven by the main RC oscillator
known as a reliable clock source. This function is enabled by configuring the XT32KFME bit of the CKGR_MOR.
An error flag (XT32KERR in PMC_SR) is asserted when the slow clock crystal oscillator frequency is out of the +/- 10%
nominal frequency value (i.e. 32.768 kHz). The error flag can be cleared only if the slow clock frequency monitoring is
disabled.
When the main RC oscillator frequency is 4 MHz, the accuracy of the measurement is +/-40% as this frequency is not
trimmed during production. Therefore, +/-10% accuracy is obtained only if the RC oscillator frequency is configured for 8
or 12 MHz.
The monitored clock frequency is declared invalid if at least 4 consecutive clock period measurement results are over the
nominal period +/-10%.
Due to the possible frequency variation of the embedded main RC oscillator acting as reference clock for the monitor
logic, any slow clock crystal frequency deviation over +/-10% of the nominal frequency is systematically reported as an
error by means of XT32KERR in PMC_SR. Between -1% and -10% and +1% and +10%, the error is not systematically
reported.
Thus only a crystal running at 32.768 kHz frequency ensures that the error flag will not be asserted. The permitted drift of
the crystal is 10000ppm (1%), which allows any standard crystal to be used.
If the main RC frequency needs to be changed while the slow clock frequency monitor is operating, the monitoring must
be stopped prior to change the main RC frequency. Then it can be re-enabled as soon as MOSCRCS is set in PMC_SR.
The error flag can be defined as an interrupt source of the PMC by setting the XT32KERR bit of PMC_IER.
30.15 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.
Switch the MAINCK to the main crystal oscillator by setting MOSCSEL in CKGR_MOR.
Wait for the MOSCSELS to be set in PMC_SR to ensure the switchover is complete.
Check the main clock frequency:
This main clock frequency can be measured via CKGR_MCFR.
3.
4.
5.
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.
If MAINF = 0, switch the MAINCK to the Fast RC Oscillator by clearing MOSCSEL in CKGR_MOR. If MAINF
≠
0,
proceed to
Step 6.
Set PLLx and Divider (if not required, proceed to
Step 7.
):
6.
In the names PLLx, DIVx, MULx, LOCKx, PLLxCOUNT, and CKGR_PLLxR, ‘x’ represents A or B.
All parameters needed to configure PLLx and the divider are located in CKGR_PLLxR.
The DIVx field is used to control the divider itself. This parameter can be programmed between 0 and 127. Divider
output is divider input divided by DIVx parameter. By default, DIVx field is set to 0 which means that the divider and
PLLx are turned off.