Go to Post "Oh, I get why we have Toy Story band-aids!!! The character Woody, and then in FIRST, we have Woodie Flowers. Woody = Woodie? I get it! I GET IT! - Millory [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, 21:36
Apollo Clark Apollo Clark is offline
confused programmer
#1081 (undecided)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Atlanta GA
Posts: 3
Apollo Clark is an unknown quantity at this point
Send a message via AIM to Apollo Clark
When would I use an interrupt?

I'm a noob to C programming, and don't understand how interrupts work, so...

How is:

void Default_Routine(void)
{
if(bButtonA)
vButtonPressed();
....
};

different from calling an interrupt when ever bButtonA is pressed?

(i tried to post this message earlier, but it didn't seem to go though...)
  #2   Spotlight this post!  
Unread 11-01-2004, 21:50
mightywombat's Avatar
mightywombat mightywombat is offline
bins? stacking?? NOOOOO!
AKA: Bill Rosemurgy
#0857 (Superior Roboworks)
Team Role: Programmer
 
Join Date: Dec 2003
Location: Houghton, MI
Posts: 93
mightywombat is on a distinguished road
Re: When would I use an interrupt?

hmmm... i still have a limited understanding but check out this post. It will enlighten you hopefullys. I actually can't find it. Do a search for interrupts in the programming forum. Read the posts. Kevin Watson and WizardofAz had some really good things to say. I wish I could find the thread. Kevin Watson also has some demo code at www.kevin.org/frc for interrupts.
__________________
Bill Rosemurgy - Aspiring Programmer and Human Player (stack of 8 in <10 seconds...oh yeah... but I can't shoot for crap.)
www.team857.com
  #3   Spotlight this post!  
Unread 11-01-2004, 22:03
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
Cool Re: When would I use an interrupt?

The difference is that vButtonPressed(); will only be called when the if statement is being executed. With interrupts it doesn't matter what part of the code is being executed for if the button is pressed it will automatically call vButtonPressed();

One basicaly gives faster feedback than the other
__________________
Andre
Team S.P.I.K.E.293

Last edited by m0rph3us : 11-01-2004 at 22:08.
  #4   Spotlight this post!  
Unread 11-01-2004, 22:13
Apollo Clark Apollo Clark is offline
confused programmer
#1081 (undecided)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Atlanta GA
Posts: 3
Apollo Clark is an unknown quantity at this point
Send a message via AIM to Apollo Clark
Re: When would I use an interrupt?

Mightywombat: thanks, i downloaded the source and am going over it right now ^_^

m0rph3us:OHHHHHHHHHHHHH... makes so much sense now.

So, when does the processor check the interrupt registers?

And, is the modem receiving data even when it's in the middle of executing a program?

Last edited by Apollo Clark : 11-01-2004 at 22:17. Reason: forogt to add something
  #5   Spotlight this post!  
Unread 11-01-2004, 22:27
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: When would I use an interrupt?

When you have something like a button you probably won't need to use an interrupt. Well it actually depends on how often the button is checked in normal operation. If the button is checked at 40 Hz (loop time for the FIRST default code, based on the radio baud rate), then you won't need an interrupt (in fact an interrupt might make it harder to deal with because you have to worry about key bounce).

But if you have some critical sensor that updates at 10 kHz and you want to catch every update with a polling frequency of 40 Hz, you would need an interrupt.

No matter where the code is, as soon as an interrupt happens it jumps to the appropriate memory location (depending on whether it's high priority or low priority). The only exception is if another interrupt of equal or higher priority is currently being processed.
  #6   Spotlight this post!  
Unread 11-01-2004, 22:38
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: When would I use an interrupt?

Quote:
Originally Posted by Apollo Clark
I'm a noob to C programming, and don't understand how interrupts work, so...

How is:

void Default_Routine(void)
{
if(bButtonA)
vButtonPressed();
....
};

different from calling an interrupt when ever bButtonA is pressed?

(i tried to post this message earlier, but it didn't seem to go though...)
First let me explain clearly what an interrupt is. Basically an interrupt is a peice of code that is automatically executed whenever a specific event occurs. When an interrupt occurs, your program will immediately stop executing whatever it was doing and jump to the interrupt handler. Once the interrupt handler has finished, the program jumps back to wherever it was before the interrupt occured. Our control system has many soureces of interrupts. The two most useful are explained below.:

Timers: These are special counters that operate in the background. They can be programmed to count up at a specified speed. They can be programmed to trigger an interrupt once they reach a specified number. This is extremely useful for keeping track of time or making somethign happen at a specific time. Thsi description really doesn't so timers justice. I recimmend you read the IFI whitepaper at: http://innovationfirst.com/FIRSTRobo...003-Nov-20.pdf

IO: pins: interrupts can be set up to execute each time the state of an IO pin changes. An example of this would be your button scenario above.

What you did above is called polling. This method of detecting whether something is happening has two disadvantages. The first is that you are wasting time actively checking to see if something happened or not. The second is that its not very good at detecting things immmediately or things that happen quickly.
__________________
1139 Alumni
  #7   Spotlight this post!  
Unread 11-01-2004, 23:44
KevinB's Avatar
KevinB KevinB is offline
Registered User
AKA: Alum
no team
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2001
Location: AL
Posts: 188
KevinB will become famous soon enoughKevinB will become famous soon enough
Send a message via ICQ to KevinB
Re: When would I use an interrupt?

In summary of the above, interrupts are more or less only necessary if the event triggering the interrupt is: (a) highly time sensitive, that is, the code should execute EXACTLY when that event occurs; or (b) going to be occuring faster than the main loop would poll for it (ie. hundreds or thousands of times per second).
  #8   Spotlight this post!  
Unread 18-01-2004, 13:29
Jeff McCune's Avatar
Jeff McCune Jeff McCune is offline
Alpha Geek
#0677 (The Wirestrippers)
Team Role: Mentor
 
Join Date: Jan 2003
Location: The Ohio State University
Posts: 67
Jeff McCune is on a distinguished road
Send a message via ICQ to Jeff McCune Send a message via AIM to Jeff McCune
Re: When would I use an interrupt?

Quote:
Originally Posted by Apollo Clark
So, when does the processor check the interrupt registers?
I think you're missing the point of interrupts. It's not that the function is executed anywhere you're code is running. This is true, but this is just a side-effect of the real purpose of interrupts.

Interrupts provide a way for the harware to be notified of an *event* versus the hardware frequently checking if an event happened sometime in the past. You don't *have* to use interrupts for a simple digital switch, but you might as well. I'm a big fan of not wasting resources, if I have interrupts left over, I'll use them for a trivial task such as this. My logic is, why waste time checking something if I can be told when it happens.

Also, if this controler has "true" interrupts, then the hardware doesn't need to "check the registers." Asserting an interrupt pin on the chip will literally *interrupt* execution and force execution of the interrupt handler. Doesn't need to check anything.
__________________
Team 677 - The Wirestrippers - Columbus School for Girls and The Ohio State University
EMAIL: mccune@ling.ohio-state.edu

...And all you touch and all you see
Is all your life will ever be...
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
Interrupts Questions mightywombat Programming 0 03-01-2004 14:50
Interrupt limitations? randomperson Programming 2 27-12-2003 21:40
EDU Interrupt and Timer Template Code Kevin Watson Programming 8 22-12-2003 14:11
IFI_Initialization Venkatesh Programming 11 08-12-2003 12:17
What is an interrupt handler? Adam Y. Programming 7 14-08-2003 10:26


All times are GMT -5. The time now is 19:56.

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