Keeping ms time in PIC

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
Posts: 1
Joined: Mon Oct 27, 2014 1:21 pm

Keeping ms time in PIC

Post by LikesToSlide » Mon Oct 27, 2014 1:29 pm

I'm working on a project with the PIC16F88 where I want to keep time accurate to 1ms. I have a 20MHz crystal in HS mode and I configured TMR0 with a prescalar of 32 and a count offset of 100 to interrupt every 1ms and increment
unsigned long long system_time;

Is this the best way to go about this? An interrupt going off every 1ms seems like a lot, but at that OSC frequency the PIC should be executing about 5 million instructions per second so I think it might be ok. What do you think?

User avatar
Non-SFE Guru
Posts: 1991
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Keeping ms time in PIC

Post by phalanx » Wed Oct 29, 2014 2:54 pm

How much accuracy do you need? If you would be fine with plus or minus a couple of Hertz, there are less processor intensive ways of setting up a timer by using Timer-2 which has a period register.

Timer 2 set up with a 1:4 prescaler, 1:9 postscaler, and 139 for the period register would get you interrupts at 999.2Hz.


Post Reply