![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
Timer1 32.768KHz and INTRC_IO |
Posted: Thu Jan 20, 2005 9:55 am |
|
|
Following along the lines of the TIMER LATENCY post by darrepac....
I have a 16F628 using the internal rc oscillator and I want to make Timer1 increment from a 32.768KHz crystal. I use the Timer1 interrupt to increment a real time clock. Since timer 1 would take 2 seconds to overflow, I set timer 1 to 0x8000 at the top of the interrupt, then I increment the time value (sec, min, hour).
What kind of latency should I expect?
The registers are being written from the internal rc of ~4MHz. Timer1 is incremented off the 32.768KHz crystal. Won't the registers be reset a lot faster than the 32.768KHz crystal can increment? My first tests show a reload of 0x8000 is too slow and looses time over a few hours. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Timer1 32.768KHz and INTRC_IO |
Posted: Thu Jan 20, 2005 10:32 am |
|
|
ljbeng wrote: | Following along the lines of the TIMER LATENCY post by darrepac....
I have a 16F628 using the internal rc oscillator and I want to make Timer1 increment from a 32.768KHz crystal. I use the Timer1 interrupt to increment a real time clock. Since timer 1 would take 2 seconds to overflow, I set timer 1 to 0x8000 at the top of the interrupt, then I increment the time value (sec, min, hour).
What kind of latency should I expect?
The registers are being written from the internal rc of ~4MHz. Timer1 is incremented off the 32.768KHz crystal. Won't the registers be reset a lot faster than the 32.768KHz crystal can increment? My first tests show a reload of 0x8000 is too slow and looses time over a few hours. |
It doesn't matter about the speed of the Timer1 clock. The fact is that you are losing 20 or more uS every second. If it were me, I would use the CCP module. Let Timer1 run free. Setup the CCP for compare mode. Start with the CCP register being set to 0x8000. In the CCP interrupt, you would add 0x8000 to the CCP value. This will give you an interrupt when the timer value is 0 and 0x8000 or every second. The other advantage is that the overall time should not drift. A second increment might be a little off if other ints are occuring but would be made up on the next int so the overall system should never lose time. Anytime you set the Timer1 value, you are bound to lose or gain time. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|