2.4 Multi-Function Timer
111
(3) Interval Interrupt Using the Zero-Detect Interrupt Masking Function
The multi-function timer can be used as a 14-bit timer with count clock source selection set for 16
MHz, to generate interrupts at constant intervals up to a maximum of approximately 32.7 ms. And by
using the zero-detect interrupt mask function, the interval time can be extended to approximately 458.7
ms when operating at 16 MHz. The interval time is determined by the formula:
Interval time = CLRBR × TCS1 to TCS0 × MODE × (CYC + 1) [machine cycles]
CLRBR (14-bit timer value)
: 0000H to 3FFFH(0 to 16383)
TCS1 to 0 (count clock sourse)
: 1, 2, 8, or 16
MODE (count mode selection)
: ‘1’ for up-count mode, ‘2’ for up/down count mode
CYC (zero-detect mask counter) : 00H to 0EH* (0 to 14) *See below
*: Note that when the above function is used with zero-interrupt masking, the first interrupt
generation interval after the start of the count will be one count shorter than normal.
Fig. 2.4.22 Example: Constant Interval Setting Using Zero-Detect Interrupts
This is because zero-detect control immediately following timer startup require that both the zero-
detect pin control and zero-detect mask counter be reduced by 1 at startup before the 14-bit timer
count begins. In the above example, the first interrupt is generated after two counts, and the second
and all subsequent interrupts at intervals of 3 counts.
For this reason, users needing to time the interval function immediately after the start of the timer
count must reset the zero-detect mask counter immediately after the timer count begins. To to this,
use the following procedure.
(1) Initialize all registers, setting the zero-detect mask counter for the desired interval.
(2) Start the timer.
(3) Rewrite the zero-detect mask counter, to a value that is one less than the value entered in step (1).
Because step (3) is performed while the timer count is in progress, the value must be written to the
buffer, and the register will be updated at the next reload cycle. Because the new value will be used
in the next zero-detect masking operation after startup, the effect will be that the interval is the same
as the first interval after startup.
Example: Up-Count Mode, Zero-Detect Mask Counter Set for 2 Cycles
Timer value
Zero-detect
4-bit counter value
TZIR set
Start
Same length for all
2
1
0
2
1-count shorter
subsequent intervals