Interrupt and Polling

What is Polling ?

Polling the device usually means reading its status register every so often until the device’s status changes to indicate that it has completed the request.

Polling means you won’t know when the data is ready, but you can get it when you are ready. You’ll have to tell your program how to wait for the data.

Example :

below mentioned code, also is similar example of Transmit data by using polling.


In above code, This line : while( ! (USCSA & (1 << UDRE))  simply waits for the transmit buffer to be empty by checking the UDRE flag, before loading it with new data to be transmitted.

below mentioned code, also is similar example of receive data by using polling.


In Above code, This line : while( ! (USCSA & (1 << RXC)) simply waits for data to be present in the receive buffer by checking the RXC flag, before reading the buffer and returning the value.

What is Interrupt?

In systems programming, an interrupt is a signal to the processor
It can be emitted either by hardware or software indicating an event that needs immediate attention.

Interrupt triggers instantly when the data is ready, and the interrupt handler can fetch the data before the next instruction completes.

Example :

below mentioned code, also is similar example of receive data by using interrupt.

   value = UDR;             //read UART register into value

In Above codeThis line :- ISR(USART_RXC_vect)  simply execute ISR, when data receive interrupt will occur and will return the value.

Below code is ADC data conversion using Interrupt :-
Screenshot from 2018-06-19 02:23:23.png


What is ISR:-

 “Interrupt Service Routine.” An ISR (also called an interrupt handler) is a software process invoked by an interrupt request from a hardware device. It handles the request and sends it to the cpu, interrupting the active process. When the ISR is complete, the process is resumed.

Basic Device notify CPU that it needs CPU attention. CPU constantly checks device status whether it needs CPU’s attention.
Mechanism An interrupt is a hardware mechanism. Polling is a Protocol.
Servicing Interrupt handler services the Device. CPU services the device.
Indication Interrupt-request line indicates that device needs servicing. Command-ready bit indicates the device needs servicing.
CPU CPU is disturbed only when a device needs servicing, which saves CPU cycles. CPU has to wait and check whether a device needs servicing which wastes lots of CPU cycles.
Occurrence An interrupt can occur at any time. CPU polls the devices at regular interval.
Efficiency Interrupt becomes inefficient when devices keep on interrupting the CPU repeatedly. Polling becomes inefficient when CPU rarely finds a device ready for service.
Example Let the bell ring then open the door to check who has come. Constantly keep on opening the door to check whether anybody has come.

Types of Interrupt :

Interrupts are a commonly used technique in real-time computing and such a system is said to be interrupt-driven.

Hardware Software (Exception/Trap) Software (Instruction set)
Interrupt Request(IRQ) sent from device to processor. Exception/Trap sent from processor to processor, caused by an exceptional condition in the processor itself. A special instruction in the instruction set which causes an interrupt when it is executed.

Hardware interrupt
A hardware interrupt is a signal which can tell the CPU that something happen in hardware device, and should be immediately responded. Hardware interrupts are triggered by peripheral devices outside the microcontroller. An interrupt causes the processor to save its state of execution and begin execution of an interrupt service routine.
Unlike the software interrupts, hardware interrupts are asynchronous and can occur in the middle of instruction execution, requiring additional care in programming. The act of initiating a hardware interrupt is referred to as an interrupt request (IRQ).

Software interrupt
Software interrupt is an instruction which cause a context switch to an interrupt handler similar to a hardware interrupt. Usually it is an interrupt generated within a processor by executing a special instruction in the instruction set which causes an interrupt when it is executed.
Another type of software interrupt is triggered by an exceptional condition in the processor itself. This type of interrupt is often called a trap or exception.
Unlike the hardware interrupts where the number of interrupts is limited by the number of interrupt request (IRQ) lines to the processor, software interrupt can have hundreds of different interrupts.

What is interrupt latency?

Interrupt latency refers primarily to the software interrupt handling latencies.

In other words, the amount of time that elapses from the time that an external interrupt arrives at the processor until the time that the interrupt processing begins.

One of the most important aspects of kernel real-time performance is the ability to service an interrupt request (IRQ) within a specified amount of time.

  1. IRQ (Interrupt Request)
    An (or IRQ) is a hardware signal sent to the processor that temporarily stops a running program and allows a special program, an interrupt handler, to run instead. Interrupts are used to handle such events as data receipt from a modem or network, or a key press or mouse movement.
  2. FIQ (Fast Interrupt Request)
    An FIQ is just a higher priority interrupt request, that is prioritized by disabling IRQ and other FIQ handlers during request servicing. Therefore, no other interrupts can occur during the processing of the active FIQ interrupt.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s