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

PRqTECT  2   2ll



                    we will  use each  of the tbree timers  (we do not have the ability to use the watchdog
                  timer) in the PIC 16F877A to create instruments that provide us with  accurate  pre-
                  dictable timed intervals  we can select with a  potentiometer.  Two ofthe thee timers can
                  also be used as counters, and that will  be unde(aken in ihe next chaptel where we
                  count marbles in some of the many different ways available to us. CounteN  are essen-
                  tially timers  that get  their count pulse  liom  an external  source.
                    On the mehonomes  created,  (he  counts  per minute will  be controlled by a poten-
                  tiometer, they will be displayed on the display, and they will bo annunciated  on a speaker
                  (or  LED). Since both the tachometer  hardware and the LAB-XI  hardware rvill have these
                  accessodes on them, either one  can be programmed  for the  purpose  we have in mind.
                  Though the output needed ftom  a metronome is rather limited  (40 to 208 ticks per
                  minute is the standard), our project will  be able to provide any count dosired,  from a
                  count every few seconds  to a few thousand counts  per second,  Al1 we will  need  to do
                  is change a few lines of code ifl the software. That,  in a  nutshell, is the  power of instru-
                  ments that  you yourself make.
                    The three timers in the  PIC 16F8?7A have the folowing  salient  features, and the char-
                  acteristics of the timers  in most other PlCs are similar. Onco  you get confortable with
                  the thr€e timers in this PIC, you should  have no difliculty  with any timer in any PIC.
                  The hard  part will  be getting familiar with the new datasheet for the PIC you select.


                  IIIUERO
                  t  This  is  an 8-bit  timer
                  :  Official  nameTMR0.
                  I  Register used  TMRo.
                  t  This register can  be written to and rcad ftom at will.
                  a  Rur.J all the time, cantot be stopped or started.
                  I  Uses a  prescalar,
                  I  Does not use a  postscalar.
                  I  Can run from an irtemal  clock  (at  Fosc/ ).
                  I  Can be used with an extemal sigral for counting.
                  I  Generates a  progranmable intenupt on overflow from 255 to 0.


                  TtiitERt
                  t  This is a 16'bit timer
                  I  Official name: TMRI.
                  I  Registers used: TMR1H and  TMR1L for the high and low bytes of the l6-bit  word.
                  I  The  two r€gisteN mentioned in the  previous  bullet  point  can be  \tritten to and Iead ftom.
                  I  The timer can be tumed on and off.
                  I  Uses  a  prescalar.
                  I  Do€s not use a postscalar,
                  I  Can  run from an intemal clock (at Fosc/4).
                   I  Can also run from an extemal clock for timing drd counting.
                   I  Generates a programmable  interrupt.
   209   210   211   212   213   214   215   216   217   218   219