Yahoo Groups archive

AVR-Chat

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

Message

Re: Counter/Timer Question

2005-06-21 by arhodes19044

I do not think it is necessary to interrupt early, then dawdle for a 
few cycles, then execute the interrupt code.  In the simpler  
method, there is a slight "phase delay" of the interrupt code 
execution, but since it executes everytime with the same delay, then 
the next time it executes will be (for instance) exactly one 
millisecond after the last time.  So, there might be a slight delay 
compared to world time, but I doubt most people (and even most 
software) would ever notice this discrepancy.  It is more important 
that the interval between executions is the exact same.

-Tony

--- In AVR-Chat@yahoogroups.com, "Roy E. Burrage" <RBurrage@b...> 
wrote:
> 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.