Page 114 - Making PIC Microcontroller Instruments and Controllers
P. 114
IO4 TIIERSAI{DCOUIITEBS
Timer2 can also control the operation of the two PWM signals that can be pro-
grammed to appear on lines C I and C2 with the HPWM command in PICBASIC PRO
they both have to have the
Since this one timer controls both lines sjmultaneously,
same PWMJ?eqxe c). Howevcr, the relative idl? ol t s ltuIsc within each of the
PWM signals during each cycle daes not haw to be the same
See
Tiner2 is also used as a baud l:atc clock timer for communications- page 54 of
the datasheet.
MAKING SURE A TIMER IS WORKII{G
If you are uncomfortable about getling a timer working, or knowing for surc that it is
working, write a very short program in which the main loop displays a variable thai is
in the intefupt routine- Ifyou see the value ofthe ladable going up. you
incrementeal
know the program is going lo, and retuming trom- ihe inlcrrupl routme
WATCHDOG TIMEB
A watchdog timer is a timer that sets an intenxpt that teiis us that lbr some reason the
program has hung up or otherwj se gone awry As such, i1 is expected that in a propcrly
w tten program, the watchdog timer will nevcr set an interupt This is accomplished
by resettrng the watchdog timer every so often in the program. The compiler inserts these
instructions automatically ifthe watchdog timeroption is selecled However, settiry the
option does not guanntee that a plogram cannot or will not hang up Software effors
and infinite loops ihat reset the timer within themselves can stiil cause hangups
The watcbdog timer is scalable. It shares its scalar t{itb Time on an exclusive basis
Either it uses the scalar or Timero uses it. They cannot both use it at the same timc. See
discussion u ler Time in ihe datasheet fbr more information
Since PICBASIC PRO assumes tlut the watth(log timer rNill be run with a l:128
prescdlat, unwante.l tratchdo! resets &uli occur when lou assiSn the prcscalar to
nn r0.lfJou chanle the tnescalar setting in OPTION-REG'lou shoukl disable the
ttatchdog timet \rhen programning. The watchdog enable/disable can be found on the
config ration screen oJ ro$ (hardware) prcsranner's sdiware
Counters
Of the three timers in the 16F877A, only Timer0 (the 8 bit timer) and Timerl (the
16 bit timer) canbe used as counters. Timer2 does nothave acounter input linepro-
videdforit. Generally speaking,this makes Timcl0 suitable for use with small counts
and rapid inten upts, and Timerl suitable for larger counts
HOW DOES A COUNTER WOBK?
The operation of a counter is sirdlar to the operation of a timer except that instead of
getting ils count from an internal clock or oscillator, the counter gets its signals from
an outside source. This means we have to do the following things to use a counter: