





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!






(^6 ) 5 4
3 2
1 0
OM7^ OL^
OM6^ OL^
OM5^ OL^
OM4^ OL
valueafter reset^0
0 0
0 0
0 0
0
(^6 7) read: anytimewrite: anytime Figure 8.18 Timer control register 1 and 2 (TCTL1 & TCTL2) 5 4
3 2
1 0
OM3^ OL^
OM2^ OL^
OM1^ OL^
OM0^ OL
0 0
0 0
0 0
0 0
(a) TCTL1 registervalueafter reset(b) TCTL2 registerOMn OLn : output level^00 no action (timer disconnected from output pin)^01 toggle OCn pin^10 clear OCn pin to 0^11 set OCn pin to high
5
300 μs^700 μ
s Figure 8.19 1 KHz 30 percent duty cycle waveform
Start Select pull high as pin action Clear C0F flag Start OC0 output comparewith a delay of 700^ μs no C0F = 1?yes Select pull low as pin actionClear C0F flagStart OC0 output comparewith a delay of 300^ μs yesno C0F = 1? Figure 8.20 The program logic flow for digital waveform generation
7
delayby1ms
pshd^ movb^ #$90,TSCR
; enable TCNT & fast flags clear movb^ #$06,TSCR
; configure prescaler to 64 bset^ TIOS,OC
; enable OC ldd^ TCNT again^
addd^ #
; start an output-compare operation std^ TC^
; with 1 ms time delay
wait_lp^
brclr^ TFLG1,COF,wait_lp0 ldd^ TC0 dbne^ y,again0 puld rts ^ Example 8.
Write a function to generate a time delay which is a multiple of 1 ms. Assume that the E clock frequency is 24 MHz.The number of milliseconds is passed in Y. Solution:^
One method to create 1 ms delay is as follows: ^ Set the prescaler to TCNT to 64 ^ Perform the number of output-compare operations (given in Y) with eachoperation creating a 1-ms time delay. ^ The number to be added to the copy of TCNT is 375. (
×^64 ÷
24000000 = 1 ms)
#include^ "c:\MiniIDE\hcs12.inc"CR^ equ
LF^ equ
$0Aorg $ oc_cnt^ rmb
frequency rmb
(^2) org $1500movb^ #$90,TSCR
; enable TCNT and fast timer flags clear movb^ #$02,TSCR
; set prescale factor to 4 movb^ #$02,TIOS
; enable OC1 and IC movb^ #100,oc_cnt
; prepare to perform 100 OC1 operation, each; creates 10 ms delay and total 1 second movw^ #0,frequency
; initialize frequency count to 0 movb^ #$01,TCTL
; prepare to capture the rising edges of PT movb^ #C0F,TFLG
; clear the C0F flag bset^ TIE,IC
; enable IC0 interrupt cli^
^ Example 8.6 Use an input-capture and an output-compare functions tomeasure the frequency of the signal connected to the PT0 pin
.