M68HC11
REFERENCE MANUAL
MAIN TIMER AND REAL-TIME INTERRUPT
MOTOROLA
10-19
* Ready to detect first rising edge
BRCLR
TFLG1,X $04 *Loop here until edge
c00e 1f 23 04 fc[7]
* First edge detected
LDD
STD
LDAA
STAA
c012 ec 10
c014 fd d00d
c017 86 04
c019 a7 23
[5]
[5]
[2]
[4]
TIC1,X
FRSTE
#$04
TFLG1,X
Read time of first edge
Save first capture value
Clear IC1F before next edge
* Ready to capture time of second edge
BRCLR
TFLG1,X $04 *Loop here until edge
c01b 1f 23 04 fc[7]
* Second edge detected
LDD
SUBD
STD
c01f ec 10
c021 b3 d0 0d
c024 fd d0 0f
[5]
[6]
[5]
TIC1,X
FRSTE
PERC
Read time of second edge
2nd - 1st -> D
Save result (period in cycles)
Figure 10-4 Measuring a Period with Input Capture
Figure 10-5 Timing Analysis for Example 10–1
As shown in Example 10–1(a), the CPU repeats the BRCLR instruction continuously,
waiting for the first rising edge. Since the edge is asynchronous to the program exe-
cution, where the edge will occur relative to this program is uncertain. This uncertainty
leads to a best-case and a worst-case minimum period that can be measured by this
program. The worst case arises if the edge is detected too late to be seen by the
BRCLR instruction at [1]. The best case arises when the edge is detected in time to be
seen by the BRCLR instruction at [2]. From the cycle-by-cycle description of the
BRCLR instruction, the read of the operand (TFLG1 register in this case) is shown to
occur in the third cycle of the instruction. The captured value is read during the last two
cycles of the LDD instruction at [3], and the IC1F status flag is cleared during the last
cycle of the STAA TFLG1,X instruction at [4]. Although a new capture could occur be-
tween [3] and [4], it would be cleared by the STAA at [4] and would not be recognized
by the program. The earliest place the second edge could occur and be properly han-
dled is during the cycle after the status flag clear instruction [4].
This timing analysis is based on a detailed knowledge of timer logic and instruction tim-
BEST CASE MINIMUM PERIOD (20 CYCLES)
E
IC1
PIN
BRCLR TFLG1,X $04
LDAA
#$04
LDD TIC1,X
BRCLR TFLG1,X $04
STD FRSTE
STAA
TFLG1,X
BRCLR TFLG1,X $04
[1]
[2]
[3]
[4]
[5]
WORST CASE MINIMUM PERIOD (27 CYCLES)