AN020101–0804 Developing the Application with Z8 Encore! XP™ MCU
3
Application Note
Fail-Safe Clock Feature of the Z8 Encore! XP™ Microcontroller
Developing the Application with Z8 Encore! XP™ MCU
This section discusses the software implementation and demonstration of the fail-
safe clock feature in detail.
Software Implementation
System clock selection, GPIO and timer initialization, and the oscillator failure
interrupt routine are discussed below.
Selecting the System Clock
The init_external_systemclock () function selects the type of oscillator used
with the Z8 Encore! XP™ 4K Series MCU. The Z8 Encore! XP™ 4K Series Devel-
opment Board uses an 8 MHz off-chip ceramic resonator. The Oscillator Control
Register must be unlocked before writing. Writing the two-step sequence E7h fol-
lowed by 18h unlocks the Oscillator Control Register. The register automatically
locks upon successful completion of a register write to the OSCCTL.
The following sequence writes to the Oscillator Control Register:
OSCCTL = 0xE7; // Unlock sequence for OSCCTL write
OSCCTL = 0x18;
OSCCTL = 0x72;
With the above setting, the internal precision oscillator is enabled, the WDT oscil-
lator is enabled, failure detection and recovery of the primary oscillator is enabled,
and the external RC oscillator is enabled as the system clock.
Initializing the GPIO
The Development Board used to implement the fail-safe clock option has three
LEDs --- D2, D3 and D4. In this example, the GPIO pins are configured as output
pins to switch the D2, D3, and D4 LEDs on or off.
The D4 LED is connected to Port C, pin 3 (PC3), the D3 LED is connected to Port
A, pin 7 (PA7), and the D2 LED is connected to Port A, pin 6 (PA6). For schematic
details of these connections, please refer to the Z8 Encore! XP™ 4K Series Devel-
opment Kit User Manual (UM0166).
After these connections are made, the init_led_gpio() function initializes the
GPIO ports. On the target board, PA6 and PA7 control the D2 and D3 LEDs,
respectively, and PC3 controls the D4 LED. As a result of this initialization, each of
these port pins are configured as output ports.
Port C pins provide a current sourced output capable of driving an LED without
requiring an external resistor. The current output is programmed to source 13 mA.