Yahoo Groups archive

AVR-Chat

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

Message

RE: [AVR-Chat] Re: documentation of timer interrupts vs bugs

2005-04-22 by Chuck Hackett

> From: Dave Hylands
> 
> ....
> However, the interrupt flag register is special.
> ....
> This is because setting the bits in the flag register happens in
> hardware. There's NO way to atomically do any bit manipulations on
> this particular register.
> 
> All the software can do is clear the bits (which clears the interrupt).
> 
> For example, let's say that you do the following (and writing a zero
> cleared an interrupt)
> 
> TIFR |= ( 1 << TOV1 ), which generates some assembly like this:
> 
> in      r24, 0x38
> ori     r24, 0x04
> out     0x38, r24
> 
> Now lets suppose that a TOV2 interrupt occurs after the "in"
> instruction. Whether interrupts are enabled or not, the TOV2 flag will
> get set. However the out instruction would write a zero into TOV2
> which would clear it. Now you've lost a TOV2 interrupt.
> 
> By making it so that the software can only clear interrupts by writing
> a 1, and using
> 
> TIFR = ( 1 << TOV1 );
> 
> you don't disturb any other flag bits.

Hi Dave,

Thanks much for the explanation.  I've always wondered why one writes a "1" to
"clear" and interrupt, your description made it clear (ouch, two puns in one
sentence <vbg>) for the first time.

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

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.