A bit different way of generating long delays with AVR

There are many ways of generating delays in AVR or any other microcontroler. One way is to use software counter like delays withing loops. This is not recommended way and should be avoided because this utilizes processor and is hardly predictable due to compiler optimizations.


But to get high precision you definitely need to use timer counter. This way you are free from compiler optimizations. Single timer can deal with rather short delays. If you need longer delays generated by hardware only, why not to put another timer to work. ATMEL app note suggests using two timers for generating long delays. The method is pretty obvious from illustration – first timer generates timer1 compare signal on dedicated pin (OC1A), This signal then ticks second timer0. Now imagine if first timer can generate maximum 10s. If timer0 is 8-bit timer, then whole configuration can give 2560s. The only drawback of this method is that first timer output has to be connected to second input. In existing boards this may be tricky, but why not think of this on new design where application is dependent on long delays.

[..Source link..]

Bookmark the permalink.

Comments are closed.