 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah Guest
|
|
Posted: Thu Sep 08, 2005 9:57 am |
|
|
| 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
|
|
Posted: Thu Sep 08, 2005 12:15 pm |
|
|
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
|
|
Posted: Thu Sep 08, 2005 12:49 pm |
|
|
| 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 I read the datasheet and it clearly spells it out! I guess I learned another lesson again. |
|
 |
Ttelmah Guest
|
|
Posted: Thu Sep 08, 2005 4:10 pm |
|
|
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 |
|
 |
|
|
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
|