Page 110 - Making PIC Microcontroller Instruments and Controllers
P. 110
ro0 fl ERs at{D coulllEl6
Consider the fact that a 0.01 second timer setting with a prescalar set to 16 would
provide us with an interrupt every 0.16 seconds and we would have 0-16 seconds to do
whatever we wanted to do between interrupts. Actually, less than 0.1 6 seconds, because
there are still the other lines of code in that program that need to be executed.
So ihere are serious limits as to what can be put in the timer counter and what can be
put in the prescalar.In additior, the intenupt fiequency is (also) affected by the accu-
racy of the processor clock oscillator.
PRESCALARS
The value of the scaling that will be applied to the timer is determined by the contents
of two bits in the intenupt confol register. These bits multiply the time betwe€n inter
rupt. b) po\ ers oi 2 a\ eiplained in the iollowing.
Prescalar For Timerl For the Watchdog Timer
00 Multiply by I 00 Multiply by 2
01 Multiply by 2 0l Multiply by 4
l0 Multiply by 4 l0 Multiply by 8
I I Multiply by 8 I I Multiply by 16
The two bits are bit 4 a-nd bit 5 of the Timerl contol reaister TICON.
The 8 bits in TICON are assigned as follows
TMR1ON Bit 0 I =Enables Timerl o=Disables timer
TMRICS Bit 1 l=Use extemal clock O=Use intemal ciock
TISYNC Bit 2 l=s).nc withintemal clockinpul O=$,ncwithextemalcl()ckinput
TIOSCEN Bit 3 l=Enable oscillator o=Shut offoscillator
TICKPSI Bit4 Counter scalat is described abow
TICKPSo Bit 5 Counter scahr is described above
Bit 6 Net Esed
---------Bi++---------+{€+rl€€d
USING TIMERT TO RUI{ A CRITICAL II{TERRUPT.DRIVEII TASK
WHILE THE MAII{ PROGNAM RUNS A FOREGROUI{D TASK
kt's use this timer in the same way we used Timero earlier and se€ what the dilTerences
between the two timers arc. To begin with, because Timerl is 16 bits wide, it can take much
longer for it to set its interupt flag. The intenupt flag was set approximately 61 times
a second by Trmero. Timerl flag can take approximately 0.524 seconds, as calculated