18.2.3.1.2 One-Shot Mode

The counter generates a single interrupt in this mode. On reaching zero, the counter halts until reprogrammed.

One-shot mode is selected by setting the TIMxMODE bit in the Table 18-8 register to 1. In this mode, the counter stops on reaching zero and a single interrupt is generated. When the counter is stopped in One-shot mode, it can be restarted by writing a non-zero value to the TIMx_LOADVAL register. Alternatively, the counter can be restarted by clearing the TIMxMODE bit. This causes the counter to be loaded with the value held in the Table 18-6 register and to begin operating in Periodic mode.

While the counter is counting down, it is possible to change the value of the TIMxMODE bit at any time without affecting the operation. For example, if the counter is decrementing in One-shot mode and the TIMxMODE bit is cleared before the counter reaches zero, the counter begins to operate in Periodic mode on reaching zero.

Writing to the TIMxBGLOADVAL register in One-shot mode has no real effect unless you intend to switch to Periodic mode when (or before) the next interrupt occurs. When in One-shot mode, the value written to TIMxBGLOADVAL is loaded into the TIMxLOADVAL register as normal but when the counter reaches zero, it generates a single interrupt and stops. Only a subsequent write to the TIMxLOADVAL register initiates another One-shot countdown sequence. However, if the counter is restarted by changing the Operating mode to Periodic (by clearing the TIMxMODE bit), the value written to the TIMxBGLOADVAL register is relevant because this is the start value (taken from the TIMxLOADVAL register) used to initialize the counter in Periodic mode.