Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: Counter/Timer Question

2005-06-21 by Roy E. Burrage

You can also set up the prescaler and count registers for something slightly less than what you require, then waste a few cycles in the ISR to get your required time.

System clock = 1 MHz

Using a prescaler value of 32 and a count register value of 31 would give 992 timer overflows per second, or 1 overflow every 992 uSec. Then if you either waste or do something else for 7 cycles you'll have 999.

Application note AVR130 explains this pretty well.


REB


arhodes19044 wrote:
I agree that it is a major pain in the neck having powers of 2 as 
the prescaler, but NOT powers of 2 as the usual crystal freq.

In my case I needed a 1 millisecond clock.  So, I used a 16 bit 
clock for my 16MHz crystal.  (8 bits would not do).

I uses CTC mode with a prescaler of zero, and triggered the 
interrupt after 16,000 clock cycles.  (16e6/16e3 = 1e3).  This 
worked out fine.  
  

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.