avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] interrupt optimization


From: Nigel Winterbottom
Subject: RE: [avr-gcc-list] interrupt optimization
Date: Wed, 1 Feb 2006 21:36:24 -0000

Sent: Wednesday, February 01, 2006 2:32 PM
Sender: David Bourgeois
Subject: [avr-gcc-list] interrupt optimization


> Hi,
>
> I have an interrupt which is called a lot of times but only
> really do
> something very rarely:
>
> ISR(...)
> {
>      if (sampling-- == 0)
>      {
>          sampling = 0x7F;
>          callInlineFunction();
>      }
> }


> What's the way to go in this situation?

If you can live with a small delay between (sampling==0) & execution of
InlineFunction() then move InlineFunction() to your main loop. Comme ca:

int main (void)
{
for (; ; ;)
    {
    Function1();
    Function2();
    if (sampling==0)
        {
        InlineFunction();
        sampling=0x7F;
        }
    Function3();
    _SLEEP(); //Or Whatever
    }
}


ISR(...)
{
//Decrement to zero so that the test in the main loop is never missed
if (sampling!=0)
    sampling--;
}


This tried * tested method provides a very fast ISR and the ability to
cascade many other timers (e.g. sampling1, sampling2, etc.)

Regards

Nigel Winterbotttom





reply via email to

[Prev in Thread] Current Thread [Next in Thread]