![]() |
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...) |
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.
|
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 |
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? |
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. |
Re: When would I use an interrupt?
Quote:
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. |
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).
|
Re: When would I use an interrupt?
Quote:
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. |
| All times are GMT -5. The time now is 00:34. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi