5.8.2 Operate as external event counter
It can be used as an event counter to count the detected valid edges (external events) of the TImn pin
input, and if the specified count value is reached, an interrupt is generated. The specified count values can
be calculated using the following calculation formula:
In event counter mode, the timer count register mn (TCRmn) is used as a decrement counter.
By setting any channel start trigger bit (TSmn, TSHm1, TSHm3) of the timer channel start register m
(TSm) to 1, load the value of the timer data register mn (TDRmn) into the TCRmn register.
The TCRmn register decrements the count while detecting the valid edge of the TImn pin input. If the
TCRmn changes to 0000H, the value of the TDRmn register is loaded again and INTTMmn is output.
After that, continue with the same run.
Because the TOmn pin outputs irregular waveforms based on external events, the TOEmn bit of timer
output enable register m (TOEm) must be set to 0 to stop the output.
The TDRmn register can be rewritten at any time, and the rewritten TDRmn register value is valid for
the next counting period.
Figure 5-46 Example of basic timing running as an external event counter
TSmn
TEmn
TImn
TCRmn
TDRmn
INTTMmn
Note 1. m: Unit number (m= 0,1) n: channel number (n=0 ~ 3).
2. TSmn: Bit n of the timer channel start register m (TSm).
TEmn: Timer channel enable bit n of status register m (TEm).
TImn: Input signal of the TImn pin.
TCRmn: Timer counter register mn (TCRmn).
TDRmn: Timer data register mn (TDRmn).