Initialization and Configuration
www.ti.com
316
SWRU543–January 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
General-Purpose Timers
• In up-count mode, the timer counts from 0x0 to the value in the GPTMTnMATCHR and
GPTMTnPMR registers. When executing an up count, the value of GPTMTnPR and GPTMTnILR
must be greater than the value of GPTMTnPMR and GPTMTnMATCHR.
6. If interrupts are required, set the CnMIM bit in the GPTM Interrupt Mask (GPTMIMR) register.
7. Set the TnEN bit in the GPTMCTL register to enable the timer and begin waiting for edge events.
8. Poll the CnMRIS bit in the GPTMRIS register or wait for the interrupt to be generated (if enabled). In
both cases, the status flags are cleared by writing 1 to the CnMCINT bit of the GPTM Interrupt Clear
(GPTMICR) register.
When counting down in input edge-count mode, the timer stops after the programmed number of edge
events is detected. To re-enable the timer, ensure that the TnEN bit is cleared, and repeat Steps 4 to 8.
9.4.3 Input Edge-Time Mode
Configure the timer to input edge-time mode with the following sequence:
1. Ensure the timer is disabled (the TnEN bit is cleared) before making any changes.
2. Write the GPTM Configuration (GPTMCFG) register with a value of 0x0000.0004.
3. In the GPTM Timer Mode (GPTMTnMR) register, write the TnCMR field to 0x1 and the TnMR field to
0x3, and select a count direction by programming the TnCDIR bit.
4. Configure the type of event that the timer captures by writing the TnEVENT field of the GPTM Control
(GPTMCTL) register.
5. If using a prescaler, write the prescale value to the GPTM Timer n Prescale (GPTMTnPR) register.
6. Load the timer start value into the GPTM Timer n Interval Load (GPTMTnILR) register.
7. If interrupts are required, set the CnEIM bit in the GPTM Interrupt Mask (GPTMIMR) register.
8. Set the TnEN bit in the GPTM Control (GPTMCTL) register to enable the timer and start counting.
9. Poll the CnERIS bit in the GPTMRIS register, or wait for the interrupt to be generated (if enabled). In
both cases, the status flags are cleared by writing 1 to the CnECINT bit of the GPTM Interrupt Clear
(GPTMICR) register. The time at which the event happened can be obtained by reading the GPTM
Timer n (GPTMTnR) register.
In input edge timing mode, the timer continues running after an edge event is detected, but the timer
interval can be changed at any time by writing the GPTMTnILR register and clearing the TnILD bit in the
GPTMTnMR register. The change takes effect at the next cycle after the write.
9.4.4 PWM Mode
Configure the timer to PWM mode with the following sequence:
1. Ensure the timer is disabled (the TnEN bit is cleared) before making any changes.
2. Write the GPTM Configuration (GPTMCFG) register with a value of 0x0000.0004.
3. In the GPTM Timer Mode (GPTMTnMR) register, set the TnAMS bit to 0x1, the TnCMR bit to 0x0, and
the TnMR field to 0x2.
4. Configure the output state of the PWM signal (whether or not it is inverted) in the TnPWML field of the
GPTM Control (GPTMCTL) register.
5. If using a prescaler, write the prescale value to the GPTM Timer n Prescale (GPTMTnPR) register.
6. If using PWM interrupts, configure the interrupt condition in the TnEVENT field in the GPTMCTL
register, and enable the interrupts by setting the TnPWMIE bit in the GPTMTnMR register. Edge-detect
interrupt behavior is reversed when the PWM output is inverted.
7. Load the timer start value into the GPTM Timer n Interval Load (GPTMTnILR) register.
8. Load the GPTM Timer n Match (GPTMTnMATCHR) register with the match value.
9. Set the TnEN bit in the GPTM Control (GPTMCTL) register to enable the timer and begin generation of
the output PWM signal.