










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Rising edge
Falling edge
or
Figure 8.4 Events represented by signal edges
Physical time is often represented by the contents of the main timer.
The occurrence of an event is represented by a signal edge (rising orfalling edge).
The time when an event occurs can be recorded by latching the countof the main timer when a signal edge arrives as illustrated in Figure8.4.
The HCS12 has eight input capture channels. Each channel has a 16-bit capture register, an input pin, edge-detection logic, and interruptgeneration logic.
Input capture channels share most of the circuit with output comparefunctions. For this reason, they cannot be enabled simultaneously.
4
5
valueafte r re s e t
Figure 8 .5 Tim e r c o ntro l re giste r 3 and 4 7
(a) Tim e r c o ntro l
re gis te r 3 (TCTL3 )
(b) Tim e r c o ntro l
re gis te r 4 (TC TL4 )
ED G nB
ED G nA -- Edge c o nfiguratio n 0
0 : C apture dis able d 0
1 : C apture o n ris ing e dge s o nly 1
0 : C apture o n falling e dge s o nly 1
1 : C apture o n bo th e dge s
^
^
7
7
6
5
4
3
2
1
0
C7F
C6F
C5F
C4F
C3F
C2F
C1F
C0F
reset:
0
0
0
0
0
0
0
0
Figure 8.8 Timer interrupt flag register 1 (TFLG1)
CnF: input capture/output compare interrupt flag bits
0 = interrupt condition has not occurred1 = interrupt condition has occurred
Timer Interrupt Flag 1 Register (TFLG1)
Whenever a signal edge arrives, the associatedtimer interrupt flag will be set to 1.
^
Use the BCLR instruction with a 0 at the bit position (s)corresponding to the flag (s) to be cleared. For example, BCLR TFLG1, $FE will clear the C0F flag.
^
Use the movb instruction with a 1 at the bit position (s)corresponding to the flag (s) to be cleared. For example, movb
#$01,TFLG
will clear the C0F flag.
^
-^
Time reference: often used in conjunction with an output compare function
...^
...
0
Interrupt generation: Each input capture function can be used as anedge-sensitive interrupt source.
Event counting: count the number of signal edges arrived during aperiod
11
ΔT
T
signal S1 signal S
phase difference =
Δ T* 360T^
o
Figure 8.14 Phase difference definition for two signals
13
14
#include "c:\miniide\hcs12.inc"
org
$
edge
ds.b
2
; memory to hold the first edge
period
ds.b
2
; memory to store the period
org
$
movb
#$90,TSCR
; enable timer counter and enable fast timer flags clear
bclr
TIOS,IOS
; enable input-capture 0
movb
#$06,TSCR
; disable TCNT overflow interrupt, set prescaler to 64
movb
#$01,TCTL
; capture the rising edge of PT0 signal
movb
#$01,TFLG
; clear the C0F flag
brclr
TFLG1,C0F,*
; wait for the arrival of the first rising edge
ldd
TC
; save the first edge and clear the C0F flag
std
edge
movb
#$01,TFLG brclr
TFLG1,C0F,*
; wait for the arrival of the second edge
ldd
TC
subd
edge
; compute the period
std
period
swi end
Solution: Period Measurement
16
17
#include
"c:\miniide\hcs12.inc" org
edge
ds.b
overflow
ds.b
pulse_width ds.b
org
movw
#tov_isr,UserTimerOvf ; set up TCNT overflow interrupt vector
lds^
; set up stack pointer
movw
#0,overflow
movb
; enable TCNT and fast timer flag clear
movb
; disable TCNT interrupt, set prescaler to 32
bclr
; select IC
movb
; capture rising edge
movb
; clear C0F flag
wait
brclr
TFLG1,C0F,wait
; wait for the first rising edge
movw
TC0,edge
; save the first edge & clear the C0F flag
movb
; clear TOF flag
bset
; enable TCNT overflow interrupt
cli^
movb
; capture the falling edge on PT0 pin
wait
brclr
TFLG1,C0F,wait
; wait for the arrival of the falling edge
ldd^
subd
edge
std^
pulse_width
bcc
next
; is the second edge smaller?
ldx^
overflow
; second edge is smaller, so decrement
dex
; overflow count by 1
stx^
overflow
next
swi
tov_isr
movb
; clear TOF flag
ldx^
overflow
inx stx^
overflow
rti end