Professional Documents
Culture Documents
1. INTRODUCTION
Interrupts and polling are the two methods used by the microcontroller to provide
service for several devices . An interrupt is a signal to the microcontroller provided by
software or hardware indicating an event that needs immediate attention. In polling method,
the microprocessor or microcontroller continuously monitors the device status and provides
service. Interrupts and polling can be used to perform the same task independently. A brief
comparison between interrupts and polling are discussed in this report.
2. POLLING
In polling, the microcontroller continuously polls or tests every device in turn as to
whether it requires attention. The polling is carried out by a polling program that shares
processing time with the currently running task. The microcontroller continuously monitors
the status of a given device; when the status condition is met, it performs the service. A
device indicates it requires attention by setting a bit in its device status register. After that, it
moves on to monitor the next device until each one is serviced. Most of the time, devices will
not require attention and when one does, it will have to wait until it is next interrogated by the
polling program. The polling method cannot assign priority since it checks all devices in a
round-robin fashion. Round robin architecture is characterized by the absence of interrupts.
It does not suffer from shared data problems. It is attractive for simple environments. The
polling method wastes much of the microcontrollers time by polling devices that do not need
service. The waste of the microcontrollers time can be used to perform some useful tasks.
Polling uses a lot of CPU horsepower and it checks whether the peripheral is ready or not.
Polled code is generally messy and unstructured and it is a big loop with often multiple calls
to check and see if peripheral is ready. Polled code leads to variable latency in servicing
peripherals. The general syntax for polling is given by
While(1)
{
get device status
if(service required)
{
service_routine ;
}
normal_execution;
}
Figure 3.1 Syntax for polling
POLLING
Microcontroller
Interrupt
method
microcontroller's
time
do
not
waste
it
provides
since
Polling
cannot
method
wastes
ignore
much
device
of
the
Polling
place.
unstructured.
code
is
generally
messy
and
method.
Interrupts uses microcontroller only when
work is to be done.
Interrupts give highly predictable servicing
latencies.
servicing peripherals.
Here CS02, CS01 and CS00 are the clock select bits. They are used to set up the Prescaler
for timer.
Timer 0 is used in this program ,the last two bits controls the interrupts for timer 0.Here the
timer overflow interrupt is set to 1.
In the above program ,Timer/counter control registers are used to define the
prescaler value for the timer .The initial value is loaded into the timer using timer/counter 0
register. The timer overflow interrupt is enabled using the timer/counter interrupt mask
register. Port A is configured as output.
Here in the main function an infinite while loop is present .This while loop execution
continues until the timer overflows . When the timer overflows, the control jumps to service
the routine and starts executing it. When it becomes equal to 61 ,it toggles the bit and the
count variable is reset to zero. It can be seen from the program that the CPU does not do
any other process other than checking for the status of the count during the entire operation.
From this program, it is understood that only when the timer overflows, the toggling
action is performed and no other task is performed in the normal case.
6