Timers, is this good practice

2camjohn

Member
Currently my timer interrupts every 0.000512s.

But I was thinking at the end of my timer routine I could set the timer value to 6, so that it would only count 250 times before it overflows (rather than 256), giving an interrupt every 0.0005 seconds.

So, that would certainly help make my maths easier. But is it good practice? Are there any side effects I have not considered.


Any information apprecaited.
 

You don't say which timer you're using?, but it's common practice to do this. However, if you use a more modern timer, such as timer2, you can set it far more easily anyway (as you can preset it's trigger value). Don't mess with the ancient timer0, where you have to bodge round it!.
 
2camjohn said:
Cheers Nigel,

Yes I was using timer0.


I just read up on timer2 and it looks pretty snazzy. I will try that....

It's a LOT easier to use, and doesn't have the problems of timer0, if you just want an accurate timed interrupt it's far better.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…