M68HC11
REFERENCE MANUAL
MAIN TIMER AND REAL-TIME INTERRUPT
MOTOROLA
10-49
Listing - Timer Examples
* TIMER EXAMPLE 10-3 Measuring Long Periods with IC
*
* Uses interrupts.
* Measures period between two rising edges at the IC1 pin.
* Overflows are counted so max is 16,777,215 cyc (
≈
8.38 Sec)
* min time measurable with this program is about 70 cyc
*
* This program runs on an EVB board and displays results
* on the EVB terminal display.
***
Sheet 6 of 16
* Initialization Portion
*
P24INZ
LDS
LDAA
STAA
STAA
LDX
STX
LDX
STX
c101 8e 00 47
c104 86 7e
c106 97 d0
c108 97 e8
c10a ce c1 71
c10d df d1
c10f ce c1 7f
c112 df e9
[3]
[2]
[3]
[3]
[3]
[4]
[3]
[4]
# $0047
# $7E
PVTOF
PVIC1
#SV3TOF
PVTOF+1
#SV3IC1
PVIC1+1
Top of User’s stack area on EVB
Jump (extended) Opcode
TOF Pseudo Vector see manual
IC1 Pseudo Vector
Address of TOF service routine
Finish JMP inst to TOF routine
Address of IC1 service routine
Finish JMP inst to IC1 routine
* Main Program Portion of PER24 program
*
PER24T
LDX
#REGBAS
LDAA
#%00010000
STAA
TCTL2,X
LDAA
# $FF
STAA
IC1MOD
CLR
IC1DUN
BCLR
TFLG1,X $FB clear IC1F (if any)
BCLR
TFLG2,X $7F clear TOF (if any)
BSET
TMSK1,X $04 enable IC1 interrupts
BSET
TMSK2,X $80 enable TOF interrupts
CLI
c114 ce 10 00
c117 86 10
c119 a7 21
c11b 86 ff
c11d b7 d0 06
c120 7f d0 05
c123 1d 23 fb
c126 1d 25 7f
c129 1c 22 04
c12c 1c 24 80
c12f 0e
[3]
[2]
[4]
[2]
[4]
[6]
[7]
[7]
[7]
[7]
[2]
Point to register block
Top of Main for PER24 prog
EDG1B:EDG1A=0:l IC1 rising edge
FF-IC1 off; 0-1st; 1-last edge
Signal period not done
Enable Interrupts
c130 b6 d0 05
c133 27 fb
c135 0f
[4]
[3]
[2]
WAITL3
LDAA
BEQ
SEI
IC1DUN
WAITL3
Sets after period done
Loop till period has been timed
Done, disable interrupts
* Display period as x.xxxxxx Seconds (to nearest
μ
S)
LDX
#OVCNT1
LSR
O,x
ROR
1,X
ROR
2,x
BCC
ARNUP3
INC
2,X
BNE
ARNUP3
INC
1,x
BNE
ARNUP3
INC
0,X
ARNUP3
JSR
H6TOD8
JSR
.OUTCRL
c136 ce d0 07
c139 64 00
c13b 66 01
c13d 66 02
c13f 24 0a
c141 6c 02
c143 26 06
c145 6c 01
c147 26 02
c149 6c 00
c14b bd c3 6c
c14e bd ff c4
[3]
[6]
[6]
[6]
[3]
[6]
[3]
[6]
[3]
[6]
[6]
[6]
Point at hi byte of 6 digit hex
24-bit +2 to change to
μ
S
(lcyc=0.5
μ
S)
RORs include carry
need to round result
yes; round up
carry to middle byte
yes
carry to high byte
yes
Convert to 8 digit decimal
Begin printing result