Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Missing interupts

2005-03-28 by Philipp Adelt

al boehnlein schrieb:
> I am working on a control application that reads
> quadrature readings from an encoder.  I seem to
> missing some counts.  I am wondering what happens to
> the interrupts when you are in the "SIGNAL(SIG_LCD)"
> ISR routine?  I assume  they are turned off, but I am
> wondering if an interrupt occurs while in the routine,
> is it saved and executed latter, upon exit?

What does your SIG_LCD do?

Where in the code you are is not that interesting, but the state of the 
global interrupt enable bit is. This is the flag you turn on and off 
using CLI and SEI instructions. To fully understand what your (C) code 
does, disassemble your compiled code or have the compiler output the 
assembler source and look at the assembler instructions generated. Then 
look up the instructions in the documentation. You will notice that 
interrupt subroutine calls (like your SIGNAL(SIG_LCD)) will end with a 
RETI instruction, that turns back on the global interrupt enable flag. 
Looking at the documenation about interrupt handling you will see that 
upon handling a non-masked interrupt, this flag is turned off before the 
SIGNAL()-routine is executed.

> The documentation is not clear to me, as to what
> happens if I get an interrupt on my quadrature sensors
> while I am in the LCD ISR.  

The interrupt is flagged (that is, the flag bit of that interrupt is 
set) but not handled, because global interrupts are disabled.
As soon as your routine ends (or a CLI is executed), the next pending 
interrupt (determined by the interrupt flag) is executed. That could 
then be your sensor inputs.

> Also, can I use cli(); and  sei(); instructions
> without fear of missing an interrupt?  I need to read
> every quadrature interrupt, although I can wait until
> another ISR finishes.

You won't miss one interrupt - but think about what happens if you get a 
second interrupt of the same type without the first being serviced. You 
will never notice you missed one.

One way to at least detect this is to hook the inputs to a counter and 
check on each interrupt invocation if the counter state matches your 
exceptations. If it doesn't there was such a condition with a second 
interrupt that was "masked" by the first.

Regards,
Philipp

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.