Page 215 - Making PIC Microcontroller Instruments and Controllers
P. 215

212   CnEAtI GACCURAIE  I  IEBVALS WllH T|[ER3! THE METhONOIE3


                     TIMER2

                     I  This is an 8 bit timer
                     I  Official name: TMR2.
                     I  Register  used: TMR2.
                     I  This timer can be wdllen to and  read fuom.
                     t  Has a register  it can be compared  to in order to generate  an mtemrpt
                     I  The special 8-bit register that is compared  to the timer can be written to-  An htenupt
                       is generated when the compadson  yields  the specified  match.
                     t  The timer can be tumed on and off.
                     I  Uses  a  prescalar,
                     I  Uses  a  postscalar.
                     a  Cannot  use an extemal clock and so carrol  be I'lsed as a counter-
                     I  Generates  a  progranmable intelrxpt.
                     !  Shares cenain  functions with the watchdog timer This is important.
                     I  This timer has  a special function that is used to drive a synchronous  pol1  for trans-
                       fe  ing dala between  the PIC and a computer



                     DEFINIIIG SOME  TERMS
                     Before we start using  the timers, let's define a lew timer-related  words and  concepts  that
                     will  help us understand  the fr.rnctions of the timers more  easily.


                     HPWM  Commands      When using the HPWM commands,  a timer must be assigned
                     to help generale  the frequencies  used by these cofimands. The timer assjgned  to this
                     function is then not available  for any other use.  In genelal,  each  timer can be used to
                     support one  function at one time and is busy to all other lunctions. (The deiaull timer
                     for IIPWM use  is Timerl, the 16-bit  timer).

                     Pr€scarar  A prescalar  is a divider function  that slows down  the rate at  which the inter-
                     rupts are  generated  by the timer  Il  a prescaler  is set to 8, the timer clock feed will  be
                     divided by eight times before if is fed to the timer count.  This slows down the rate at
                     which the intefiupts occur by eight. Presca]ars  are specilicd by setting  a fcw bits in one
                     of the registers  that control the timer. The registers  and  prescalar values are different
                     for each timer

                      Posbcalar   A postscalar  has lhe same  effect as a prescalar!  it  1oo slows down the
                     rate at  which the interrupts  occur, but instead  ofslowing down  the clock  feed, it counts
                     the overflows. If  a postscalar  is set lbr 4, the timer will  ovetflow four limes before an
                     intenupt  is generated.
                        The  prescalar  anal  postscalar  values are multiplied by one aoother  to get  the total delay
                      seen on the  lnlerrupls,

                     ,rterrupt   An intenupt is a signal  that informs the  system that something  needs  imme-
                      diate attention.  The inteffupt manifests  itselfby setting a  bit sonewhere  in the  processor-
   210   211   212   213   214   215   216   217   218   219   220