Example Configuration For The Lifetime Timer - NXP Semiconductors MKL27Z128VFM4 Reference Manual

Table of Contents

Advertisement

Example configuration for the lifetime timer

The 100 MHz clock frequency equates to a clock period of 10 ns, so the PIT needs to
count for 6000 million cycles, which is more than a single timer can do. So, Timer 1 is
set up to trigger every 6 s (600 million cycles). Timer 2 is chained to Timer 1 and
programmed to trigger 10 times.
The value for the LDVAL register trigger is calculated as number of cycles-1, so
LDVAL1 receives the value 0x23C345FF and LDVAL2 receives the value 0x00000009.
The interrupt for Timer 2 is enabled by setting TCTRL2[TIE], the Chain mode is
activated by setting TCTRL2[CHN], and the timer is started by writing a 1 to
TCTRL2[TEN]. TCTRL1[TEN] needs to be set, and TCTRL1[CHN] and TCTRL1[TIE]
are cleared.
The following example code matches the described setup:
// turn on PIT
PIT_MCR = 0x00;
// Timer 2
PIT_LDVAL2 = 0x00000009; // setup Timer 2 for 10 counts
PIT_TCTRL2 = TIE; // enable Timer 2 interrupt
PIT_TCTRL2 |= CHN; // chain Timer 2 to Timer 1
PIT_TCTRL2 |= TEN; // start Timer 2
// Timer 1
PIT_LDVAL1 = 0x23C345FF; // setup Timer 1 for 600 000 000 cycles
PIT_TCTRL1 = TEN; // start Timer 1
30.8 Example configuration for the lifetime timer
To configure the lifetimer timer, channels 0 and 1 need to be chained together.
First the PIT module needs to be activated by writing a 0 to the MDIS bit in the CTRL
register, then the LDVAL registers need to be set to the maximum value.
The timer is a downcounter.
The following example code matches the described setup:
// turn on PIT
PIT_MCR = 0x00;
// Timer 1
PIT_LDVAL1 = 0xFFFFFFFF; // setup timer 1 for maximum counting period
PIT_TCTRL1 = 0x0; // disable timer 1 interrupts
PIT_TCTRL1 |= CHN; // chain timer 1 to timer 0
PIT_TCTRL1 |= TEN; // start timer 1
// Timer 0
498
KL27 Sub-Family Reference Manual , Rev. 5, 01/2016
Freescale Semiconductor, Inc.

Advertisement

Table of Contents
loading

Table of Contents