TIMERS AND COUNTERS:PRE-SCALERS AND POST-SCALERS

PRE-SCALERS AND POST-SCALERS

Pre-scalers and post-scalers can be confusing for the beginner. Here is a simple explanation.

A pre-scaler is applied to the system clock and affects the timer by slowing down the system clock as it applies to the timer. Normally the timer is fed by a fourth of the basic clock frequency, which is called Fosc/4. In a system running a 4 MHz, the timer sees a clock running at 1 MHz. If the pre-scaler is set for I:8, the clock will be slowed down by another eight times, and the timer will see a clock at 125 kHz. See Figure 6.2 (for Timer1) in the data sheet to see how this applies to Timer1.

A post-scaler is applied after the timer count exceeds its maximum value, generating an overflow condition. The post-scaler setting determines how may overflows will go by before an interrupt is triggered. If the post-scaler is set for 1:16, the timer will overflow 16 times before an interrupt flag is set. The upper diagram on page 55 (for Timer2) of the data sheet shows this in its diagrammatic form and is worth studying.

All other things being equal, both scalers are used to increase the time between interrupts.

When starting out, just leave the scalers at 1:1 values and nothing will be affected. We will not need them for any of the experiments that we will be doing right away. Once you learn the more sophisticated uses of timers you can play with the values and learn more about how to use them. The primary use is in creating accurate timing intervals for communications and so on, because no external routines are necessary when this is done with scalers. Everything becomes internal to the PIC and is therefore not affected by external disturbances.

Note Additional information on timer modules is available in The PICmicro Mid-Range MCU Family Reference Book (DS33023).

Leave a comment

Your email address will not be published. Required fields are marked *