Thursday 10 September 2015

Interrupt and Polling

What is interrupt?

In an embedded system we use many sensors, serial communication, ADC and much more Microcontroller communicates
with these systems through control lines,  in order to get information from these systems microcontroller uses two methods 1.Polling (See polling method) 2.Interrupt.   
 
Polling method

In the polling method microcontroller keeps checking the status of devices for example we have a simple microcontroller circuit with one switch and one LED and the circuit working is when press the switch LED will turn ON and when release the switch LED will turn OFF.  The program would be like
main
{
While(TRUE)
{
If(Switch == Press)
{
LED = TURN ON;
}
else
{
LED = TURN OFF;
}
}
}

In this program you can see that the processor always check the status of the switch and decide the LED condition. While doing so it does no  other operations and consume all processing time for monitoring . This monitoring time doesn’t matter in this project as it is a simple project  when you go for complicated big projects you may use many switches, LEDs, sensors etc in such situations this monitoring wastes your processor time and that affect your project performance and fast response.  Another real life example is  you are working in your home kitchen and expecting someone as guest to your home. The polling method is exactly like you often (may be every 5 minutes) go and open the door to check whether the guest has come or not.

 Interrupt

 As name implies an interrupt is some events or requests that interrupts the current program execution. Interrupt is an important feature in microcontroller it is basically an event or a request that require immediate attention of microcontroller. When an interrupt occurs the microcontroller completes the current execution of the current instruction and starts the execution program written in an interrupt service routine (ISR).  
We can use LED example here

 main
{
             Enable Switch Interrupt;
While(TRUE)
{
LED = TURN OFF;
}
}

Interrupt Service Routine (void)
{
LED = TURN ON;
}


                Here the switch input is an interrupt.  When we press the switch an interrupt occurs the microcontroller completes the current execution of the current instruction and starts the execution program written in an interrupt service routine (ISR).  In the real life example the interrupt method is like you have a calling bell in front of your door so you don’t need to check always you only need to go and open the door when your guest press the calling bell.

No comments:

Post a Comment