Prescaler
ICLK
16 Bit
Counter
PWMx
Compare
1
CMP1 Interrupt
Compare
0
CMP0 Interrupt
Pin
Control
OVF24 Interrupt
Counter Reset
T16PWMx Prescaler and Counter
400
SNIU028A – February 2016 – Revised April 2016
Copyright © 2016, Texas Instruments Incorporated
Timer Module Overview
Figure 11-2.
11.8 T16PWMx Prescaler and Counter
The Prescaler for the 16 bit PWM Timer is always driven by ICLK. The clock divide is equal to PRESCALE
+ 1.
Here is C code which sets the prescale value to 3, for a divide of 4:
TimerRegs.T16PWM0CNTCTRL.bit.PRESCALE = 3;
//divide by 4
To see the counter value, please follow the example below:
result = TimerRegs.T16PWM0CNTDAT.bit.CNT_DAT;
The counter is free-running and counts from 0x0000 after a reset. If the counter reaches 0xFFFF, it rolls
over to 0x0000 and continues counting. This rollover causes the overflow flag to be set and an interrupt to
be generated, if enabled. The interrupt and flag bits are well described in
.
The timer can also be reset by a compare event on the compare 0 block. To enable this function, use this
C code:
TimerRegs.T16PWM0CNTCTRL.bit.CMP_RESET_ENA = 1;
//enable Comp 0 reset
If this bit is set the counter will be reset when the counter reaches the value in the
T16PWM0CMP0DAT.bit.CMP_DAT register.
The 16 bit counter can also be reset by setting the SW_RESET bit:
TimerRegs.T16PWM0CNTCTRL.bit.SW_RESET = 0; //reset and stop counter
A zero in SW_RESET is the default state, so it is necessary to write a 1 to this bit in order for the counter
to run. The compare and control registers should be initialized before writing to SW_RESET to enable the
counter.
11.9 T16PWMx Compare Blocks
There are two Compare Blocks for the T16PWMx timer. The Compare 0 block has the capability to reset
the 16 bit counter. The Compare 1 block does not.
The Compare 0 block also has the highest priority. If both compare data registers are loaded with the
same value, the Compare 0 operation will take place, and the Compare 1 operation will be ignored.
Each compare block has a 16 bit data register. When the 16 bit counter value matches the value in the
data register, a programmed action can take place on the output pin for the T16. Here is the C code to
write to a compare data register:
TimerRegs.T16PWM0CMP0DAT.bit.CMP_DAT = 100;