MOTOROLA
10-46
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
Listing — Timer Examples
c027 fe d0 0f
[5]
c02a 1a 83 00 20[5]
c02e 22 03
[3]
c030 7e c0 88
[3]
c033 cc 00 20
[3]
c036 03
[41]
c037 ff d0 11
[5]
Sheet 3 of 16
LDX
CPD
BHI
JMP
LDD
FDIV
STX
PERC
#32
OKP
OUTRNG
#32
Period in cycles (16 bits)
($20) Check against min allowed
Skip if OK
Else go say it was too small
X-period; D-32
D/X -> X; r -> D
OKP
TEMP1
* (Freq*16)+1,000,000; radix left of MSB
*
* We now have frequency but it isn’t in a good displayable
* form yet. If we move the binary radix 16 places to the right
* we would have a 16-bit integer representing
* E(2**20)/(10**6) x freq] or [((1,048,576)/(1,000,000))*freq).
* By adding and subtracting binary multiples of the freq we
* will arrive at [((1,000,000)/(1,000,000))*freq] (or just frequency)
*
* 1,048,576 16-bit starting value ((2**20)freq)+(10**6)
* - 32,768 2**15
* - 16,384 2**14
* + 512 2**9
* + 64 2**6
* = 1,000,000 * freq
*
* The limitation of 33 ($21) cycles min was selected so
* (1,048,576/1,000,000)*freq would fit in 16 bits so we would
* only need 1 FDIV, Although it is pretty easy to extend the
* precision of an FDIV
*
* The partial results which are added and subtracted in this
* program may have an error of
±
LSB ea. because I truncated
* rather than rounding.
*
c03a fc d0 11
[5]
LDD
c03d 04
[3]
LSRD
c03e 04
[3]
LSRD
c03f 04
[3]
LSRD
c040 7f d0 13
[6]
CLR
c043 b7 d0 14
[4]
STAA
c046 04
[3]
LSRD
c047 04
[3]
LSRD
c048 fd d0 11
[5]
STD
c04b 8f
[3]
XGDX
c04c b3 d0 11
[6]
SUBD
c04f 8f
[3]
XGDX
c050 04
[3]
LSRD
c051 fd d0 11
[5]
STD
c054 bb d0 14
[4]
ADDA
c057 b7 d0 14
[4]
STAA
c05a 8f
[3]
XGDX
c05b b3 d0 11
[6]
SUBD
c05e f3 d0 13
[6]
ADDD
c061 fd d0 13
[5]
STD
TEMP1
(2**20)f; where f=freq+(10**6)
A=(2**9)f; D=(2**17)f
Clr upper half of hex freq loc.
FREQH is a temp = 512f
FREQH
FREQH+1
now D=(2**15)f or 32,768f
Needs to be in mem for subtract
D=(2**20)f; X=(2**15)f
1st subtraction (-32K)
Working result -> X; D=(2**15)f
A=(2**6)f; D=(2**14)f
Put in mem so you can subtract
(512+64)f
Update low half of FREQH
D=1,015,808*f; X=junk
999,424*f
1,000,000*f = frequency
Save the 16-bit binary result
TEMP1
TEMP1
TEMP1
FREQH+1
FREQH+1
TEMP1
FREQH
FREQH