two timers

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

two timers

3,305 次查看
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
标签 (1)
0 项奖励
回复
4 回复数

600 次查看
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 项奖励
回复

600 次查看
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 项奖励
回复

600 次查看
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 项奖励
回复

600 次查看
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 项奖励
回复