M68HC11
REFERENCE MANUAL
MAIN TIMER AND REAL-TIME INTERRUPT
MOTOROLA
10-27
* SV3IC1 - Input Capture 1 service routine
*
* Called at start and end of a period being measured
***
SV3IC1
LDX
#REGBAS
INC
IC1MOD
BNE
NO1ST3
c17f ce 10 00
c182 7c d0 06
c185 26 13
[3]
[6]
[3]
point at top of register block
$FF->O at 1st edge; 0->1 at 2nd
if not 0, this is second edge
* Process first edge of period
CLR
LDD
STD
BMI
LDAA
BPL
DEC
* decrement OVCNT1 to -1, TOF svc routine will inc to 0
BRA
OU3IC1
Done processing first edge
c187 7f d0 07
c18a ec 10
c18c fd d0 08
c18f 2b 27
c191 a6 25
c193 2a 23
c195 7a d0 07
[6]
[5]
[5]
[3]
[4]
[3]
[6]
OVCNT1
TIC1,X
RES1
OU3IC1
TFLG2,X
OU3IC1
OVCNT1
Zero the overflow count
Read time of first edge
Save till next capture
If IC was before any overflow
Check for TOF in MSB
If no overflow, you’re done
This TOF shouldn’t count
c198 20 1e
[3]
* Process second edge of period
NO1ST3
LDD
TIC1,X
BMI
ARNOV1
TST
TFLG2,X
BPL
ARNOV1
INC
OVCNT1
ARNOV1
SUBD
RES1
STD
RES1
BCC
RES1OK
DEC
OVCNT1
RES1OK
BCLR
TCTL2,X $30 Disable IC1
LDAA
#1
STAA
lC1DUN
OU3IC1
BCLR
TFLG1,X $FB Clear IC1F
RTI
c19a ec 10
c19c 2b 07
c19e 6d 25
c1a0 2a 03
c1a2 7c d0 07
c1a5 b3 d0 08
c1a8 fd d0 08
c1ab 24 03
c1ad 7a d0 07
c1b0 1d 21 30
c1b3 86 01
c1b5 b7 d0 05
c1b8 1d 23 fb
c1bb 3b
[5]
13]
[6]
[3]
[6]
[6]
[5]
[3]
[6]
[7]
[2]
[4]
[7]
[12]
Get time of second edge
If MSB-1, skip TOF check
Check for overflow
If no TOF, skip increment
TOF was before edge so count it
(Time of last) - (time of 1st)
Update result
Check for borrow
If borrow, fix overflow count
Signal period measured
** Return from IC1 service
Figure 10-8 Measuring Long Periods with Input Capture and TOF (Sheet 2 of 2)
10.3.6 Establishing a Relationship between Software and an Event
In common MCU applications, a software program must generate various output con-
trol signals as a result of various input signals or events. A software program monitors
the input signals and produces output signals as needed. Sometimes it is important for
the output signals to be in some strict timing relationship to an input signal. A problem,
which is called latency, arises when software requires some time to notice and re-
spond to an input event. In many MCU systems, this latency determines the worst-
case uncertainty in the ability of software to know exactly when an event occurred and
the accuracy of the timing relationship between the event and a resulting output signal.
In the MC68HC11A8, the timer system allows much more accurate control of the re-
lationship between events and resulting output signals.
The critical input signal will drive one of the input-capture pins of the MCU. When an
event (edge) occurs on this pin, the input-capture function automatically latches the
current value of the free-running timer counter. Even though software takes a variable