CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Keeping Time Accurate

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zer0flag
Guest







Keeping Time Accurate
PostPosted: Tue Jun 30, 2009 2:26 am     Reply with quote

Hi all!

I am using Timer3 to count operating hours of a device. Now I want that the time is as accurate as posible. My timer3 overflows every 62500 * 1.6 µs = 0.1 s. In the ideal situation I would preload the timer with -62500 every time in my ISR. But to compensate for time expired between the actual timer3 overflow and the execution of my set_timer3(...) instruction I use get_timer3() (in order to get the actual timer3 value at this point in time):

Code:
#INT_TIMER3
void OperatingTimeCounter_ISR()
{
   set_timer3(-62500 + get_timer3());
   operating_time++;
}


What do you think about this?

Best regards,
Zer0flag
Code:
Ttelmah
Guest







PostPosted: Tue Jun 30, 2009 3:21 am     Reply with quote

The problem is that when you load the timer, the prescaler is also reset. This will lead to a tiny error every time you do this. Also the maths itself takes time...
Do a search here. The best accuracy, is achieved by never setting the timer in the ISR. Instead design the code to let the timer free run. There are great examples from (I think originally Neutone), of how to use a running counter to give accurate final results, or use a timer (Timer2), that allows decimal division factors to be programmed.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 30, 2009 4:21 am     Reply with quote

Here is the link to Neutone's accurate clock: http://www.ccsinfo.com/forum/viewtopic.php?t=26177
Zer0flag
Guest







PostPosted: Tue Jun 30, 2009 5:49 am     Reply with quote

Thank you Ttelmah and ckielstra! I will read the posts.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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