MOTOROLA
10-48
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
Listing - Timer Examples
Sheet 5 of 16
* Main Program Portion of Pulse Width program
*
PWTOP
LDX
#REGBAS
LDAA
#%00010000
STAA
TCTL2,x
LDAA
# $FF
STAA
IC1MOD
CLR
IC1DUN
BCLR
TFLG1,X $FB clear IC1F (if any)
BSET
TMSK1,X $04 enable IC1 interrupts
CLI
WAITL2
LDAA
IC1DUN
BEQ
WAITL2
SEI
* Display pulse width as xx,xxx mS (32,768 max)
JSR
.OUTCRL
LDD
HPW
LSRD
BCC
ARNUP2
ADDD
#1
ARNUP2
STD
HPW
LDX
#HPW
JSR
HTOD
JSR
P5DEC
LDX
#MSGMS
JSR
.OUTSTO
BRA
PWTOP
*
* END of Main Program Portion
***
* SV2IC1 - Input Capture 1 service routine
*
* Called first when a rising edge is detected and again
* when a falling edge is detected.
***
SV2IC1
LDX
#REGBAS
point at top of register block
INC
IC1MOD
$FF->0 at 1st edge; 0->1 at 2nd
BNE
NO1ST2
if not 0, this is trailing edge
* Process leading edge of pulse
LDD
TIC1,X
read time of first edge
STD
FRSTE
save till next capture
* Reconfigure IC1 for trailing falling edge
BCLR
TCTL2,X $30 EDG1B:EDG1A->0:0
BSET
TCTL2,X $20 EDG1B:EDG1A->1:0
BRA
OU2IC1
done processing first edge
* Process trailing edge of pulse
NO1ST2
LDD
TIC1,X
get time of trailing edge
SUBD
FRSTE
time of last minus time of 1st
STD
HPW
update result
BCLR
TCTL2,X $30 disable IC1
LDAA
#1
STAA
IC1DUN
signal pulse measured
OU2IC1
BCLR
TFLG1,X $FB clear IC1F
RTI
**Return from IC1 service**
*****END Ex 10-2
c09c ce 10 00
c09f 86 10
c0a1 a7 21
c0a3 86 ff
c0a5 b7 d0 06
c0a8 7f d0 05
c0ab 1d 23 fb
c0ae 1c 22 04
c0b1 0e
c0b2 b6 d0 05
c0b5 27 fb
c0b7 0f
[3]
[2]
[4]
[2]
[4]
[6]
[7]
[7]
[2]
[4]
[3]
[2]
Point to register block
Top of Main for PW24 prog
EDG1B:EDG1A=0:l IC1 rising edge
FF-IC1 off; 0-lst; 1-last edge
Signal pulse not done
Enable Interrupts
Sets after pulse done
Loop till pulse has been timed
Pulse done, disable interrupts
c0b8 bd ff c4
c0bb fc d0 15
c0be 04
c0bf 24 03
c0c1 c3 00 01
c0c4 fd d0 15
c0c7 ce d0 15
c0ca bd c3 33
c0cd bd c2 df
c0d0 ce c3 f6
c0d3 bd ff ca
c0d6 20 c4
[6]
[5]
[3]
[3]
[4]
[5]
[3]
[6]
[6]
[3]
[6]
[3]
Begin printing result
number of cyc (0.5
μ
S/cyc)
16-bit +2 to change to
μ
S
need to round result
yes; round up
Update hex Pulse width
Point at hex Pulse width
Convert to 5 digit decimal
Print 5 digit decimal
Point at rest of display line
Print “ milliseconds”
Goto top of main & repeat
c0d8 ce 10 00
c0db 7c d0 06
c0de 26 0d
[3]
[6]
[3]
c0e0 ec 10
c0e2 fd d0 0d
[5]
[5]
c0e5 1d 21 30
c0e8 1c 21 20
c0eb 20 10
[7]
[7]
[3]
c0ed ec 10
c0ef b3 d0 0d
c0f2 fd d0 15
c0f5 1d 21 30
c0f8 86 01
c0fa b7 d0 05
c0fd 1d 23 fb
c100 3b
[5]
[6]
[5]
[7]
[2]
[4]
[7]
[12]