View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
Detecting when timer2 is about to overflow. |
Posted: Sat Jan 20, 2007 11:58 am |
|
|
Hi,
I want to detect when Timer2 (prescaled and post scaled) is about to overflow and generate an interrupt.
I know I can read timer2, but I donīt know how to deal with the post scaler. Is there a readable counter?
Thank you. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: Detecting when timer2 is about to overflow. |
Posted: Sat Jan 20, 2007 4:28 pm |
|
|
future wrote: | Is there a readable counter? |
Yes. You can read any timer's counter with GET_TIMERx() function. x is a number of the timer. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sat Jan 20, 2007 4:33 pm |
|
|
I thought that the postscaler would let the timer rollover N times before the interrupt flag come active.
Thank you. |
|
|
ferrumvir
Joined: 01 Feb 2006 Posts: 64 Location: England
|
|
Posted: Sun Jan 21, 2007 3:48 am |
|
|
Hi,
Sorry, I've no help, I'm watching this thread as the issue interests me.
Why do you need to know when the interupt is about to occur, can you tell us why you need to do this and maybe we can think of an alternative solution to your underlying issue.
Cheers Scott |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sun Jan 21, 2007 6:59 am |
|
|
The timer 2 is the 'software timers' base timing. When I load a new soft timer I want to know if there is an interrupt happening soon so I can add a count to it and have less jitter. |
|
|
ferrumvir
Joined: 01 Feb 2006 Posts: 64 Location: England
|
|
Posted: Sun Jan 21, 2007 8:20 am |
|
|
Hi,
I think I understand what you are after, and I think this is the answer.
The trick is to only reset the timer with the updated values, in the interupt. In order to do this you'll need to some global variables.
psuedo code...
Code: |
int reset_value;
#Int
void int()
{
do update
reset timer from reset_value
}
void main()
{
set reset_value;
}
|
I hope you see how this avoids jitter, by allowing the last interupt to complete, before resetting the timer to the new values.
Hope that helps,
Cheers Scott |
|
|
|