- Published: Saturday, 04 April 2009
- Written by Digital DIY
- Hits: 12742
TMR0 is an 8 byte timer that can be pre-scaled to change vary its incrementing cycle. Pre-scaling is important as we may want the Timer Register to increment faster/slower in different applications. The speed in which it does cycle is dependent on both the external crystal speed and the pre-scaling options.
To change the pre-scaling for TMR0, the following bits of the OPTION Register are modified:
The OPTION register contains 8 bytes of information, the other 5 are for completely different options, so when I modify settings that are shared in Byte registers with other options, I access them like above, so I don't accidentally change anything I don't want to.
To change the pre-scaler too 1:4 (increment the TMR0 register every 4th clock cycle), the following would be used:
Now to make a timer that can be used to count mS and Seconds very accurately. An easy way to find out how much time each clock cycle will take is to use a cycle calculator such as this. Make sure that the Internal Check Box is selected, now be sure that 4Mhz is the clock speed, and the pre-scaler is set to 1:2, you will see that the TMR0 period is now 512uS, so every time the TMR0 clock reaches 255, and rolls over to 0, 512uS has elapsed. Now we have a basis in which we can write our program.