The PICmicro contains a special register called a timer register. Like all the other registers in the PICmicro it is 8 bits in size, which means that it can hold values in the range 0-255. Some PICmicros have several timers, but the 16F84 only has one, which is held in register TMR0.

The timer is actually a counter in that it is able to automatically count up when triggered. It can be triggered from an external source (for example if you wanted to use a PICmicro to count pulses) or it can be triggered by the PICmicro clock, if you want to use it to keep track of time.

Because the timer is only 8 bits wide it will overflow when it is incremented past the maximum value which it can hold, i.e. when it goes from 255 back to 0. By setting up INTCON you can configure the PICmicro to generate interrupts when the timer overflows. This is a very popular way to set up a "heartbeat" for your system. By setting the timer running you can get the PICmicro to repeat an action at a particular interval.

The rate at which the timer overflows depends on how fast it is "clocked". You can select the clock source between the PICmicro internal instruction clock and an external signal. You can also control the pre-scaler which can be used to divide the internal signal by a particular power of two. This means that you can use the timer to count longer periods of time (or numbers of pulses) by setting the pre-scaler to an appropriate value.

We will do this in a lot of the practical work.

On the right you can see how the OPTION register is configured with respect to the timer. Remember that the INTCON register is used to enable timer interrupts and also lets you test for timer interrupt flags.

If you want more precise control over the frequency of interrupts caused by the timer you can write a value to the timer register at any time. This will cause it to count up from the new value. However, remember that it takes the PICmicro 2 instruction cycles to "notice" this change and so if you are after really precise timing you should write a value 2 less than the one you really want. Of course the fact that the PICmicro can be driven from a very stable crystal means that you can use these techniques to produce extremely accurate pulse timings, should you need to.