Initialization and Configuration
1268
SLAU723A – October 2017 – Revised October 2018
Copyright © 2017–2018, Texas Instruments Incorporated
General-Purpose Timers
18.4 Initialization and Configuration
To use a GPTM, the appropriate TIMERn bit must be set in the RCGCTIMER register (see
). If using any CCP pins, the clock to the appropriate GPIO module must be enabled using
the RCGCGPIO register (see
). To find out which GPIO port to enable, see the device-
specific data sheet. Configure the PMCn fields in the GPIOPCTL register to assign the CCP signals to the
appropriate pins (see
and the device-specific data sheet).
This section shows module initialization and configuration examples for each of the supported timer
modes.
18.4.1 One-Shot and Periodic Timer Mode
The GPTM is configured for One-Shot and Periodic modes by the following sequence:
1. Ensure the timer is disabled (the TnEN bit in the GPTMCTL register is cleared) before making any
changes.
2. Write the GPTM Configuration Register (GPTMCFG) with a value of 0x0000.0000.
3. Configure the TnMR field in the GPTM Timer n Mode Register (GPTMTnMR) :
1. Write a value of 0x1 for One-Shot mode.
2. Write a value of 0x2 for Periodic mode.
4. Optionally configure the TnSNAPS, TnWOT, TnMTE, and TnCDIR bits in the GPTMTnMR register to
select whether to capture the value of the free-running timer at time-out, use an external trigger to start
counting, configure an additional trigger or interrupt, and count up or down. In addition, if using CCP
pins, the TCACT field can be programmed to configure the compare action.
1. Load the start value into the GPTM Timer n Interval Load Register (GPTMTnILR).
2. If interrupts are required, set the appropriate bits in the GPTM Interrupt Mask Register
(GPTMIMR).
3. Set the TnEN bit in the GPTMCTL register to enable the timer and start counting.
4. Poll the GPTMRIS register or wait for the interrupt to be generated (if enabled). In both cases, the
status flags are cleared by writing a 1 to the appropriate bit of the GPTM Interrupt Clear Register
(GPTMICR).
If the TnMIE bit in the GPTMTnMR register is set, the RTCRIS bit in the GPTMRIS register is set, and
the timer continues counting. In One-Shot mode, the timer stops counting after the time-out event. To
reenable the timer, repeat the sequence. A timer configured in Periodic mode reloads the timer and
continues counting after the time-out event.
18.4.2 Real-Time Clock (RTC) Mode
To use the RTC mode, the timer must have a 32.768-KHz input signal on an even CCP input. To enable
the RTC feature, follow these steps:
1. Ensure the timer is disabled (the TAEN bit is cleared) before making any changes.
2. If the timer has been operating in a different mode prior to this, clear any residual set bits in the GPTM
Timer n Mode (GPTMTnMR) register before reconfiguring.
3. Write the GPTM Configuration Register (GPTMCFG) with a value of 0x0000.0001.
4. Write the match value to the GPTM Timer n Match Register (GPTMTnMATCHR).
5. Set/clear the RTCEN and TnSTALL bit in the GPTM Control Register (GPTMCTL) as needed.
6. If interrupts are required, set the RTCIM bit in the GPTM Interrupt Mask Register (GPTMIMR).
7. Set the TAEN bit in the GPTMCTL register to enable the timer and start counting.
When the timer count equals the value in the GPTMTnMATCHR register, the GPTM asserts the RTCRIS
bit in the GPTMRIS register and continues counting until Timer A is disabled or a hardware reset. The
interrupt is cleared by writing the RTCCINT bit in the GPTMICR register. If the GPTMTnILR register is
loaded with a new value, the timer begins counting at this new value and continues until it reaches
0xFFFF.FFFF, at which point it rolls over.