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):
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
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