PIC Timer 0 as timer -- which clock speed is best?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

PIC Timer 0 as timer -- which clock speed is best?

Post by gtc »

When using Timer 0 as a timer to count elapsed seconds as a 'background' process, I guess it's sensible to run the clock at a rate that minimizes the interrupts per second and thereby minimizes interference with the 'foreground' process, but which clock speed is best?

Given that the target chip (PIC16F88) has byte-only arithmetic, I will need to count timer overflows in multiples of 255. Accuracy is not absolutely critical in this application, nonetheless I would like the elapsed time to be as accurate as possible given the available clock and prescalar options available.

Here are the Interrupts Per Second rates for the PC16F88 using either 4MHz or 8Mh clock speed:

Code: Select all

   Clock->      4Mz        8Mz

Prescalar  
1:1          3906.250    7812.500
1:2           953.125    3906.250
1:4           976.563    1953.125
1:8           488.281     976.563
1:16          244.141     488.281
1:32          122.070     244.141
1:64           61.035     122.070
1:128          30.518      61.035
1:256          15.259      30.518
Environment

Chip: PIC16F88 (byte only, no float data type)
Timer: Timer 0
Mode: INTRC as Port I/O

gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Re: PIC Timer 0 as timer -- which clock speed is best?

Post by gtc »

Anybody?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC Timer 0 as timer -- which clock speed is best?

Post by Benj »

Hello,

At 8MHz the 1:128 option seems to give you the least amount of error - 0.035

Or you could go for the 1:256 and alternate between counting up to 30 and counting to 31 to give 0.018 error.

gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Re: PIC Timer 0 as timer -- which clock speed is best?

Post by gtc »

Benj wrote:Or you could go for the 1:256 and alternate between counting up to 30 and counting to 31 to give 0.018 error.
Great idea. Thanks.

Post Reply