Pages: [1]   Go Down
Author Topic: interrupt's importance  (Read 406 times)
0 Members and 1 Guest are viewing this topic.
Pakistan
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5494
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

Grand Blanc, MI, USA
Online Online
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some pretty good reading here:
http://en.wikipedia.org/wiki/Interrupt
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pakistan
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thnaks to all
Logged

Pages: [1]   Go Up
Jump to: