UG-549
ADuCM310 Hardware Reference Manual
Rev. C | Page 158 of 192
An interrupt signal is generated each time the value of the counter reaches zero when counting down, or each time the counter value reaches the
maximum value when counting up. An IRQ can be cleared by writing 1 to the time clear interrupt register of that particular timer (TxCLRI).
In addition, Timer 0, Timer 1, and Timer 2 have a capture register (TxCAP) that is triggered by a selected IRQ source initial assertion.
When triggered, the current timer value is copied to TxCAP, and the timer continues to run. This feature can determine the assertion of
an event with increased accuracy.
GENERAL-PURPOSE TIMERS OPERATION
Free Running Mode
In free running mode, the timer is started by setting the enable bit (TxCON[4]) to 1 and the MOD bit (TxCON[3]) to 0. The timer
increments from zero scale/full scale to full scale/zero scale if counting up/down. Full scale is 2
16
− 1 or 0xFFFF in binary format. Upon
reaching full scale (or zero scale), a timeout interrupt occurs, and TxSTA[0] is set. To clear the timer interrupt, user code must write 1 to
TxCLRI[0]. If TxCON[7] is set, the timer keeps counting and reloads when the TxCLRI register is written.
Periodic Mode
In periodic mode, the initial TxLD value must be loaded before starting the timer by setting the enable bit (TxCON[4]) to 1. The timer
value either increments from the value in TxLD to full scale or decrements from the value in TxLD to zero scale, depending on the TxCON[2]
settings (count up/down). Upon reaching full scale or zero scale, the timer generates an interrupt. The TxLD is reloaded into TxVAL, and
the timer continues counting up or down. The timer must be disabled prior to changing the TxCON or TxLD register. If the TxLD register is
changed while the timer is being loaded, undefined results can occur. By default, the counter is reloaded automatically when generating
the interrupt signal. If TxCON[7] is set to 1, the counter is also reloaded when user code writes TxCLRI. This allows user changes to the
TxLD to take effect immediately and not on the next timeout.
The timer interval is calculated as follows.
If the timer is set to count down,
Interval
= (
TxLD
×
Prescaler
)/
Source Clock
For example, if TxLD = 0x100, prescaler = 4, and clock source = UCLK, the interval is 12.8 µs (where UCLK = 80 MHz).
If the timer is set to count up,
Interval
= ((
Full Scale
−
TxLD
) ×
Prescaler
)/
Source Clock
Asynchronous Clock Source
Timers are started by setting the enable bit (TxCON[4]) to 1 in the control register of the corresponding timer.
However, when the timer clock source is HFXTAL or LFOSC, some precautions must be taken:
•
The control register (TxCON) must not be written if TxSTA[6] is set. Therefore, TxSTA must be read prior to configuring the
control register (TxCON). When TxSTA[6] is cleared, the register can be modified. This ensures that synchronizing the timer control
between the processor and timer clock domains is complete. TxSTA[6] is the timer busy status bit.
•
After clearing the interrupt in TxCLRI, ensure that the register write has fully completed before returning from the interrupt handler.
Use the data synchronization barrier (DSB) instruction if necessary and check that TxSTA[7] = 0.
__asm void asmDSB()
{
nop
DSB
BX LR
}
•
The value of a counter can be read at any time by accessing its value register (TxVAL). In an asynchronous configuration, TxVAL
must always be read twice. If the two readings are different, read it a third time to obtain the correct value.
TxSTA must be read prior to writing to any timer registers after setting or clearing the enable bit. When TxSTA[7] is cleared, registers can
be modified. This ensures that the timer has completed synchronization between the processor and timer clock domains. The typical
synchronization time is two timer clock periods.
The TxCON register enables the counter, selects the mode, selects the prescaler value, and controls the event capture function.