View previous topic :: View next topic |
Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
PIC24EP - Disable interrupt inside interrupt or not? |
Posted: Wed May 01, 2024 6:06 am |
|
|
Good day,
Just as a general question, I know it may have been already answered many times but I'm asking again.... I have a timer 1 interrupt. When the code jumps into the interrupt, should I disable it, do whatever has to be done then re-enable before the exit?
Or I just don't need to disable and re-enable an interrupt within that interrupt as this is all taken care of?
Thanks,
Ben |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Wed May 01, 2024 6:22 am |
|
|
Well, it depends on what you want to do inside that interrupt. Normally it should be something quick, done way before the next interrupt triggers. So I'd say no, no need to disable interrupt. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Wed May 01, 2024 6:41 am |
|
|
But then let's say for argument's sake that the code inside the routine is "long", can the interrupt re-enter itself or it won't trigger until it has exit? I guess the other word is "nested" interrupt...? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed May 01, 2024 6:43 am |
|
|
pretty sure, well mostly, that the compiler will disable it, do stuff..then reenable it on exit.
need to see the listing though..... |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Wed May 01, 2024 7:54 am |
|
|
benoitstjean wrote: | But then let's say for argument's sake that the code inside the routine is "long", can the interrupt re-enter itself or it won't trigger until it has exit? I guess the other word is "nested" interrupt...? |
An interrupt cannot re-enter itself. The PIC24s have various priority levels, but they tend to all default to the same priority level as each other, so they cannot interrupt each other. And a singular interrupt is by definition the same priority level as itself.
So you only need to worry about other interrupts and only if you manually change their priority level (and turn on the "nested interrupts" feature).
So the general rule is no you don't generally need to do any disabling of an interrupt inside itself. There are some niche cases like some PIC24s need to turn off the serial transmit ISR after you are finished sending data so it doesn't fire again with an empty queue, but those are pretty rare.
However, you should not be doing long interrupts, because they cannot interrupt each other usually. So having a long interrupt stops the other ISRs from firing on time. If you have a long interrupt it is usually not the design you want to use. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Wed May 01, 2024 8:40 am |
|
|
Ok thanks.
It makes sense.
Cheers!
Ben |
|
|
|