Top Banner
`ri Min~ Generayon 2- ~teqAcJrvv\enfS Ihpuf o p Pure 4oth It 0 . Odfpuf cornfore 'to 'V\ C~s }gyp{ or0(q The .~,~ nners ~s~en~5o K V ersa I enerafetnferrupfs jer'Od or pu rs e wCd4h rleouCe I s Cceafepcr'o4" +'"+ P ~CeKe~dfe s~v4AC waYeo w % a Ke ~ kx( ' 6le 'rd bVst ,heao urunCKtS46Sfen~ S ye t have c.a/pa pct Con"kQ1ters h°Ale-r e f v11 6 cddei 6een,1aJe boss , ~ oft ~ Me ,, s~ s few: iii fi
45

enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Sep 17, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

`ri Mi n ~ Generayon 2- ~teqAcJrvv\enf S

Ihpuf op Pure

4oth It 0

. Odfpuf corn fore 't o

'V\C~s

}gyp{ or0(q

The.~, ~ nne r s ~s~en~5 o K

V ersa

I enerafe tnferrupfs

jer'Od orpu rs e wCd4h

rleo uCe

I sC ce afe pcr' o 4" +'"+

P

~C eKe~dfes~v4AC

waYeo

w%a Ke ~ kx(' 6le

'rdb Vst

,heao urunCKt S46Sfen~S

ye t

have

c.a/p a

pct Con" kQ1ters

h°Ale- r

efv 11

6 c ddei

6een ,1aJeboss,

~ o f t ~ Me ,, s~ s few:iii fi

Page 2: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

ROM-8K BYTES

RAM-256 BYTES

COP WATCHDOG

EEPROM-512 BYTES

wI --Cr

OSCILLATOR

PULSE ACCUMULATOR

PERIODIC INTERRUPT

TIMER

Port B

SPI

PM

O OC3

OC5

IC2IC3

SCKMOSTMISO

TxD

11111111DATA DIRECTION C

PORT C

SINGLECHIP

c) C,5 loci

oc.t /cc- ,

acs/oct

oca loci

? \1/oct

1~R ° ~ Tc 3

pz

-S C

M68HC11CPU

cc' ooS 13:U3 EXPANDED« « « «

FIGUIIIE 1 .2 1Mernal block diagram of the MC68HC11A8 microcontroller (Courtesy of Motorola, Inc .)

Page 3: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

progrQ„hMa(,(e- timer O perct,~fov~S ;

This svbsyftM Sao hnoref rea' trs *kar, Tt,t otkevs

Cov4fo.Q fea i s4 tv S

7C T L

Tiv~e~. COhiro.Q re4l3~P/,,

-T C T L 1

T ttsk I

t"lo.i" }frrlt/t, ihf'errvet wwok r~9is~Pr+, f

T t{ sK 2

rAi scel(6cKeovs tiwtev I, vj t-evtrclef. mask Ire,

p A C T L

eukSe occuMvt&J-or cov fel_f re-9 is+a1

ac 1 M

R CiiaH r"as k rtti34.&t

C) C t b

ft cln'ovt (J a ~a r e% i,fej

Q(X4 Q & c3 t e)L.o

T C N T

T irhei cauhfei,. rc15 is+e1

TIC 4- TICS

Tiwte ivPvt capbtite. re-S''S4*U ', 2,3

70c1- TO C 5

Ti rntn, ov~wt compw re-6 ~sf-ers t . X. 3i 4, S'

PAC N T

p JIse o ccvww( dor cook t re.ji et

~ ~-ct,+vs ~ i s+Q~o

T F- L G- I

T F L G-~

hl a.ih 4 wtU, ih+errva t

g1113 re q

KI S C t (("c ov % +i YWOL 9 1aq rcg I's fel,, t

Page 4: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-1 Bit assignments for the Timer Control, Mask, and Flag Register

* Allo ,,ls 0 Se- -t o ?ra9rawl

OCI - o C-

c ah~Pi

s Q<6 ~ca ca9e-

LL Pin Cat) C T IC rt9is 4N

-to (4. '' i~L r4 . r~rhtK~

Gov~k

b u1r~hlot~ a bt

-tp

t1SK1

0 11 Z

4.QC" ih?u

C

uhc~loa }has t t 5 Duh

Si'u~VIs

l(At

-rkis

w ken ' S~lct~ Sc} s

~ furci„ ut

cqpC.our~-Ur

Pat I~ ~'

S ~GCt~ I~P ; A tot,

Peter SpasovMlcrocontroller Technology : The 68HC11,Fourth Edition

[' fir''=

«M~'

Ol 4 OMS0

Output Compare Specification,see Figure 11 .4

as

OMx,OLa -

TCTt .2

EDG1B0

0

0

0E001A

EDGxB,EDGXA -

TMSK1

0

0

0

OCII - OCSI ∎

ICII - IC31 .

Input capture specification .see Figure 11 .5

Output Compare Interrupt enable,see Figure 11 .4kiput capture Interrupt enable,see Figure 11 .50 ∎ Interrupt inhibit1 ∎ Interrupt enable

Output Compare Flag,see Figure 11 .4

IC1F - IC3F ∎

Input Capture Flag .see Figure 1 1 .S

Write with bit(s) set to clear corresponding flag(s) .

OC1 F - OCSF -

. .,Cf. A chIaM

o

MC aCAON

o

I

T 031'e Oct

(

0

c 1C a/1, 0C -V

SCE OcxI

EflG><8 En~xA

a c.f~

0

LaP Av'rlt0

disabd

O

(

l

vI

(

bd r'

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

Page 5: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11.1 (continued)

>;v.ab~C"WOr k-S

9r.C e t

Peter SpesovMkrocongroller Technology: The 68HCl1,Fourth Edition

TOI =

Timer Overflow enable, -,-1 RTII

Real Time Interrupt (RTII) enablePAOVI =

Pulse Accumulator Overflow Interrupt enable,see Figure 11 .9

--~ PAII -

Pulse Accumulator Interrupt enable,see Figure 11 .90 - Interrupt inhibit1 - Interrupt enable

PR1, PRO = Timer Prescale select (Time protected), V'see Figure 11 .2

TFLG2

Miscellaneous Timer Interrupt Flag Register 2B7

$1025

RESET =

TOF =

RTIF =PAOVF =PAIF =

* Write with bit(s) set to clear corresponding flag(s) .

s.&C' ih ray

t.o u~ truts all

QoQ s

TMSK2

Miscellaneous Timer Interrupt Mask Register 2 87V BO

$1024

ITOIIRTIIIPAOVI IPAIIIIIPR1IPRORESET =

0

0

0

0

0

0

10--- 0

TOF

I RTIF

I PAOVF I PAIF

0

BO

0

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

0 0

0

0 0

0

Timer Overflow Flea,see Figure 11 .2Real Time (periodic) Interrupt FlatPulse Accumulator Overflow Flab,Pulse Accumulator Input edgeFlag

Page 6: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-2 Free-Running Counter (TCNT)

Peter SpasovMicrocontroller Technology: The 68HCI1,Fourth Edition

Before

After

TCNT

TCNT

TMSK2

Divide-by-Prescale

(a) Counter System

IFFHFFI

1001 001

(b) Overflow Action

f TCNT

I1High Byte Low Byte

TFL02

C

Bit TOF sets

Copyright 02002 by Pearson Education, Inc .

Upper Saddle River, New Jersey 07438

All rights reserved .

Foctor PR 1 PRO

1 04 0 18 1 0

16 1 1

Page 7: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

C ltariK~ Timer IF I aq S

7 {~~

la bl fs ,n bo t h r~q isfelt~ TF L G l L T F r L Cr. z

0 .

Ba

T FL (rI

locic tocar ocas ocqFOcSF orb 1CaFIcac

a

0

0

0

O O o

d

B T 8o

TFL GL

4 Tof JKTIFj1'*ow PAlx

o

°

o

0

e 00

to the b ,f-to be c (ectweJ I

O.r e-

e .ICko$S +imer

ovvfuw 0`3IOF

TirAe pro tcckej 131 fS

ckOuta b~ w{ ;v I

aK~

64

wood I c ckho„

Al

-r-U

ro+~c 11p„ i 5

LDAA

STAA

TFLG,1,f -K

rl"

-. 410

re

bi4-S P R (

Rd

CL(

t 1 %

~re~cc4)

}-STimer

S cacJ~fl

.e

these bi4-s eav, vh~`~ be mad ` ~-ej c Ce

w,vs~ 6e Jo

wI ;n rtL. firS~

_ c 6CIkS

.her reset .

i~Q E b;4 ;K Ire 15je, Of I SON

-t~.eh

Z C~ cah be erode &dDe s pSuhVC .

P roVI-d ej ay- 'tine se 6;h LJ ko SC

e,4 to b e c r ; i- ~cJ.

Page 8: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

^----~

9 "I

x S»vu

Li J 1 H

Flb' 903

9"143

,,SIII'

4 x3

1N~1

e r .A ( ) X.I }.0

IA4wno'-) t!q - 9

o 1 Z„

o . 3 oot :F

bKg%c .Yp~"aa}X7lJ

U

Pas n

d a%J ~.

0

1

b%jIc s

uC

Sjdfl)'aft'.1s ,~o~ ~S~b a~

l11 3N »,

rw,1 s h s?J4/ 'b -0 ? A O/ a • a y J-

~,,s ;e -)I `

03'1T-car/ oed

r:lZ/idd

)1 %. 9121AV cl

S 8) ~ Paul Xd 7!C/b'J

1 0

'1fp'r~' as~ndMC,s p^-a1-1 11

o

nau, asn M-0

aM

ao

Page 9: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

R6

-T c N rI

0

04

v

ig

~

oE

(6

1 ~

N .,h

Free runniK

Cd VV6-ft T C N T

wken MCV is reset, •T c NT

a e r e g r avVA C,aO.n4 f W r ; {,e -t o

--,`V\ -rt-tSK2 -*(0L4

L0W

t's &(%a rese.+ -t o

tke rM is ~fA

only stskm ctoC(t cah d rive T C N T

CO-k de~crw~; c~ 6

R( e R o

O T C A/r

i s a 4- 63 ke

fe9 %s iec„

(- cat"

i'mcrtw%, v p -t o 6 5, 5 3 1-

b eloe t f Over f (oW 3

Q Ah ove, to (4) occurs tyl ti"w- TCA/T

FFFF to

A oooa .

TN1;5 CaUSed

oYeAF,O(,l f (aJ CTa F) ;

rt9,'sfpt

TFLG2

4 (oas --c, seE

PR(, PRO aAe -'iwte pro4tc+ec) 6(Fs C aptly, w•o dI'fi•cd

0 ffice wj44.j tke ors+ 4f4 clock elc(rt age. rose&)

C ouK+S

ZEYLO

Page 10: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Fro)

h 9 IdA&.a.V!

o-yd

I'M

r -Vd

J F DS 3 tai J) ~r

ot'd 1

,va

tIVoI *

iicDT I r :>.r

O

(N] i sf -os

o

z

s

9

L

`- ~ j -L L f"rn 9 r a ~n~' ° O' M }titan a

rydr }pd' wo ~! a14! aafaP tir orn}4os ano

z bd

? 1 Jz

Aa+r, 1 Pai

aAn.}c1 b' f nb"_

u o 7aRq

AO )Afl+d »)

a' 0 IV

d~~a3ldCPa drn.-r

aP° ~daP ~ dd

~P° tddQ

1

b 9

d

9

d

9v:io3 45903 t 99 3x903

1943 I')Q3

P `"10

3S,30

e

E

1N) L

js ,o

1-4 >0 =SDo

ti s

WI's , p ~AO

jr?o

I Y~O 117 o

9 L

Oo

t 9

s ;p I -.) .} b 1

}"1 ~'

an,1{'7)'0 ?Mf

!'ads

alt

Page 11: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

-TL4-t o

U Frr tke Po`lccq,ue S4 ecJ o v

O 9er for vv1 tw O

Coop4-V`e

tO

a r three O C fiQK s

10 C-urren{ TCNT vc*ive wi(I bQ co pied iKfo i4ekli

ca p+ure rep le.r

cqp+V(e f to- 3

Cs ) ft p in+Crrvpt IS r e I veS}eJ(' f r+1as k

-rv%rce Cowwoot o phll c4.

Lr l per cac01

ca r~Si1e.d le, CAP +ure

t I

7't~tr A tq din e.d i e C-a p u e

s clbfr0.ctt (4 e k QO nne.a~ovreme A + S

a

8

1.S

ce$ (Jl f

w Cqp I-ure a Ve"

Set

bib so -f. Lt*

a"

a c "e cdI a of

r

r

r

5v b+ru t 4. tke -two wteaourewteK i s

Page 12: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11.7 Input Capture Sequence

d W ktM td 9e. s

c e4ccota b y Ic PIN

TC N T -, kftkcd ~A4 0

TICX

11C'YF F 143 isSet

I F 1c x 1 ~itkvvup{

ehable- bid h $

6 C &

+ 4 t de4ec}tJ

eJ a also 9thevo&5

0.n i h}errve('

Peter SpdovMicrocontroller Technology: The 68HCI1,

Fourth Edition

ETCNT

I-LF -~

ICx Input

none

either

Counting

TCTL2

EDGxB EDGxA

Input Capture

TMSK1

Latch T

TICx

-~

Read by software

TFLG1

Flog sets whenedge detected .

low

GenerateInterrupt

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

Page 13: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

S, OPV) -f

40f lb) and 41

?I4fc/r 9 ic4 / 7 74

?V-,L y-'f1'/

3

J''"c,ls I-F

Z)/S14_L.

fo Vol '

44-01 AD

}as~~

ID )Qh 0./c ?9 919wwO]

E--/ 'P

WYO

~z i 'r .>J L 'r

If 21 ,/,4 1 N ~1 .7. /f7 -9

}asI1'r' ) ) S 9

u i s an7 ,> o 3 4?A 3

zbd / 'dd> oydo } . P" gr s 1J. _ L -

Nb ~77W*A0'

PL

PYol

/I P A*

~s,l .?/14-90) ei*4is vn r,"9 -9/) 1 N ) .L

aY,L

s~rbiapa~nfd~~ fnSW,r I13f-I g 9W

Page 14: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

t4J k aa+ c kppen.s tj kevt T C N T re 3 i 5kv 0 Jer' f lvw S Fro"

0

Tlnf,

a, 0 0

T k *- 'T'O '57

-rMSK 2-

cF F F F

-t c

-C o F" 1 i n *he

rr t a, Co Kd i 4 foM

1'F L, c

re-5 i s{er is SeC

Will Gadse i' fernvfl 6T 01' = /

1

$ (o z. S-

-t FIG 2

rC 3 r ~ i4tis ?

6 ~ e.

c ~ F ~

1

~~Fotk,c s Pe,ci 6-c

Page 15: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

pulse ask ex0. P

„ rff 6conf;~,Nt cgp+urc ov r . six$ eat.

c%ftr CAP

wait_for_riseIf flag a 1,

then risetime = capture timeelse repeat wait_forrise

Configure : capture on falling edgeClear capture flag

wait_forfallIf flag - 1,

then fall_time - capture timeelse repeat waitfor_fall

pulse-width - fall-time - risetime

There are limitations . If the pulse is too short, the second edge occurs before the soft-

ware can capture it . One way to remedy this is to use two input capture functions . One is con-

figured for a rising edge and the other is configured for a falling edge . ff the pulse is longer

than 65,536 TC NT cycles, overflow will give erroneous results. The program will have to

count how many times the timer overflow bit (bit T OF in-mtister TFLG2) has set.

We can write the pseudocode of Listing 11 .7 in assembly language (Listing 11 .8).

'Listing 11.8*Measure time between a rising and a falling edge on IC1 .

BRCLRLDDSUBDSTDBRA

TFLG1,X $04 POLLFALLTIC1,X

;read the fall timeRISETIME

;width - fall - risePULSEWIDTH store width•

;stop here for now

442

Chapter 11 : Programmable Timer Operators

RISETIME

EQUPULSEWIDTH EQU

ORG

LDAASTAALDAASTAR

'wart for rising edgePOLLRISE

$10$12

$100

#$10TCTL2,X#$04TFLG1,X

;confg. to capture rising edge

;clear flag 1C1F if set

BRCLRLDDSTDLDAA

TFLG1,X $04 POLLRISETIC1,X

;store the rise timeRISETIME#$20 ;config. to capture falling edge

STAALDAA

TCTL2,X#$04 clear flag IC1F

STAR'wait for falling edgePOLLFALL

TFLG1,X

Page 16: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Exavv P le

I

OR C, o

IC-1 OVA/

KIi e

1

Tc1 Mod

RM8

I

PEI

RM6 a

p vcoc ( ~lr cIveIAc ) nea'sUfew cn i

C

S U br'0uF

S K i fC I

Co K F1 *3 vreo irl p U f Cap ~vvC

USII ihftvvuj3fT

t iV ITCf

p 5 14 A

p rcserke ce g is 44

L a Pr A

4 4 to

; EDGl8 = 60C. 1 .4

o :l Per

ST 4A

LOA fF

TCTLJ, ,r

I ctfoPI c- t 13 vN

$ T4A

cLR

13CLR TFLG!,X,#Fe ;

65 T T 17Ski, x, .fo4 :C LlP ULR i

P I ccS . O -, KoJ J .0 Ke , 4

mode Ia~ = Ff - a Ff , O -+ , $44 i- /sot

A tl,I ,d' l! Al Fs

i cf -to wntasure kI~h pUISs

w, oIt F/7 o Jf

s,1nJ P e' w'oJ h o f c/o me

Clta"L rc fc IF re {e, K a Ile rc 1 i a f~Crrv~o/

L'hK t!c %K~err,fl/f

r C S 1o rt r ~Si~erT

Page 17: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

S'eJ1,vi c f

A71C1

4t

proLesS

EDG~~

k P roLCSS

EOCrE2

r0vA'xe R TIC l

L DY

S A(G

8 NE

.# Rb6 BAS

Ic1 HOD

Ep6E2

.

FF-~ a o.,f ors/ e dje

.

o

l

of

``

o they +his ~'s Ji

~~~oKcc) cJ~Gv~5~5km c c.cfcc)

ea ~e

ad;,, t to r y,skrl

I*f pro t

Ai,csf eJae

CaP re firstLDp

T TC

t19e - f', c!' x

. pond 54 rc i E

5 Tb

e ERLOAA

* $o

s TA A

T FLGI, 4

}vY nRT S

s e.Caj ed 8e

lodcqP ~v~ a

LDD

TZcI,Y:5e-Co .j

T"'ce - ~irs{ Ti wo

s ~eD

p ER

5T D

E

i'5 low a Iyk s °f .ewl

Q CSR

T CTL.?, X, #3O .S ~'° P coca ~

`~

S?AA

Ic1DuN

~

L04A

41

Ohe QO~S~ ~¢.0.5urc

8 c I?

T F LGl, x, AFB

cleanL

f lad IC~F

R T S

i ne+vr.

o+h 1 S R

e J3t firm

Page 18: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

,~ Ro }atk~ trlc chai,w' u; pwten l 1\avQ s e,"Sor5 t 6% 4

~evcra+e

c

pulse Sor e. very ~~L O,c p ro ~a~o~t .

t

ii c V cam

s e

e 1" 1' } ca p ire

uv~L~

1O rnea-SUre

i pee / d-ccf MpficN

tc Corcl tLe. 4'Sct ce- trgvCIec _

A u ~oM,,,o b; les

Rn};5 k,'d bra k w

s +ew

C A BS)

t ek e~~ ro fi t o de~c r w,,,,c i h .S y5,rtm SensesU

bra Ki+1

rc s5vre •fv a P?

Tr0.ve~iK

5 Qe~ d c kh& C`

cj+orh.o bile S rAea.5utej

(~

~ tk

to tk e C4 heeiS •

b~ S CKSOr 5 °1

MCVcan use tk's ~dY

Cruise co~ ,~J

Page 19: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11.8 Optoelectronic Position/Motion Detection

IK M4 M C-A&M t k e

MCU uses inpu}

Cgp4ure ltd n^ohtior

could for COh Cj Specd •

A co irtort -tye o cspeed seAsor i s ah

etyludGt diSK rrour}ed

Oh o skaf i

3' Oisli i s Iota ed be~weew

c- sld+ftd c, pdr'caJ swi 1 cti

Qy whey, eh(oJei. dis) ro1-a ks

ahe sw,+ clt otiipuh pulses

Peter SpasovMlerocontroller Technology: The 68HC11,Fourth Edition

I. . cc) tMt }S i h fra+c

(a) Encoder DiskFront Mew

(c) Schematic

(b) Slotted optical SwitchSide View

OpticalCenter Line

Phototronsistor

UQ To Mea0or .. ~0(W04j o+'

reverse C bidire-C- Kaj ) s Peed

Usc d u .JS1644-td

0 P -VCj s%o i 4ch .

e l lh ~

pt) lses r-orves PC-Ad

-t c) apte c)tS K revdh h t4

's o pulse c'9uoic . + S

rela lrcrj 3 ;4f-COy t a

speec) d c reVdLJhatl

- So we- c 4Yt CQKira

s ~ex.d a Ced ra c l~ .

ti ,Acader disk kain ttO(eo tka4

aIIdW If gh{ to pano tltradg 11

pl,ototrans ;S+cr $wifches an oKIy,

u) ketj cl I's Ic r e k }es -t o

. P o S464

such -tka.1 a disk hole ~'s

Jt'3kd bti+•re4it Iota E -trart.S.

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved.

Page 20: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

v

~ 5s~e 5

VSe t I wtef d We-f t 'Zo

,~ Z

e e~

i t~*te- bekweeK ~~ tscs 7 6 5~ 5en,

s p

C~L)

tl l se 7 re t/ekC - O46 k h !

Mcasurewte 4 o f time

be4,^Ieer poses be cowtcs

impre ci se .

-lY~~iskcc br4Ki l s~skm 1. 1

T o preveAE S k i ddi K q ; }~'S ~+e.et~.oa .

to ?reve,Kt a,t~ 0 f tke wkcels

lockin UP -

Page 21: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Rea9 Time ivx}erfv p t

;,,Jut Ck I(Jre

P11o /1t3

Per iof e F SSS

An i^PufC(& t' C

r , • S e o F 4L.

5 55

ste

v

amout

65-

I. S o,d93 x CT X ( Xq {AN '

Y f j

O GCur S

OK

e- CL C tr

5 VahL w ave

C~terc~~c~

o -+ker A li C."'onS

--.~ 5~Q bdo K

Sect °"

if

F - pulse w ~ . 44t r(C QAUrem

S-C

boo kS e-c +'o~ ~ ~ • 3 .3

p 4't3

~a r

~er~'o

iMew u ire- +1!E '; 4

Page 22: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

xi I se A cc v w~ u la4a c

1, 45

OL

SS - Oi

c o uK key -t ka E

e. J . !aell

o r nn Laoure

mode .

TzS cax app)t"c(,j o' S

O moni vorlll -r A pl° p0 Sl }iovi

Cc ,

Courli

i K q U 3c

pulse wla 14i dcPekd ;1 o V., 0~e cLkixq,

Q Mow +06 tai v'o Ivwe o f PA f (ow ;v,

w

~ loci wk e- dear

o ,r Qu j to i ( f-

0 d o iekv

-t ~rovl 4

t5e c&cCuw~ula~Y hqp OKe ~~ fut Phi (R A t)-T ke ~U

~0.~ 1o` L-

fl

,; v,

A 1

(

I, tS

dcc 'cn C&V\ 6c- dekefAivLea b

(p A C TL) Ipt ecc~

A &CCUwAvl0.Jor co,fi'0J rc_b s+e&v

S~ psCTL ~a°

DISC A CC

Pc E N) WW., \, Hn u s t b e.

t o91 C 'L

all

EDGE

bi ~s

~slQSA M

6(is~ tke c'"r-ch'Qt s

o tea'

x

p R C A (r C C o uti.1 r c3 Sl6L Cq`^ 6 e- read .6 ,t w ee 4E fl to

Page 23: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-9 Pulse Accumulator in Event Counting Mode

K(,pR C N) bit i n (p OIL)

en &6 O I kt P 6 5ds}e~

Peter SpasovMicrocontroller Technology: The 68HC11,Fourth Edition

-~ PAIInput

0PACTL

PEDGE

1

ai 1eTMSK2Q ( "}`CtvP{Y °'`"

PAOVI

IncrementCount

PACNT

Input EdgeDetection

8-Bit Counter

Overflow

GenerateInterrupt

TFLG2

ty PAOVF

TFLG2

PAIF

• •

b~}se-~Xdh

+0

k

e e TMSK2

PAII

Generate

PACTL

Interrupt1

V

PAEN - I , PAMOD - 0

,eVe t

COUVA

a ~i cu. 'an Qa y%4l cats iv\ 4 kc4ac6l

W

BvP~~~~e}c~I ,

1

~i - QM e a e 1 Scc'{ C-d . A' f i s s erg

C p oiled >S sa&+wca4)

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved.

Page 24: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Sho t t Co u v iS

T1e Pulse CLCCUY" u la4ar car, b € Setup

-t 0 prod LI

cxh CIA1-err

a.

P re se

vhum 6er d f €-dies kave beeh

e

S ;M le

. f Pfesec I - 5 L a s~,~ ckd .

~5

CO ,,,,%e lemewt o f preset - t d

p A CAI T .

aP

veKfs have bee" ale.{ecfed

~keN

rGSe ~ h v w~be r

e~

J

P A CN T k1 a tj tia` ~L ~~"'~` pu,s~ ~ F~

t~ ccwS~

OverFtow Cpv'J ~ If(,"

LOr

COvA s

c,av` be COVn~'~6~

M~Ye tea" a 5~ e~`~

-t-r aCK

~

lse

O ~,~! and -t a kee p raCK d

Atf t nVrA 6er o

w

sfu v M) la{~r 0 ver f (oW S

will

51-"b of zfty/ a 5 6 Gver,6

cav"4'r

°-"d yer la w

overt (oWS 4'cjvjrej s tke

S dtie- K(jr L60r o

Iroa j ;v',a 6~ ~5~

P

v se-

c-( i,fit ° f

ove, OOli1S r\-

P

ASS

CQVt

kdlb5rema,i%d&

Page 25: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-10 Pulse Accumulator in Gated-Time Accumulation Mode

E/64 Clock

Peter SpasovMicrocontroller Technology : The 68HCI /,Fourth Edition

PAI

Input PACTL

PWGE

1

Overflow Systemas in Fig. 11 .9

PACNT

8-Bit Counter

Input Edge DetectionSystem as in Fig . 11 .9

PACTL

PAEN = 1

PAMOD i- 1

a /1/ T ~Q N ~

K-~ P

e vex

6' 4c (oC ~' c1 c led

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

O

~~coin `

w~I

hbfi ihCy2meItaS

10h~ow

Page 26: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

LrLJ

2A4 i°a

b

roo/~Iwv 1.47

cA ~7 D ~`'vj 1J'V

AAP '~p't»faP

yn 0 J

J

/ /;r o~1 bu ~ U~/h

'~

fc*^nomIan»o

as/nc

o

sw/ ,m Jt/AS

(,pf,JTv1 t' ry4

N) V d

?7 J

asjp ~ a f ` r'

Or ^

P.;- WVA b

a_Y+ tea/f ?9

L mw

ai~~~ M°""roN

Page 27: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

a

Uv

gva

km ti , Fpw

S

a11deA 5[noc

1

14-

1

A b rv

s -

° a~' Q' ~}n Pa

fall o,tuo,:) S.1 aar,od 4nd-}no -" 1-

al' 9'D +n P - -DI .A o A

1m a5106 W M ~

IA „ „o t Aa d a-} n) -)C

S LIaP a I .- 110 MA'1 J

,VnlOM -y~nn b s a +'0"'~

o .~ Pas A -q ub2 r-' '

h („, ~J{so **-

Page 28: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

TFI(.ii to ?

Output Compkite_ JeW(~

TC N T100E

T oc f

* tvf G

To CS

4Io1E

'o ibU ~~1.t Zt1

UNUMMMM

TIFLGI

t 43

I.41 02. 1-

*

e- C&h ahM or d 1 SaJu j *fiftC

m~m~mmn~Ocf I

1

ocic acaf

sof4uj*tt cav% J c4-erwi ;rte is ovspufcompare- event- kwO CC urred 6y 'r ding

T F f ~, ( rtji.1tat

C S

octF c~citor-IF]r

s

0ac3F oc4F I OcSF

{-ka T?i Sk 4

re,~i s l

v

IOC`fOc51

3

iY ividua.9

a

6 $ ((

iKcre, ofec) ever

6 - c(oc ( ; rack Q

aekv wkiKcdfKk., PRO

(

j OCI F se 4 esker,J TUC( = TcA/ T

0C- -5F Set wke"70C5 = TCNT

oF (a~5 Cte.~vc

6~

11 4

Page 29: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-3 Output Compare Action

TOCx

Write

SpssovMicrocontroller Technology : The 68HCI1,Fourth Edition

TCNT

x=1,2,3,4,5,

P -two"t0 Wrlk.

C) 'r-cam -+hvu., nA cve 00i-PU4 comPatc

So f ~w t Jri }cp cam. V,0C rt o

s}eti (yc CX)

vi kevt -rc/Vr

To Cn

--~

OCxF ~-1a6 isSeb

sUCc 4u-pcowtip~

Written to by software

TFLG1

OCxF

Flag sets when TCNTincrements to TOCx

Counting

40k : t o w f1' fea vajxe to Tocxuse- a douh (e 6 ke ihSi

seParak i n3rucfion S ayc used2_ bjl& -the fc ~S a possi6ili

5T D Toe 5,n

10-_I-Peter

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

Page 30: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

at

d 0c ReI

mas k

Q

~^3

T W U

Tke- Saw1e

a Paced i i

-t-- NT% .f IV

. 16 - b)'L ovfpu+ Compare

€x ferKJ o o+put p fK Dc"

G) A Force compare (o, + of bi 1

con+ro2 bits

i6_ bit TCAl T

j5 vs'c

a. cla1 bit

a.K ivLftrrvpt mask 611

0

cor

o n,Fi

F'o C

IJ FO C„l

j'" c remeK+kd

in pv+ cQp4uyc

avfpvf cowlpgY

61 <<h~

fPu t

1eSmad

COMP

0Cy

re-3 i's fe r

4\

Page 31: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

(pv'-5.3

6 q < < of-#

W ke,K ee i +ker

~, TL - l6-bit TCWt

f-'~

(jr; }.mssS o

(; .e

01(-put coMpare pin isCL

V'

,0

uti of tkc co w,P" 'he~tc

Can b e used to con+re9 °L n

\A3- WkCA aloe's aK ou%pL1f co ,,neQife event

pen?

,Fo r ce C,° M pare

kea -Ike_ 16 - b i E O C. Y.t3 is}ek r

I -to tke F OC b i 1

IC-0 rt+ra jQ b i E

. F tai iS se l

®Wk0.+

i tke ro (e o ~ Orih, OLD b'fs

0 Vl,,F'j L, 0Lk

4~ns -rbaAi cu(ly, s peu wkaf aFfecb

oOPul

0

i(

oK

o vfput p c let

hctveC0niPwre event w I

ti FFcc{poeShoE ofc OchTv g91e OCn

C, I Cox OcK = a

t C ~ Ocvt = 1

Page 32: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

Q w k ew D Cx F s Q-}-s/ i t- caAA wA

FIGURE 11.4

a,h a vw l t o O CC UY d C. f ena) Oo h

-th a coK F'9urai4ah Sei~4t'k~ ; vt tie

TC.TL1 % TrSk

TFLG1

OCxF

Flag sets

TMSK1

OCxl

InterruptEnable

x = 2, 3, 4, 5

Peter SpasovMkroeontroler Technology : The 68HC11,

Fourth Edition

TCTL1

OCx Output

No OutputToggle OutputDrive Output LowDrive Output High

Generate Interrupt

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

OMx OLx

0 00 11 01 1

Page 33: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

JJkCd

o"s)

a, re,

d T k e Och

(D v(i fpuf

(S set the-

e cc r *ke

tke aCfiaKs reSV(~*VL1 frow

even f

C.o b%PA re

R n ;K f Lrru p t ,'s

oufpti

b ; E c ku ~~ ~

se :

re7vesfeJ (wkek

G. K

Crtafe a. ~'xr~ tlme delay ,

5{eps

Q . R~.ad the Current v&Qve oc I6_bit T(N ('

ca l cU (u ~-~

-f tie. %r jv e (-1xeJi-t TCIVrJ

ou~pu4 compare rei%s+ev

Xe J .;. T C N T i

o u+pot cd w j ) a re,

(tai t for the_ odfeu f C-Owi I'`tre c is 0 { ° b e

s e t

KfcrrvP 4

oifpt/+ corkpgr

v+1as k = ti

-t o

Page 34: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

r81~~~ t 618

P 'Y'10 0 a r';

,,a ,1ia c o4

('u~^, .

a 6, o }-

3

s 4 --

.,

04- ~~Sn aq un~ AO! nbv ) 9

S ,.8 a~bchMO

tnc4n°i 14 O

o7Snv~

>>~M

Y" 4- %J ,)

f!

~- 1 N 1L

n o o.4

NA o

. a` 6IMnX-3 Jo

+ IA ~,AIN

i »a1o'.)

jo u''f'PP'O

s. a s) nd

PaZ A4O.A ,'UGS

nom S .11 1

as b d w o- >

)) 3 .9

a4 v.* 1) !M -4 1

40 0"VI -.)

I ndiP o un

uo

3 ° -0) Ni °

..hag vunu

7

4pd ar,

' fls~,ic,~ C ~~ J 0

O-J 4' P LOW/ '1

0001 $

= 1Mn s

~! ~) (S

11~~''~ lAa,lf!e?O

-a

2)a p-*-?

,o„1 O} S r M • M oO

i I

0

0

Page 35: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

0 V-a ck o v t.pv4 C-O m Pa.¢ (0cxJ e.x ce p1 fO -c

QC 1 hao obe p;h a s sacsa+~a w' ~ ~ ~'

l octn3 cx.tn6 lactiolocir4oa - -- - j

4% oo c Oc I M

N17

Sb1Octloctt`oc,os`ouo4 `0003 j -[ -I- I

cphILCc~ S

t6 PA3 , PA 4

0 u

cki s co )Utecf s

S Vj Cd rMg- cZ. CV Y Ss v cccs f

LL bx

t35~T

sTAALbAA

sTA AasEr

C L I

s eK t -it 0dart- A c %n f

~E~t3A 5 i

p AC Tt_, X,00

q 1%

O C~ tA, x

.i t $

dCt0,x

T tAski, xi $ o

f

$ 100 0 0CI L)

A P11\6 O C t co rt , +'ro.R4

aA5

.

p Q i ,t } to r t3 fs 4e1`'a

nnw ke ?A -( 0 0 ~?u4

se} OCt M 3, '( 1

Chad l,e P A 3 i 4. 7

5 e,{- 0 C1 c 3i' C- (em, OCI0/i

t/d c ;~e fA3 • Y ~'`''9t,

; PA' lo

:K0. (e i h }errv ~~ {

Page 36: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

oAe Sk 4 pukS& EXc.%pke

a_KHz clock -* o •S A45 even E cock

o R G

-,~ 100

E G?

2.0000

L D1)

TCNT, X

ST O

T oCai X

esf rL6AA

STAR

1 LOAA

STA A

o Y

drive p A Cf 0C-2ki

p~A • '~• x `1 0

$o raV%

a° 4 -~ a c leaf

'x

j t j i S (~h«{ o +%U4, OCXS

~ CTL ,X 4 0

cteovt. oc ac + F 5e{

"CFLGii X

OAAt TOG4 vo" ms

-r c

1OC~, X

b

pQi1iK °cZ k~9~'

cL~ T~LG1,X 4o wLsE~~

OC2 to~JOvj fpul~c-L R

porT A, A 40

c\cow p A(

L O AA

# 40

; c. lead, OCZ

be- Pcres -TAA

TFLGI ,X

16C LK T CTL(,X X80~i S cohKec''~M~ aC~

9KA

A-A-

L p0

aoo 0

Sib

20,000 G cycle"

Page 37: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

S Q U

W GvQ. G~~Qn i~~

4 CA- +m Q ~C

*Listing 11 .3*Shows routines for generating square waves*using output OC3 .*A main application program varies frequency*by modifying 16-bit data in addresses HPERIOD .*Frequency = U(2 * HPERIOD)*User responsibility to set up vector addresses*and other initialization as required by application .

ORG $180

*Subroutine INITOC3*Initializes timer output OC3 for*square-wave output, interrupt driven .*Calling registers*

IX = register block address*Return registers

*Service routine RTOC3*Drives OC3 output for square wave by scheduling*time delay for next edge to be toggled .*The minimum permissible half-period is the number of clock*cycles in this routine plus those required to enter*and exit the routine .*Static variable (2 bytes)*Address HPERIOD = OC3 half-period time duration

*This routine executed after TOC3 == TCNT occurs

RTOC3LDX #REGBAS ;point to registers

LDD HPERIOD ;update TOC3ADDD TOC3,X

;by adding half periodSTD TOC3,X

to latest TOC3 value;to schedule the next interrupt

BCLR TFLG1,X $DF;clear flag OC3F

RTI

;return from service

*INITOC3

None, except CCR affected

PSHA ;preserve registersPSHBLDAA #$10 ;OM3:OL3=0:1STAA TCTL1,X to toggle OC3LDAA #$20 ;clear OC3F if setSTAA TFLG1,XSTAA TMSK1,X ;set OC31 to enableCLI ;interruptPULB ;restore registersPULARTS ;return

Page 38: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

T65 C.xa*kp Ie. tcvte.ro` JtO a vah+'aI fe d v I Cyc le

sa,,vA.'re wave

vsivta

001pit cowtfarc

9 9

6 I (I

see. prcgfgwt

't,Yll~10 Q$Oav a&OO

'a.~ Sooo

DJ+j c c(e

45006

I

Zoo C+

fvo.

In

+ (ow

IAJi(( JAAj aj 5

or 5 'n 5

\ITJIL. J

%ni }o IZe ,

1

FT

~'~`~a~~I a ~s k;h

51

to gera;i

cOwk ma

he3k t low

4ex b oo k

ThS k) «ITC T L 1 re~

TF I GI

See- ce~<4ls ivt +e-X+ boat

u

43 4

e-Ivj

10/

o 0, c~c(eo

041c%c V V% b i }-s

4

J e krW% .VLWc 4-o n

O C pin

c tears Pa-AS

Page 39: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

*Listing 11.4*Shows routines for handling PWM using output OC2 .'A main application program varies the duty cycle*by modifying 16-bit data in addresses OC2HI and OC2LO .*Duty cycle =100% * OC2HV(OC2HI + OC2LO)*User responsibility to set up vector addresses*and other initialization as required by application .*

ORG $180

*Subroutine INITOC2*Initializes timer outgit OC2 forPWM output. interrupt driven .*C•

alling registersIX - register block address

*Return registers•

None, except CCR affectedINITOC2

PSHA

preserve registersPSHBLDD

TCNT,X

;delay PWM generationSTD TOC2,XLDAA #$CO

;0M2.01.2=1:1 to setSTAA TCTL1,X

,,OC2 high first timeLDAA I$40

;dear OC2F if setSTAA TFLG1,XSTAA TMSK1,X

met OC21 to enableCLI

interruptPULB

restore registersPULARTS

;return

*Service routine RTOC2*Drives OC2 output for PWM by schedulingtime delay for next edge. Also reconRgures

*next edge opposite to that of current edge .*Note that routine will not work property with*duty cycles dose to 0% or 100%.*Static variables (2 bytes each)*Address OC2HI - OC2 time duration for high pulse*Address OC2LO - OC2 dyne duration for low pulse

*This routine executed after TOM - TCNT occurs

OC21-11

EQU

$0006

OC2LO

RTOC2

**

EQU

LDX

$0008

#REGBAS ;point to registers;if low part of cyclethen load OC2L0

BRCLR TCTL1,X $40 GETOC2LOLDD OC2HI ; else load OC2HIBRA NEVVTOC2

GETOC2LOLOD OC2LO

*updaN TOC2NEWTOC2

ADDD TOC2.XLDAA TCTL1,X ;invert 012 to toggleEORA i%01000000 ;next OC2 edgeSTAA TCTL1,X ;by updating control reg .BCLR TFLG1,X $BF ;clear flag OC2FRTl ;return from service

Page 40: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

W M Fuvtc fi'ah 5

OtJ4eu4- Cowead1Q fuWc{fovts owlk g(C. ;ble bu& ~or

aw M -tkov- ; s a s a f hwaAe o ven,kcaLd r c ( u irca(

-to %cvtvkA to

slva.t.Cc iQo vto oA% J p uJ M o V4 puts

M C 6 3 NC -7

k4o a. bull+ in P W Mport ti)

1 W t1 e.Lanvteb

CA vtjroQ rc9isters to select 9et+ucco svCk QA

0 cla cK s o u r CP

Q clock s caui"q . .

ea ck cG,tru1J kao Cc, scPOm~P

f! V41 C6 (L4-

reA i 5 -

a f

li

OACe +kv&e r4is}cr5 cwt_ 5Cup , tk-C ~ W M d r"+reo

-tke. ovfpv-s wtAko f - cvrAer s o c iwa44 ; n Fervev h'ot .

4QM di )PlicA1oh erayam hccds to Ck4v,e

1`e period or duo a4C(e, if- Cah curl+e +a

't e,

rcspeC h ve rcs i S rs-

hl odu1C

COuKVQ.k, peirCc J

Page 41: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

W6+ -, i - ke p&s4e.s4 s4 vat

-t- kaf (Q h

Cdwtfoxeni-

ExecJEt eKf4 tvkdipA

Pro

+Kf«'up f

fioF 4S

ire

be

3?ne.raj-ed ?

l .~ s

--s

-V O'Le iK {c rUPC I s cc-7 v;rcrj

I

G v fpv f Cc m P qrL ;K ferru p 4s w i (I (o e-

CL

a r&k t . s' c

a,

SluoJ c'c .ye ~regvtKty .

ao

o. VSO

4Kd titer

.Or

9'a 11 in 3 ed I e .

TO d e~et miKe t -ke coks~ s g vane w a ve ire_ ~ov n

+ke1*ivKe, i f taken ko Pract4

W a ve

re~vcsfedt ke ve.S v I RKI

For -Ekc ri5 i1q, cov

aK

a 4t rrv+~ I'

6 '~ t t

~--i4 0306 ,

53-5C ca deo

70 .4 S -1

Page 42: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

.. O ht; gppi~ca~ioh Fo r u 's OU('puf co,KI2ae P C -o s

sfcppcr roi-Of S QA.C Ekcc+ft'c vwwofor5 tkaf 'o+a+e f-rdrA

orm fosifia%A to At Kex{ i h skis (C-t discrefe ihkrvJ)

wtb4,vr sfq

k cad

I s

-t k f -

A s+cp Acts t o -two fraCRO4 o f a f A 360 O f

a

Tke Qlf%VAOLI =~rpper rnOfor appt(CctA1d i .S

0 t) (3k ac ;Yeo vse- 5kpte, rno'ro(S to po5i fro"

Q Sow%e,

C O lk jro I

'T3Pi cad( S4-CPS Qt~ft dlt 1 .1

3 . c,aKd 7.s -

-t k c

tke prihE

rabofs 'Se tkew, P'o,r poSi fiatiiKI

30 bM- mody X privi kcS u3e-

pge2r4, Pctd camaaC

sic pOlha

:Z---

me 4OrS -to

K /W

fa posy jnOr1

Yo 4-ct4e

kcaj kOr fzQh4 Q((1 re(a~we to tke Pgfaj

Page 43: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11-5 Four-Phase Stepper Motor

ImP)

A ~X(3~ .¢,VCQ

i s relvircd +0 Cause

Sko.R ro4o ovt (rus~ cucre.i)

DutjK~ tl,e period (A)kfA1

V%O 'r6fk oh OCCur S

skp S ; L e sPeter SpaeovMicrocontroller Technology : The 68HCI1,Fourth Edition

(a)

tke n+o+or w(*ndi1 mus4be. suppt(ed t i)I R Q 1ZouleA

Avd 0 F coveAt (kotd cufre,E)

TI

0

Schematic

Fl(b)

Step Sequenco

fA

:A 3 i

I

T3

ti

'Two sej-s o T

t

T2

r

I

1

T4

(c)

Sequence Waveforms (Forward Direction)

wihdin IS

c urrtHt throva 1)

the t j tJhi0, 5 d e4erw%int 1j ki ck

post 614 rke wAo4or s4cps 1-0 M ext

C rv s ~ c urrth 6 s)

Q The direcit'a' 0c

Q

4 a c It e lea, a 's[ p a kA 4~, a to

-tC.v1Miha) of a WitiatoSo

c a( (ea a s 4 a o p ttaQe,

0

swi F t,

t'go

t(,e . to arlve to

of a

(0-7 0

Oti_ti(VA i m14

3 ., 4/ (, 4, S/ if

K e ed

So a. SeIvencc 0 c logic

Pulses sites the Major

FIdwI Oh e post ~ch to akotht

* T lee p 64C s egventce nn.u,~

vvtus4 c-oKIiewe

s% x Skf5)

Copyright 02002 by Pearson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved .

E

rH order .

11410P we TtUO~TLevels

I t

0

0

t

2 t

0

t

0

3 0

1

1

0

4 0

t

0

t

Page 44: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

FIGURE 11 .6 Stepper Motor Drive Circuit

51hCe hj

curret4s

relUireCL to dYiv(f

s -eppe~, ,n,obr~ & MosFE -rc l1 LJik4 Opeh c c&1

ok}puk is used,

-to S-JpP(& 9 01 ses

io Tkt w ; K d ;Vkys

7prc .1u6(

infc(IsY4 f pourer

quad ¶'l os~ E T

6~ TtXm iks -

1 T Ca.h d ri 4e

' k loads C3A Swi+ 1 bui t i v ?f o edw'ovi

Peter SpasovMlcrocontroller Technology: The 68HC11,Fourth Edition

PhoaPB0

R3

R

PhasePei

Open-Groin

InvertingBuffer*

+24 V

CC CLR VOS

TPIC2406

1 IN

1 DRAIN

2 1N

2 DRAIN

3 IN

3 DRAIN

4 IN

4 DRAIN

VcLVCL

ENBL LONG GNO

Ij1

1

D1

D2

Cke4, pcte 437

t vs~ h l If. s. & (t.~

or 'Pro U(awl ~t o

c.chjw- skpp& vviofo+r

vsii ac

Copyright 02002 by Peuson Education, Inc .Upper Saddle River, New Jersey 07458

All rights reserved.

Page 45: enf Sb' 903 9"143,,S I I I ' 4x3 1N~1 er.A X.I}.0 I A4wno'-) t!q - 9 o 1 Z„ o. 3 oot:F bKg%c .Yp~"aa}X 7 lJ U Pas n r° d a%J ~. 0 1 '° b%jIc s uC Sjdfl)'aft'.1 s ,~o~ ~S~b a~ l11

~e4 Z iwte i ,~efr u F ~

U .5 ;K

6 .% S-x RA

4 555 sPtr~~

TiMe

- .> CLK 0c

c ,hb

a

(t I~kou,k 6 %(l b G o K •`

"% rcr n r

Clock to Crea..4-e ?exit i c

AsRs we use- 55S

O . .C

T (R - a t 4 Ks)

6 43

d o r ;,&I =VL; EsTh I

-I,

1{.r 0s=°

GA

or

e OF STI11t

p roc•

-,* }errne4rr

A ~ fi,~;=p Kahl R6 ~P

/fit

its

P o l l for zeros a~

(uoLIRQ14AN

ld°`a~'c' c,p~~bc~ CLKNAN

5

p, ck~wW<<d,t

ldx

Tim¢.

ST 4

c Ke.S

l o 0 0i

I,~Ferr~~

`(