
Internal Clock Generator Module (ICG)
MC68HC908KX8 MC68HC908KX2 MC68HC08KX8 Data Sheet, Rev. 2.1
78
Freescale Semiconductor
7.4.1 Switching Clock Sources
Switching from one clock source to another requires both clock sources to be enabled and stable. A
simple flow requires:
1.
Enable desired clock source
2.
Wait for it to become stable
3.
Switch clocks
4.
Disable previous clock source
The key point to remember in this flow is that the clock source cannot be switched (CS cannot be written)
unless the desired clock is on and stable. A short assembly code example of how to employ this flow is
shown in
Figure 7-8. This code is for illustrative purposes only and does not represent valid syntax for any
particular assembler.
;Clock Switching Code Example
;This code switches from Internal to External clock
;Clock Monitor and interrupts are not enabled
start
lda
#$13
;Mask for CS, ECGON, ECGS
; If switching from External to Internal, mask is $0C.
loop
**
;Other code here, such as writing the COP, since ECGS may
; take some time to set
sta
icgcr
;Try to set CS, ECGON and clear ICGON. ICGON will not
; clear until CS is set, and CS will not set until
; ECGON and ECGS are set.
cmpa
icgcr
;Check to see if ECGS set, then CS set, then ICGON clear
bne
loop
;Keep looping until ICGON is clear.
Figure 7-8. Code Example for Switching Clock Sources
7.4.2 Enabling the Clock Monitor
Many applications require the clock monitor to determine if one of the clock sources has become inactive,
so the other can be used to recover from a potentially dangerous situation. Using the clock monitor
requires both clocks to be active (ECGON and ICGON both set). To enable the clock monitor, both clocks
must also be stable (ECGS and ICGS both set). This is to prevent the use of the clock monitor when a
clock is first turned on and potentially unstable.
Enabling the clock monitor and clock monitor interrupts requires a flow similar to the one below:
1.
Enable the alternate clock source
2.
Wait for both clock sources to be stable
3.
Switch to the desired clock source if necessary
4.
Enable the clock monitor
5.
Enable clock monitor interrupts
These events must happen in sequence. A short assembly code example of how to employ this flow is
shown in
Figure 7-9. This code is for illustrative purposes only and does not represent valid syntax for any
particular assembler.