Using the Internal Clock Source (ICS) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
5-2
Freescale Semiconductor
•
ICS_Init – ICS module configuration
This example configures one of six modes of operation for the ICS module.
These are the four definitions used in the ICS code source. You need to uncomment the desired mode and
compile the project. This makes the MCU work with the selected clock source. For example to configure
the ICS in FEE mode just delete the two slashes at the beginning of the define.
//#define FEI // Configure bus clock to run at 25 MHz in FEI mode.
//#define FEE // Configure bus clock to run at 2 MHz in FEE mode.
//#define FBI // Configure bus clock to run at low frequency in FBI mode.
//#define FBE // Configure bus clock to run at low frequency in FBE mode.
The code below executes the instructions to disable the watchdog, enable the Reset option and background
pin. The System Option Register 1 (SOPT1) is used to configure the MCU. The SCGC1 and SCGC2 are
registers used for power saving consumption, here the bus clock to peripherals can be enabled or disabled.
The clocks to the other peripherals are disabled.
void MCU_Init(void) {
SOPT1 = 0x23; // Watchdog disabled. Stop Mode Enabled. Background Pin
// enabled. RESET pin enabled.
SCGC1 = 0x20; // Bus to TPM1 peripheral is enabled.
SCGC2 = 0x00; // All clocks to peripherals are disabled.
}
This is the General Purpose Input/Output configuration. These code lines configure the directions for the
PTE port. Only one LED is connected to the PTE port; therefore the PTE0 pin is configured as output.
void GPIO_Init(void) {
PTEDD = 0x01; // Configure PTE port as output
PTED = 0x00; // Put 0's in PTE port
}
This is the initialization code for the internal source clock used for the QE MCU. This application
configures the MCU in one of six modes of the ICS module.
void ICS_Init(void) {
#ifdef FEI
ICSC1 = 0x04; // Output of FLL is selected and Internal Reference Selected
ICSC2 = 0x00; // Bus frequency divided by 1
ICSTRM = *(unsigned char*far)0xFFAF; // Initialize ICSTRM register from a non volatile memory
ICSSC = (*(unsigned char*far)0xFFAE) | 0xA0; /* Initialize ICSSC register from a non volatile
memory */
#endif
#ifdef FEE
ICSC1 = 0x00; // Output of FLL is selected
ICSC2 = 0x87; // Divides slected clock by 4. External reference is selected
ICSSC = 0x00; // Initialize ICSSC register from a non volatile memory
#endif
#ifdef FBE
ICSC1 = 0xB8; // External reference clock selected. External reference divided by 5
ICSC2 = 0x00; // Bus frequency divided by 1
ICSSC = 0x00; // Initialize ICSSC register from a non volatile memory
#endif
#ifdef FBI
ICSC1 = 0x40; // Internal reference clock is selected
ICSC2 = 0x00; // Divides selected clock by 1