Go Down

Topic: interrupt's importance (Read 499 times) previous topic - next topic

I want to know about why we need interrpts? What is the main purpose of interrupts and when we need it.
your comments and guidence will be appreciated.
Thanks,

Erdin

For example when you have sketch, that detects buttons and turn on leds, and also checks the serial port for incoming data.
Suppose your sketch is busy with all that, but suddenly serial data is being received.
At that moment the serial data has to be read and placed into a buffer.
That is done in an interrupt routine.

If you would have a "delay(1000);" in your sketch, the serial data is still being received, because the interrupt is executed during the "delay(1000);"

The sketch is still running, and doesn't know that the interrupt occured. But once the sketch requests the Serial.available() is can read the the serial data from the buffer.

Also the Wire (I2C) library uses interrupts.

You could use interrupts yourself, when something has to be done at that very moment.

kf2qd

Using interrupts means you ca write other code that is more complex without having to constantly check if your input needs to be serviced. By using a interrupt you write a routine outside of your main processing loop that will respond to the interrupting input when the transition happens.

2 scenarios - #1 without interrupts - every other line of code has to check and see if your input needs processing. #2 With Interrupts. You write the interrupt handling code and store the information in a variable and set a flag variable when the interrupt occurs. When your code gets to the place where it can process the information it reads the variable and resets the flag.
I have also written a programm that was only and interrupt, the loop had no code between the { }. That allowed the fastest processing of the transition on hte input.

fungus


I want to know about why we need interrpts? What is the main purpose of interrupts and when we need it.
your comments and guidence will be appreciated.
Thanks,


Use them for things that need to happen even if somebody uses the "delay()" function.

eg. Data arriving at the serial port.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Jack Christensen

Some pretty good reading here:
http://en.wikipedia.org/wiki/Interrupt
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/


Go Up