SN8P2200 Series
USB 1.1 Low-Speed 8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 92
Version 1.7
8.5.4 Tn TIMER CAPTURE OPERATION
Tn timer capture is using input edge trigger Tn timer count and stop. Time base is controlled by TnRATE2~0 bits. After
TnENB is set (TnENB=1), first edge input from external signal starts Tn counter. Second edge stops Tn counter and
set TnIRQ as “1”. TnC value is the result of pulse width or period. The next edge input can’t restart Tn timer when
TnIRQ = 1. TnIRQ must be cleared by firmware and Tn timer actives to catch next signal. TnRATE decides timer
capture clock rate from system clock (Fcpu). The one count period is the unit time of TnC. The product of multiplication
from TnC value multiplied by Tn unit time is result of input signal’s pulse width or period. Tn timer capture operating
sequence is as following.
Set TnRATE
Set Tn Trigger Edge
(TnG1,0)
Clear TnC and
TnIRQ
Set TnENB
Set TnIEN
Tn Mode and
Function Setting.
TnC Count
Start Edge input
Stop Edge input
TnIRQ=1.
TnC Stop.
TnC Application
Program.
Clear TnC and
TnIRQ
Before using Tn timer capture, have to know input signal information (eg. pulse width or period range) to decide Tn
time base. The time base value selection has to avoid TnC overflow (0x00>0xFF>0x00) and make sure TnC result in
8-bit range. If TnC is overflow, TnIRQ wouldn’t be set and Tn keeps counting. When stop edge trigger occurrence,
TnIRQ is set. TnC overflow occurs one time, the result is over 8-bit range, so the TnC is not correct value. Time base
selection is very important. Please refer to the table as following.
High speed mode (Fcpu = 6MHz / 1)
TnRATE TnCLOCK
Tn max interval
TnC = FFh
Tn unit time = max/256
TnC=01h
Pulse width and period
measure range.
Frequency measure
range.
000 Fcpu/256 10.923
ms
42.67 us
42.67us~10.923 ms
23.44KHz~91.55Hz
001 Fcpu/128 5.461
ms
21.33
us 21.33us~5.461
ms
46.88KHz~183.12Hz
010 Fcpu/64 2.731
ms
10.67
us 10.67us~2.731
ms
93.72KHz~366.67Hz
011 Fcpu/32 1.365
ms
5.33 us
5.33us~1.365 ms
187.62KHz~732.6Hz
100 Fcpu/16 0.683
ms
2.67 us
2.67us~0.683 ms
374.53KHz~1.46KHz
101
Fcpu/8
0.341 ms
1.33 us
1.33us~0.341 ms
751.88KHz~2.94KHz
110
Fcpu/4
0.171 ms
0.67 us
0.67us~0.171 ms
1.49MHz~5.85KHz
111
Fcpu/2
0.085 ms
0.33 us
0.33us~0.085 ms
3.03MHz~11.76KHz