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 CCS Technical Support

Detecting when timer2 is about to overflow.

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



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

Detecting when timer2 is about to overflow.
PostPosted: Sat Jan 20, 2007 11:58 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Detecting when timer2 is about to overflow.
PostPosted: Sat Jan 20, 2007 4:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 20, 2007 4:33 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 21, 2007 3:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 21, 2007 6:59 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 21, 2007 8:20 am     Reply with quote

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