
MS51
Dec. 17, 2019
Page
212
of 316
Rev 1.01
M
S51
SE
RIES
TE
CHNICA
L REF
ERE
N
CE MA
NU
A
L
TF2
Timer 2 Interrupt
Pre-scalar
F
SYS
RCMP2H
T2DIV[2:0]
(T2MOD[6:4])
RCMP2L
TH2
TL2
00
01
10
11
CAPF0
CAPF1
CAPF2
LDEN
[1]
(T2MOD.7)
LDTS[1:0]
(T2MOD[1:0])
TR2
(T2CON.2)
Timer 2 Module
C0H
C0L
Noise
Filter
ENF0
(CAPCON2.4)
or
[00]
[01]
[10]
CAP0LS[1:0]
(CAPCON1[1:0])
CAPEN0
(CAPCON0.4)
CAPF0
Input Capture 0 Module
Input Capture 1 Module
Input Capture 2 Module
In
p
u
t
C
a
p
tu
re
F
la
g
s
C
A
P
F
[2
:0
]
CAPCR
[1]
(T2MOD.3)
CAPF0
CAPF1
CAPF2
Clear Timer 2
[1]
Once CAPCR and LDEN are both set, an input capture event only clears TH2 and TL2 without reloading RCMP2H and RCMP2L contents.
Input Capture Interrupt
CAPF0
CAPF1
CAPF2
CAP0
CAP1
CAP2
0000
0001
0010
0011
0100
0101
0110
0111
P1.5/IC7
P0.5/IC6
P0.3/IC5
P0.1/IC4
P0.0/IC3
P1.0/IC2
P1.1/IC1
P1.2/IC0
1000
P0.4/IC3
Figure 6.5-6 Timer 2 Auto-Reload Mode Block Diagram
Input Capture Module
6.5.2.2
The input capture module along with Timer 2 implements the input capture function. The input capture
module is configured through CAPCON0~2 registers. The input capture module supports 3-channel
inputs (CAP0, CAP1, and CAP2). Each input channel consists its own noise filter, which is enabled via
setting ENF0~2 (CAPCON2[6:4]). It filters input glitches smaller than four system clock cycles. Input
capture channels has their own independent edge detector but share the unique Timer 2. Each trigger
edge detector is selected individually by setting corresponding bits in CAPCON1. It supports positive
edge capture, negative edge capture, or any edge capture. Each input capture channel has to set its
own enabling bit CAPEN0~2 (CAPCON0[6:4]) before use.
While input capture channel is enabled and the selected edge trigger occurs, the content of the free
running Timer 2 counter, TH2 and TL2, will be captured, transferred, and stored into the capture
registers CnH and CnL. The edge triggering also causes CAPFn (CAPCON0.n) set by hardware. The
interrupt will also generate if the ECAP (EIE0.2) and EA bit are both set. For three input capture flags
share the same interrupt vector, user should check CAPFn to confirm which channel comes the input
capture edge. These flags should be cleared by software.
The bit CAPCR (CAPCON2.3) benefits the implement of period calculation. Setting CAPCR makes the
hardware clear Timer 2 as 0000H automatically after the value of TH2 and TL2 have been captured
after an input capture edge event occurs. It eliminates the routine software overhead of writing 16-bit
counter or an arithmetic subtraction.
Compare Mode
6.5.2.3
Timer 2 can also be configured as the compare mode by setting
CM/RL2
̅̅̅̅̅̅
. In this mode RCMP2H and
RCMP2L registers serve as the compare value registers. As Timer 2 up counting, TH2 and TL2 match
RCMP2H and RCMP2L, TF2 (T2CON.7) will be set by hardware to indicate a compare match event.
Setting CMPCR (T2MOD.2) makes the hardware to clear Timer 2 counter as 0000H automatically