Specifications

Chapter 2 - Microcontroller PIC16F84
now the inductive sensor at a distance of 5mm from the head of a screw. Inductive sensor will
generate the falling signal every time the head of the screw is parallel with sensor head. Each signal
will represent one fourth of a full turn, and the sum of all full turns will be found in TMR0 timer.
Program can easily read this data from the timer through a data bus.
The following example illustrates how to initialize timer to signal falling edges from external clock
source with a prescaler 1:4. Timer works in "polig" mode.
The same example can be realized through an interrupt in the following way:
Prescaler can be assigned either timer TMR0 or a watchdog. Watchdog is a mechanism which
microcontroller uses to defend itself against programs getting stuck. As with any other electrical
circuit, so with a microcontroller too can occur failure, or some work impairment. Unfortunately,
microcontroller also has program where problems can occur as well. When this happens,
microcontroller will stop working and will remain in that state until someone resets it. Because of this,
watchdog mechanism has been introduced. After a certain period of time, watchdog resets the
microcontroller (microcontroller in fact resets itself). Watchdog works on a simple principle: if timer
overflow occurs, microcontroller is reset, and it starts executing a program all over again. In this way,
reset will occur in case of both correct and incorrect functioning. Next step is preventing reset in case
of correct functioning, which is done by writing zero in WDT register (instruction CLRWDT) every time
it nears its overflow. Thus program will prevent a reset as long as it's executing correctly. Once it gets
stuck, zero will not be written, overflow of WDT timer and a reset will occur which will bring the
microcontroller back to correct functioning again.
http://www.mikroelektronika.co.yu/english/product/books/PICbook/2_08Poglavlje.htm (3 of 5) [4/2/2003 16:17:58]