Page 1 of 1

Reset interrupt flag

Posted: Thu Nov 12, 2015 1:46 pm
by Jan Lichtenbelt
Why is the interrupt flag reset after the function call, instead of before the call? The earlier the flag is reset, the better repeated interrupts are prevented.

An example is given below.
AFTER:
if (ts_bit(intcon, IOCIF) && ts_bit(intcon, IOCIE))
{
FCM_A();
mxtmp=portb;
cr_bit(intcon, IOCIF);
iocbf=0;
}

BEFORE
if (ts_bit(intcon, IOCIF) && ts_bit(intcon, IOCIE))
{
cr_bit(intcon, IOCIF);
FCM_A();
mxtmp=portb;
iocbf=0;
}

With kind regards

Jan Lichtenbelt

Re: Reset interrupt flag

Posted: Thu Nov 12, 2015 4:07 pm
by Benj
Hello Jan,

Clearing the flag before the function call opens the possibility of an interrupt firing again whilst you are inside the function call which would likely cause stack corruption and other problems such as RAM corruption.

Clearing the flag after the function ensures that the code in the function has been processed correctly before we allow the interrupt to fire again.

Whilst repeated interrupts could be annoying they are generally easier to spot and deal with than stack corruption.

This is why we also recommend that any heavy processing be left outside of an interrupt macro, including things like delays etc.

Re: Reset interrupt flag

Posted: Thu Nov 12, 2015 8:36 pm
by Jan Lichtenbelt
How do I program a dead-end interrupt. Say on a high temperature the program must stop (after resetting some outputs). But jitter in the temperature may not cause additional interrupt(s). My suggestion would be to disable the interrupt in the interrupt macro. Or is there a better way?

(May be this is a Flowcode 6 subject?)

With kind regards

Jan Lichtenbelt