two timers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

two timers

3,171 Views
ernestsnaith
Contributor I
What is the best way to run two timers, i currently use the main timer and increment a register each time it overflows using interupts giving me a 32 bit timer that i need. However i am starting to use a lot of interupts and wish to lower the number.
 
Cheers
 
S12XDT512
Labels (1)
0 Kudos
4 Replies

466 Views
DanielM
Contributor III
You can lower the number of interrupts you get by factor of 256 if you use the PIT instead of the ECT. Have a look at AN2724 on how to create a 24-bit timer from the PIT. Then you only need to increment a byte on top of it to get a 32-bit value.

Are you using XGATE for handling these interrupts? It is much better at servicing frequent requests.

Daniel
0 Kudos

466 Views
ernestsnaith
Contributor I
Is there a way of automatically incrementing the second timer variable when the first overflows without the use of an interupt? Is this what a pulse accumulator is?
 
I dont have lots of interupts yet but my project revolves around accurate timing with few errors and i want to start off writing it well.
0 Kudos

466 Views
rhinoceroshead
Contributor I
I don't think the the pulse accumulator works that way.  It's there to count external events that happen on the pin as far as I know.  I've never actually used it though.
 
I really wouldn't worry about the overflow interrupt.  They only occur once every 65536 timer cycles, and if you scale your timer clock then there could be many CPU cycles for each timer cycle.  Even though it still could happen many times a second, it is a relatively rare event from the CPU's prespective.
 
You can still get accurate timing even if lots of interrupts happen.  The timer's interrupt priority is one of the highest and since it latches values using hardware, the time is still recorded accurately even if there is a software lag to acknowledge the interrupt.
0 Kudos

466 Views
rhinoceroshead
Contributor I
Are you only using the timer overflow interrupt?  If that's the case and you are only looking at the upper 16 bits of your '32 bit timer' then you can just add another counter variable and increment and check them both on the overflow interrupt.  That wouldn't add any more interrupts.  You could also scale back the timer clock as slow as possible if you don't need the full accuracy of 32 bits.
 
If you're using all 32 bits then you could enable that timer's specific channel only when the first 16 bits match, which would mean that there is really only the overflow interrupt firing most of the time.
 
How do you define 'a lot of interrupts'?
0 Kudos