Question
Polling or Interrupt based method
When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?
Question
When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?
Solution
If the event of interest is:
then an interrupt based handler would make sense.
If the event of interest is:
then polling might be a better fit.
Other considerations include whether you are writing a device driver for an OS or just writing bare metal code with no thread support. In bare metal situations the CPU is often just looping when it isn't busy so it might as well be polling something.
Solution
Polling should be avoided where possible, as it typically eats a lot of CPU cycles unnecessarily (unless either (a) you are only going to poll for a short time or (b) you can afford to sleep for a reasonable time in your polling loop). Wasting CPU cycles is bad not only from a performance perspective, but it also drives up power consumption, which may well be an issue for battery-powered embedded applications.