tell the difference between polling and interrupt mechanism in any 16 bit microcontroller

cancel
Showing results for 
Search instead for 
Did you mean: 

tell the difference between polling and interrupt mechanism in any 16 bit microcontroller

34,283 Views
sunil99
Contributor I
hai sir,
           can any one please  tell me the difference between polling and interrupt mechanism in any 16 bit microcontroller.currently i am using MC9S12XDp512 .how the polling mechanism is handled and how is it different from interrupt handling.while hadnling data transfer how polling mechanism is handled and how is it different from interrupt handling.in polling mechanism how an array of 8 elements tranferred and in interrupt mechansim how they are transferred and reception side how they are recieved just tell me the procedure of handling of both mechanisms .what i am thinking is if i tranfer data from one microcontroller to other microcontroller through polling mechnaism only one element is recieved at a time and in interrupt mechanism all 8 elements are recieved when interrupt comes is it true please ealborate and tell me
 
bye
sunil
thanks in advance              
Labels (1)
0 Kudos
3 Replies

263 Views
imajeff
Contributor III
From what Alban said, notice that polling tends to lead to a longer delay before reacting, but there's a more important difference which can affect other things.

On your open-book test, put this:

The difference between polling and interrupt is whether software asks, or whether the hardware tells it.

When polling, the software is asking at a certain point in the program, whether the event has occurred. It might look at the RDRF flag to see if a char has arrived yet on the serial port. In other words, imagine a schoolboy raising his hand every 5 minutes, and asking, is it time yet?

When the system is "interrupt driven", it means the software under (normal conditions) never asks, just keeps doing something else as if it doesn't care whether a char is received yet on the serial port. Meanwhile, hidden away is an ISR (Interrupt Service Routine). When the interrupt occurres, it means hardware has detected the char on the serial port. The CPU will then find where you hid that ISR, and change the program counter so it starts running that routine instead of whatever it was doing before. That's why we call it an "interrupt". The hardware literally interrupted the program to tell it that a char has arrived on the serial port. Imagine the schoolboy quietly doing his worksheet, when suddenly the teacher grabs him by the arm and drags him to the bus (so he doesn't miss his ride home).


P.S.  I almost forgot to say the other things that become important   :-/
When I started using interrupts, it was horrible because
  1. Interrupts increase risk by being non-synchronous with the rest of the program. Developers can go quite out of their way to protect from this, but it adds more code, ram usage, and time to execute. Too bad because they were just trying to speed it up in the first place.
  2. It gets harder to debug with interrupts. You could be tracing one line at a time in the C source code, but not have a clue how many ISR were called inbetween each step.
  3. I didn't really need it, since it was plenty responsive with polling. Sometimes I benefit by polling in two different parts of the main loop, and that introduces almost no added risk compared to interrupts.


Message Edited by imajeff on 2007-06-14 03:25 PM

Message Edited by imajeff on 2007-06-14 03:26 PM
0 Kudos

263 Views
sunil99
Contributor I
thanks for your answer now i am able to understand exact difference by going through thoroughly the two answers which i got from you.
0 Kudos

263 Views
Alban
Senior Contributor II
Hello Sunil,

The difference is in the time spent.

When you do a polling, it means you are regularly checking that a bit is set or not. This takes time and you can do a lot of things before checking again and see that the bit actually changed.

When working on interruption, the program continues running and do anything it wants and when the event occurs, your software is stopped and execute the interrupt to deal with the event. It means you react immediately to the event and that you don't need to check if the bit is set or not.

With interrupt, you have a better reaction time as the event triggers the interrupt.
With polling, you are talking CPU load to do a check that are usually not met, until the check works.

It a bit like if a phone with a ring and a phone without a ring:
Polling means that you pick up the phone regularly to see if someone is on the other end.
Interrupt means you can do what you want and the phone will ring to interrupt you when someone arrives on the other end.

This explanation works on all MCU of all sizes.

Cheers,
Alban.
0 Kudos