Go to Post You know you've overdosed on FIRST when you hear people yell "CHARGE" and you get confused and lost when you look and see baseball and not robots - thatphotochick [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-01-2004, 02:00
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
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   Spotlight this post!  
Unread 12-01-2004, 17:06
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Nesting Interrupts - is it possible?

Quote:
Originally Posted by Larry Barello
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.
Yes, with low-priority interrupts it can. If you don't know what a low priority interrupt is, then jsut take my word and know it will work. Just don't try too many interrupts inside interrupts, as these are added to the stack, which will eventually overflow if you do.
__________________
1139 Alumni
  #3   Spotlight this post!  
Unread 12-01-2004, 17:40
m0rph3us's Avatar
m0rph3us m0rph3us is offline
Registered User
AKA: Andre
#0293 (Spike)
Team Role: Programmer
 
Join Date: Feb 2003
Location: Hopewell, NJ
Posts: 32
m0rph3us will become famous soon enough
Send a message via ICQ to m0rph3us Send a message via AIM to m0rph3us Send a message via MSN to m0rph3us Send a message via Yahoo to m0rph3us
Lightbulb Re: Nesting Interrupts - is it possible?

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.
__________________
Andre
Team S.P.I.K.E.293
  #4   Spotlight this post!  
Unread 12-01-2004, 17:50
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Nesting Interrupts - is it possible?

Quote:
Originally Posted by Rickertsen2
Yes, with low-priority interrupts it can. If you don't know what a low priority interrupt is, then jsut take my word and know it will work. Just don't try too many interrupts inside interrupts, as these are added to the stack, which will eventually overflow if you do.
Thanks. This actually might be useful. I have some tasks that are (relatively) infrequent, but could easily be done in the interrupt handler as long as I don't shut the frequent, high speed stuff down (e.g. quadrature encoder input). The design requires only one level of nesting.

So, to conclude, to enable interrupts, within the low priority handler, I simply write a 1 to the global interrupt enable flag?
  #5   Spotlight this post!  
Unread 12-01-2004, 18:19
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Nesting Interrupts - is it possible?

Quote:
Originally Posted by Larry Barello
Thanks. This actually might be useful. I have some tasks that are (relatively) infrequent, but could easily be done in the interrupt handler as long as I don't shut the frequent, high speed stuff down (e.g. quadrature encoder input). The design requires only one level of nesting.

So, to conclude, to enable interrupts, within the low priority handler, I simply write a 1 to the global interrupt enable flag?
I am not 100% sure, but am fairly sure that it is never disabled to begin with, and you should be able to nest interrupts as is.
__________________
1139 Alumni
  #6   Spotlight this post!  
Unread 12-01-2004, 20:30
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Nesting Interrupts - is it possible?

Quote:
Originally Posted by Rickertsen2
I am not 100% sure, but am fairly sure that it is never disabled to begin with, and you should be able to nest interrupts as is.
I need to dig into the manual a bit more. Clearly global interrupts are not disabled, because the system needs to service high priority interrupts. However, to nest low priority interrupts I would need to re-enable the low interrupt - and clear whatever interrupt I am servicing & so forth.
  #7   Spotlight this post!  
Unread 07-03-2004, 17:52
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
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   Spotlight this post!  
Unread 07-03-2004, 17:57
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
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   Spotlight this post!  
Unread 07-03-2004, 18:42
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Nesting Interrupts - is it possible?

Quote:
Originally Posted by KenWittlief
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.
Oh, really? How can nesting be any less efficient than serializing the context switches? Does it cost more to save an interrupt handlers context than the top level code?

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   Spotlight this post!  
Unread 07-03-2004, 22:41
10intheCrunch's Avatar
10intheCrunch 10intheCrunch is offline
Who's John V-Neun?
AKA: Alex Baxter
None #0254 (Cheesy Poofs)
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2004
Location: San Jose, CA
Posts: 129
10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough
Send a message via AIM to 10intheCrunch
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.
__________________
~Alex Baxter
Programming, Arms operation, Team 254
  #11   Spotlight this post!  
Unread 07-03-2004, 23:07
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 20:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi