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
- 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.
- 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.
- 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 PMMessage Edited by imajeff on
2007-06-14 03:26 PM