Hardware Reference
In-Depth Information
The assembly program that implements this algorithm is as follows:
#include “c:\miniide\hcs12.inc”
org
$1000
edge1 ds.w
1
ovcnt
ds.w
1
PW
ds.w
1
org
$1500
movw
#tov_isr,UserTimerOvf; set up TCNT overflow interrupt vector
lds
#$1500
; set up stack pointer
movw
#0,ovcnt
movb
#$90,TSCR1
; enable TCNT and fast timer flag clear
movb
#$05,TSCR2
; disable TCNT interrupt, set prescaler to 32
bclr
TIOS,IOS0
; select IC0
movb
#$01,TCTL4
; capture the rising edge
movb
#$01,TFLG1
; clear the C0F flag
brclr
TFLG1,C0F,*
; wait for the first rising edge
movw
TC0,edge1
; save the first edge, clear the C0F flag
movb
#$80,TFLG2
; clear the TOF flag
bset
TSCR2,$80
; enable TCNT overflow interrupt
cli
; “
movb
#$02,TCTL4
; capture the falling edge on PT0 pin
brclr
TFLG1,C0F,*
; wait for the arrival of the falling edge
ldd
TC0
subd
edge1
std
PW
bcc
next
; is the second edge smaller?
ldx
ovcnt
; second edge is smaller, so decrement
dex
; overflow count by 1
stx
ovcnt
; “
next
swi
tov_isr
movb
#$80,TFLG2
; clear the TOF flag
ldx
ovcnt
inx
stx
ovcnt
rti
end
The C language version of this program to be compiled by the CodeWarrior C compiler is as
follows:
#include
“c:\cwHCS12\include\hcs12.h”
unsigned
diff, edge1, overflow;
unsigned
long pulse_width;
void main(void)
{
overflow 5 0;
TSCR1
5 0x90;
// enable timer and fast flag clear
TSCR2
5 0x05;
// set prescaler to 32, no timer overflow interrupt
TIOS
& 5 , IOS0;
// select input-capture 0
Search WWH ::




Custom Search