A PIC Microcontroller can have one of two types of 8-bit timer 2/4/6/8.
The first type is the one that most will likely to be be familar with. This timer can have only one possible clock source and that is the System Clock/4 or FOSC/4. The second type is much more flexible and can have many different clock sources and supports more prescale values.
The timer type for a PIC microcontroller can be determined by checking for the existance of a T2CLKCON register, either in the Datasheet or in the Great Cow Basic "dat file" for the respective device.
If the microcontroller DOES NOT have a T2CLKCON register then ALL Timer 2/4/6/8 timers on that chip are the first type, and and are configured using:
InitTimer2 (PreScale, PostScale)
If the microcontroller DOES have a T2CLKCON register then ALL Timer 2/4/6/8 timers on that chip are the second type and are configured using:
InitTimer2 (Source,PreScale,PostScale)
The possible source, prescale and postscale constants for each type are shown in the Great Cow Basic Help file.
The "Period" of these timers is determined by the system clock speed, the prescale value and 8-bit value in the respective timer period register. The timer period registers are PR2,PR4,PR6 or PR8.
When the timer is enabled/started it will increment unitil the TMRx register "matches" the value in the PRx register. At this time the TMRx register is cleared to 0 and the timer continues to increment until the next match, and so on. The lower the value of the PRx register, the shorter the timer period will be. The default value for the PRX register at power up is 255.
The timer interrupt flag (TMRxIF) is set based upon the number of match conditions as determine by the postscaler. The postscaler does not actually change the timer period, it changes the time between interrupt conditions.
Hope this helps.
Last edit: William Roth 2017-06-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using Timers 2/4/6/8 on PIC microcontrollers.
A PIC Microcontroller can have one of two types of 8-bit timer 2/4/6/8.
The first type is the one that most will likely to be be familar with. This timer can have only one possible clock source and that is the System Clock/4 or FOSC/4. The second type is much more flexible and can have many different clock sources and supports more prescale values.
The timer type for a PIC microcontroller can be determined by checking for the existance of a T2CLKCON register, either in the Datasheet or in the Great Cow Basic "dat file" for the respective device.
If the microcontroller DOES NOT have a T2CLKCON register then ALL Timer 2/4/6/8 timers on that chip are the first type, and and are configured using:
If the microcontroller DOES have a T2CLKCON register then ALL Timer 2/4/6/8 timers on that chip are the second type and are configured using:
The possible source, prescale and postscale constants for each type are shown in the Great Cow Basic Help file.
The "Period" of these timers is determined by the system clock speed, the prescale value and 8-bit value in the respective timer period register. The timer period registers are PR2,PR4,PR6 or PR8.
When the timer is enabled/started it will increment unitil the TMRx register "matches" the value in the PRx register. At this time the TMRx register is cleared to 0 and the timer continues to increment until the next match, and so on. The lower the value of the PRx register, the shorter the timer period will be. The default value for the PRX register at power up is 255.
The timer interrupt flag (TMRxIF) is set based upon the number of match conditions as determine by the postscaler. The postscaler does not actually change the timer period, it changes the time between interrupt conditions.
Hope this helps.
Last edit: William Roth 2017-06-03
Very clear information - great job!!!