18.2.3.1.1 Periodic Mode

In this mode, the counter generates the interrupts at constant intervals. On reaching zero, the counter is reloaded with a value held in a register and counting restarts.

Periodic mode is selected by setting the TIMxMODE bit in the Table 18-8 register to 0. In this mode, the counter continually counts down to zero when it is enabled. On reaching zero, an interrupt is generated and the counter is reloaded with the value stored in the Table 18-6 register. The counter then continues to count down towards zero, without waiting for the interrupt to be cleared. The interrupt remains asserted until cleared by the processor. If the counter reaches zero without clearing the previous interrupt, the counter behaves as if it has just timed out (reached zero). In effect, an interrupt is lost. It can continue indefinitely as long as the counter is enabled in Periodic mode and interrupts are not cleared.

Writing to the TIMxLOADVAL register at any time causes the counter to be loaded immediately with the value written, and, if enabled, it will continue counting down from the new value. If the Table 18-7 (background load value) register is written, the value written overwrites the TIMxLOADVAL register. The counter is not updated immediately with the new value. However, when the counter reaches zero, it is loaded with the new value contained in the TIMxLOADVAL register. By making use of the TIMxBGLOADVAL register, it is possible to continually generate interrupts with varying or alternating time intervals between interrupts without having any arbitrary variation in the lengths of the intervals due to (possibly) different cycle counts for servicing successive interrupts. For example, this approach is used to allow a processor to generate a waveform with a non-equal mark-space ratio on a general purpose output pin.