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.