SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
The compare control register also contains a SHADOW bit. It is normally cleared, but it can be set this way:
TimerRegs.T16PWM0CMPCTRL.bit.SHADOW = 1;
The SHADOW bit is useful for a PWM output that will vary over time. The compare blocks work by detecting when the compare data is equal to the 16 bit counter value. This works fine if the compare data is never changed.
If, however, the compare data value is reduced at the wrong time, it is possible for the compare block to miss it, and therefore for the PWM pulse to remain on for the entire period.
For example, suppose that the compare 1 data value is 100. Suppose that the counter value is 90, and the compare 1 data register is written to, changing the data value to 80. In this case, for one cycle, the compare 1 event will not occur. Normally for PWM, compare 1 is used to turn off the PWM pulse. So the result will be a PWM pulse that is on for the entire period.
If the SHADOW bit is set, it enables buffer registers, called shadow registers, for the compare data registers. The data written is stored in the shadow register until the next compare event, and only then is it written into the compare data register.
So to return to the example, the 80 will not be written into the data register until after the counter reaches 100, so the pulse will stop at 100, instead of going on to the end.
There are two side effects to using the shadow register:
Of course, the same thing could happen without the shadow bit set.