This section will include three mode switching examples using an 4 MHz externalcrystal.24.5.3.1 Example 1: Moving from FEI to BLPE mode: External Crystal= 4 MHz, MCGOUTCLK frequency = 4 MHzIn this example, the MCG will move through the proper operational modes from FEI toBLPE to achieve 4 MHz MCGOUTCLK frequency from 4 MHz external crystalreference. First, the code sequence will be described. Then there is a flowchart thatillustrates the sequence.1. First, FEI must transition to FBE mode:a. C2 = 0x1C• C2[RANGE0] set to 2'b01 because the frequency of 4 MHz is within thehigh frequency range.• C2[HGO0] set to 1 to configure the crystal oscillator for high gain operation.• C2[EREFS0] set to 1, because a crystal is being used.b. C1 = 0x90• C1[CLKS] set to 2'b10 to select external reference clock as system clocksource• C1[FRDIV] set to 3'b010, or divide-by-128 because 4 MHz / 128 = 31.25kHz which is in the 31.25 kHz to 39.0625 kHz range required by the FLL• C1[IREFS] cleared to 0, selecting the external reference clock and enablingthe external oscillator.c. Loop until S[OSCINIT0] is 1, indicating the crystal selected by C2[EREFS0] hasbeen initialized.d. Loop until S[IREFST] is 0, indicating the external reference is the current sourcefor the reference clock.e. Loop until S[CLKST] is 2'b10, indicating that the external reference clock isselected to feed MCGOUTCLK.2. Then, transition to BLPE:a. Set C2[LP] to 1.Chapter 24 Multipurpose Clock Generator (MCG)KL04 Sub-Family Reference Manual, Rev. 3.1, November 2012Freescale Semiconductor, Inc. 359