When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?
It is much better to go with Interrupt based design compared to polling based because polling based is flawed in the sense that it expects the data to be returned on every poll.
So between the two methods, the interrupt is more advantageous than polling because the microcontroller can serve many devices (not all at the same time, of course) based on the priority assigned to it. The polling method cannot assign priority because it checks all devices in a round-robin fashion.
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.
In a computer, a polled interrupt is a specific type of I/O interrupt that notifies the part of the computer containing the I/O interface that a device is ready to be read or otherwise handled but does not indicate which device.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With