activity 3 - timer0
TRANSCRIPT
-
7/27/2019 Activity 3 - Timer0
1/3
ACTIVITYTimer0 is
external
freesupt
withano
TMR0is
notaSF
Prescaler.
event.Dr
method
ratherth
2.
3TIMER0acounter i
vents.Activi
heprocesso
ptionalpresc
SpecialFun
and thusca
The timer
ivenbythep
fmarking ti
nwastecycl
plemented
ty3configur
todomeani
aler,whichis
tionRegiste
nnotbe rea
aybe fede
rocessorclo
me,better t
esindelaylo
Figure
in theproce
esittocoun
ngfulworkr
configuredt
Figure1.(SFR)andm
ormodifie
itherby the
k,itincreme
andelay lo
ops.Thepre
2.Prescalercon
Figure3.T
ssor. Itmay
tinstruction
therthanju
odivideby2
TIMER0Simpliaybereado
by thepro
sameclock
ntsoncefor
ps,as itall
calerisconf
figurationthro
imer0blockdi
beused toc
cyclesands
stwastingcy
56beforere
fiedrmodifiedb
ram.Howe
hatdrives t
everyinstru
ws theproc
iguredthrou
ughOPTION_R
gram
ountproces
taflagwhe
cles.Timer0
chingtheTi
ytheprogra
er,writing t
eprocessor
tioncycle.T
essor towo
htheOPTIO
G
orclockcyc
itrollsove
isan8bitco
er0counte
.ThePresc
TMR0clea
orbyanex
hisisaconv
kon thepr
N_REG,see
lesor
.This
unter
.
aleris
rs the
ternal
nient
blem
igure
-
7/27/2019 Activity 3 - Timer0
2/3
Figure3showstheinternalblockdiagramofTIMER0moduleofPICmicro.Thesuppliedclockcanbethe
oscillatorprovidedoranotherexternalclock.ThiscanbechosenbyswitchingT0CS. The inputedclock
canthenbemodifiedbytheprogrammableprescalebyswitchingPSA.
Asanexample,activity3 configuresTimer0with thePrescaler foramaximumdelayonTimer0.The
prescalerwilldividetheprocessorclockby256andTimer0willdividethatby256again.Thus,Timer0
Flagwillbesetevery65536s(0.0000001second*256*256),orabout15timesasecond.Themain
programsitsinaloopwaitingfortherolloverandwhenitdoes,itincrementsthedisplayandthenloops
back.
TocalculatefortheTIMER0Periodoverflow, it istorealizethatbyusingtheclockoftheoscillatorthe
timeisdividedby4(Fosc/4).Theequationbelowsummarizesthecalculation.
4 256 0
FoscFout
prescale TMR
and1
ToutFout
#i ncl ude
__conf i g( _HS_OSC & _PWRTE_OFF & _CP_OFF & _WDT_OFF)
cbl ock 0x0CDi spl ay
endc
ORG 0
BSF STATUS, RP0MOVLW b' 00000111' ; conf i gur e Ti mer 0. Sour ced f r omt he
; Pr ocessor cl ockMOVWF OPTI ON_REG ; Maxi mum Pr escal erCLRF TRI SB ; Make PORTB al l out putCLRF Di spl ayBCF STATUS, RP0
For everLoopBTFSS I NTCON, T0I F ; wai t here unt i l Ti mer 0 r ol l s overGOTO For ever LoopBCF I NTCON, T0I F ; f l ag must be cl ear ed i n sof t war eI NCF Di spl ay, f ; i ncrement di spl ay var i abl eMOVF Di spl ay, w ; send t o t he LEDsMOVWF PORTBGOTO For ever Loop
END
Figure4.TIMER0Example
-
7/27/2019 Activity 3 - Timer0
3/3
Aswiththeexampleabove,with4MHzoscillator,aprescaleof256andhavingTMR0registertocount
from0255(256steps,settingittozero).Theoverflowfrequencyis,
415.25879
4 256 256
MHzFout Hz
TheTIMER0overflowperiodis
10.0655359 65.536
15.25879Tout ms
Hz
Notethatthe8bitTMR0registercanbewrittentoprovideavariedTIMER0timeperiodoutput. Ifan
externalclockisconnectedtoT0CKI(also,settingthepropervalueofT0CS),theFoscwillnotbedivided
by4.
PleaserefertoPIC16F84adatasheetandPICmicroMidRangeMCUFamilyReferenceManualformore
information
about
TIMER0.
Problems:Solvethefollowingproblem.Verifyyouranswersusingassemblylanguage.1. ConfiguretheprescaletogenerateaTMR0interruptthatwillincrementthecountervariablefor
eachofthefollowingperiodsexactlyassumingusinganoscillatorof4MHz.
a. 8.192msb. 1.024ms
2. Create/modifytheexampleassemblyprogramabovethatwillincrementtoexactly1second.