
General-Purpose Timers
139
March 22, 2006
Preliminary
8.
Set the
TnEN
bit in the
GPTMCTL
register to enable the timer and begin waiting for edge
events.
9.
Poll the
CnMRIS
bit or wait for the interrupt to be generated (if enabled). In both cases, the sta-
tus flags are cleared by writing a 1 to the
CnMCINT
bit of the
Interrupt Clear (GPTMICR)
reg-
ister.
In Input Edge Count Mode, the timer stops after the desired number of edge events has been
detected. To re-enable the timer, ensure that the
TnEN
bit is cleared and repeat steps 4-9.
9.3.5
16-Bit Input Edge Timing Mode
A timer is configured to Input Edge Timing mode by 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 to a value of 0x4.
3.
In the
GPTM Timer Mode (GPTMTnMR)
register, write the
TnCMR
field to 0x1 and the
TnMR
field to 0x3.
4.
Configure the type of event that the timer will capture by writing the
TnEVENT
field of the
GPTM Control (GPTMCTL)
register.
5.
Load the timer start value into the
Timern Interval Load (GPTMTnILR)
register.
6.
If interrupts are required, set the
CnEIM
bit in the
GPTM Interrupt Mask (GPTMIMR)
register.
7.
Set the
TnEN
bit in the
GPTM Control (GPTMCTL)
register to enable the timer and start
counting.
8.
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 a 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 Timern (GPTMTnR)
register.
In Input Edge Timing mode, the timer continues running after an edge event has been detected,
but the timer interval can be changed at any time by writing the
GPTMTnILR
register. The change
takes effect at the next cycle after the write.
9.3.6
16-Bit PWM Mode
A timer is configured to PWM mode using 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 to a value of 0x4.
3.
In the
GPTM Timer Mode (GPTMTnMR)
register, set the
TnAMS
field to 0x1 and the
TnMR
field to 0x2.
4.
Configure the output state of the PWM signal (whether or not it is inverted) in the
TnEVENT
field of the
GPTM Control (GPTMCTL)
register.
5.
Load the timer start value into the
Timern Interval Load (GPTMTnILR)
register.
6.
Load the
Timern Match (GPTMTnMATCHR)
register with the desired value.
7.
If a prescaler is going to be used, configure the
Timern Prescale (GPTMTnPR)
register and
the
Timern Prescale Match (GPTMTnPMR)
register.
8.
Set the
TnEN
bit in the
GPTM Control (GPTMCTL)
register to enable the timer and begin gen-
eration of the output PWM signal.