Polling vs Interrupt

Introduction

There are two basic approaches to the task in the microcontroller programming- Polling Method and Interrupt. In this article, we will point out the difference between Interrupt and Polling.

An Example

Consider a scenario: suppose you are waiting for your friend. There are two methods to know that when your friend has arrived. First is- You waited for him/her at the door and as soon as he/she comes, you get to know. Not cool right? Well, there is another method. You can close the door an continue to do the work you were doing. As soon as he/she arrives, he/she will hit the doorbell and you get to know your friend’s arrival. So the first method I have mentioned is the Polling method and another method is called as Interrupt Method.

The Polling Method

In polling method, a microcontroller continuously checks the status of a register continuously and do the task according to the status of the register. The first case in the example above. The example of this method is what we had done in Button Counter. In that program of button counter, I programmed the microcontroller to check the status of the PIN0 of PORT D register to determine whether the particular button is pressed or not. I have given the conditions in IF-else statements on how to act if the button is pressed. Needless to say that while using polling method, your microcontroller is not doing anything besides checking the status of the device or register. So, if you don’t want to do anything else besides checking the status of the device or register, you can opt for this option otherwise, you should use the interrupt method.

The Interrupt Method

Normally, the hardware is very slow in terms of processing speed with the microcontroller.  Therefore, if we implement Polling method, it is going to slow up the speed of the microcontroller and hence, performance. Therefore, we need a different type of approach that does the task-The Interrupt Method. In this method, the microcontroller doesn’t continuously check on the status of the device or the status of registers. Instead, the device or the register send the signal to the microcontroller that it is ready. The microcontroller stops whatever it is executing and starts to execute the program you have written for interrupts(Interrupt Service Routine-ISR). After executing the ISR, the microcontroller resumes the program where it had left.

Advantages of Interrupt over Polling

  • The first advantage is- the performance of microcontroller is far better in Interrupt method than Polling Method.
  • In polling method, the microcontroller is checking continuously whether the device is ready or not, but the chances of data loss are greater in Polling than Interrupt. This is because of the fact that the microcontroller is checking the register according to the clock it is supplied. But the device can send the data anytime to the microcontroller. To simplify this-Suppose, the time period of the microcontroller is 1 sec. It means it is checking the register in every 1 sec. But what if the data arrives at 1.5 sec? While, in interrupt method- the chances of data loss is very minimal.

Now, the choice is yours. I personally favor interrupt method over polling but I was reading some article and in that, it was written that interrupt increases the risk of being non-synchronous with the rest of the program. Also, it is said that it is little difficult to debug the interrupt program. And yeah, Polling is little simpler to implement and understand than Interrupt.

This ends the article-if you like this you can be the member of our mailing squad to never miss an article update. Do check out the other articles as well.

15 thoughts on “Polling vs Interrupt”

  1. Charisse Divenere

    I do love the way you have presented this problem plus it does indeed give me a lot of fodder for thought. Still, thank you for this excellent point and though I do not go along with the idea in totality, I respect the perspective.

  2. F*ckin’ amazing things here. I am very glad to see your post. Thanks a lot and i’m looking forward to contact you.

  3. This is really interesting, You are a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your
    excellent post. Also, I’ve shared your website in my
    social networks!

Leave a Comment

Your email address will not be published. Required fields are marked *

Share This
Scroll to Top