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

Timer1 and milliseconds
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







PostPosted: Thu Sep 08, 2005 9:57 am     Reply with quote

Anonymous wrote:
Yes Mark, so the manual about setup_timer2 is wrong.

setup_timer_2 ( T2_DIV_BY_4, 0xc0, 2);

// At 20mhz, the timer will increment every 800ns,

// will overflow every 153.6us,

// and will interrupt every 307.2us.

I'm not suprised. This was wrong for a couple of years in the 'wizard', so the two parts were probably written by the same person. :-)
It cause me problems ages ago, when I was trying to set up a PWM on an accurate rate. Then reading the data sheet entry made it clear that you needed 'count-1', and in recent years the wizard has been updated, but the manual still has the old values.

Best Wishes
Guest








PostPosted: Thu Sep 08, 2005 12:15 pm     Reply with quote

Im firing the counter pressing a button connected to rb0. I have a handler for #Int_ext. I agree that it generate delay, but the real problem is that with short measurement (1 to 10 seconds my program is always slower (about 1/300 seg) than chronometer and if I wait the measurement for a long time it tends to become stabilized.

I just need fire an event from an external event and count each millisecond in order to know the elapsed time between each event but this time must be precise.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 08, 2005 12:49 pm     Reply with quote

Ttelmah wrote:
Anonymous wrote:
Yes Mark, so the manual about setup_timer2 is wrong.

setup_timer_2 ( T2_DIV_BY_4, 0xc0, 2);

// At 20mhz, the timer will increment every 800ns,

// will overflow every 153.6us,

// and will interrupt every 307.2us.

I'm not suprised. This was wrong for a couple of years in the 'wizard', so the two parts were probably written by the same person. :-)
It cause me problems ages ago, when I was trying to set up a PWM on an accurate rate. Then reading the data sheet entry made it clear that you needed 'count-1', and in recent years the wizard has been updated, but the manual still has the old values.

Best Wishes


That's where I got it from Mad I read the datasheet and it clearly spells it out! I guess I learned another lesson again.
Ttelmah
Guest







PostPosted: Thu Sep 08, 2005 4:10 pm     Reply with quote

I suggest you post the actual counting code. Are you resetting all the counters when the edge occurs?. I'd almost suspect something simple, like using the wrong 'edge' on the interrupt, so it is detecting the button releasing, not making. The amount is more than the interrupt latency, or any sensible 'setup' time.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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