SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
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;
The compare action is programmable for each compare block to one of 4 states:
00 = No action (Default)
01 = Set pin
10 = Clear pin
11 = Toggle pin
To set Compare 0 up to toggle the pin:
TimerRegs.T16PWM0CMPCTRL.bit.PWM_OUT_ACTION0 = 3;
There is also an OUT bit and an OUT_DRV bit. When a 1 is written to the OUT_DRV bit, the OUT bit value is placed on the pin. Both compare blocks and the OUT bit can work seamlessly together.
All of this only works, of course, if the OUT_ENA bit is set as well. The default state for the pin is as an input, so it is necessary to set the OUT_ENA bit if output is desired.
As already mentioned, each compare block can cause an interrupt, if it is enabled. The interrupt enable and flag bits are described in Section 11.22 for details.