When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?
See, we have main 5 methodologies:
1) Blind
CPU checks every x ms for data. ETC check pin 12.
2)Polling( Busy/Wait)
The CPU is always checking and waiting for Flag to be raised, like UART raising a flag after a packet is transferred. Forever checking the Flag register. (Best response time) but the CPU cant perform anything else.
3) Interrupt:
CPU performs normally, if interrupt happens, CPU will switch context to ISR. if Pin 18 saw a falling edge, perform ISR (1). Not bad response time and CPU can do anything while the ISR is not active. Do it with urgent apps that you do not know when it might happen.
4)Periodic Polling:
CPU is doing its stuff but, every ms seconds its checking pin 11. Blind is doing nothing in between. The worse response time, not urgent apps, do it when you don't trust the hardware will raise the interrupt. it can be created using a timer interrupt.
5) Direct memory access.
Advanced interfacing approach. Transfers data directly from/to memory. Input will be read to memory directly. Output will be written from memory directly. Both uses a controller.
Polling mode can be useful in systems with high frequency events, where the overhead associated with entering and exiting interrupt handlers uses more CPU cycles than simply polling. For example polling might be used in an IP router to maximise CPU bandwidth available to packet processing.