|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Nesting Interrupts - is it possible?
Can the PIC nest low interrupts? I.e. can I re-enable interrupts while in an interrupt handler and have the chip do the right thing?
I actually have a good reason for doing this, but I suspect the chip can't handle re-entrant code. Thanks In Advance for your wisdom. |
|
#2
|
||||
|
||||
|
Re: Nesting Interrupts - is it possible?
Quote:
|
|
#3
|
||||
|
||||
|
Also something to keep in mind. The less stuff you have on the stack the more efficient the code will be. So recursion is out of the question.
|
|
#4
|
|||
|
|||
|
Re: Nesting Interrupts - is it possible?
Quote:
So, to conclude, to enable interrupts, within the low priority handler, I simply write a 1 to the global interrupt enable flag? |
|
#5
|
||||
|
||||
|
Re: Nesting Interrupts - is it possible?
Quote:
|
|
#6
|
|||
|
|||
|
Re: Nesting Interrupts - is it possible?
Quote:
|
|
#7
|
|||
|
|||
|
Re: Nesting Interrupts - is it possible?
There are high and low priority interrupts. We are to only use low priority interrupts.
High priority interrupts can interupt low priority interrupts (call it nesting if you would like). BUT low priority interrupts can not interrupt other low priority interrupts. In you are servicing a low priority interrupt and do not clear the interrupt flag for another interrupt then as soon as you exit the interrupt service routine then another interrupt will occur - no nesting. I discussed this with Dave at IFI while writing Interrupts for Dummies. The C Compiler Usrs guide can get you a bit confused. |
|
#8
|
||||
|
||||
|
Re: Nesting Interrupts - is it possible?
what could your code be doing with an interrupt coming along that is SO imporant it cant wait a few microseconds for the current interrupt to finish?
in general its not a good idea, because it adds overhead to the tasks being performed, you have to save your context registers and then switch to the new interrupt, then switch back, then finish the one that was running from a throughput perspective is best not to interrupt someone who just interrruped someone - your code will run like mud. |
|
#9
|
|||
|
|||
|
Re: Nesting Interrupts - is it possible?
Quote:
Anyway, it is good to finally understand that one cannot nest interrupts within a prioprity level. In practice two levels and being able to assign individual sources to either level is probably more control than most folks need. As it turned out, in the code in our teams robot used only two interrupt sources: the change of portB for quadrature encoders and timer2 (or one or zero, I don't remember) for a 1khz system clock. The timer code just incremented a global and the quadrature code just did it's quadrature thing. Everything else was driven off the timer global which incremented once every millisecond. Cheers! |
|
#10
|
||||
|
||||
|
Re: Nesting Interrupts - is it possible?
We use several interrupts in our code, and it really isn't a problem. Even if the millisecond timer fires during the handling of another interrupt, the function will finish before the timer fires again, so the timer stays on schedule.
|
|
#11
|
||||
|
||||
|
Re: Nesting Interrupts - is it possible?
in this pic chip when an interupt occurs a flag is set for that interrupt - so even if a higher priority interrupt is being processed at the time
and the source of the second interrupt goes away it will not be lost, the flag will remain set until that interrupt is serviced. Its very rare that you need to allow interrupts to be interrupted SW should be designed as if all these things will be polled - if you dont have time to poll the conditions, you dont have time to service interrupts either and if you dont know how often all your different interrupts can happen, your code is likely to be buggy and unpredicable. Design your system (SW) as if you dont have interrupts, and then use the interrupts as a convience only. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EDU Demo Code: Encoder Interfacing Using Interrupts | Kevin Watson | Programming | 4 | 08-01-2004 23:14 |
| Interrupts Questions | mightywombat | Programming | 0 | 03-01-2004 14:50 |
| Problem with interrupts on the PIC | Mike Betts | Programming | 7 | 16-12-2003 21:26 |
| Interrupts on the EDU-RC? | Andrew | Programming | 3 | 13-11-2003 23:16 |
| New Controller Specs Posted | Jnadke | Programming | 58 | 05-10-2003 08:18 |