English
Language : 

AN887 Datasheet, PDF (10/12 Pages) STMicroelectronics – MICROCONTROLLERS MADE EASY
MICROCONTROLLERS MADE EASY
2.5 INTERRUPTS
Polling. Polling is what you have to do if your microcontroller does not have interrupts or if
what you want to do is not time critical. It is a software technique whereby the controller con-
tinually asks a peripheral if it needs servicing. The peripheral sets a flag when it has data
ready for transferring to the controller, which the controller notices on its next poll. Several pe-
ripherals can be polled in succession, with the controller jumping to different software routines,
depending on which flags have been set.
Figure 14. Polling versus Interrupt
POLLING
INTERRUPT
TASK 1
TASK 1
POLLING LOOP
TASK 2
POLLING LOOP
TASK 3
Event occurs
POLLING LOOP
TASK 4
PROCESS
EVENT
TASK 2
TASK 3
Event occurs
TASK 4
INTERRUPT
Save State
PROCESS
EVENT
Restore State
VR02101M
Interrupts. Rather than have the microcontroller continually polling - that is, asking periph-
erals (timers / UARTS / A/Ds / external components) whether they have any data available
(and finding most of the time they do not), a more efficient method is to have the peripherals
tell the controller when they have data ready. The controller can be carrying out its normal
function, only responding to peripherals when there is data to respond to. On receipt of an in-
terrupt, the controller suspends its current operation, identifies the interrupting peripheral, then
jumps to the appropriate interrupt service routine. The advantage of interrupts, compared with
polling, is the speed of response to external events and reduced software overhead (of con-
tinually asking peripherals if they have any data ready).
Most microcontrollers have at least one external interrupt, which can be edge selectable
(rising or falling) or level triggered. Both systems have advantages. Edge is not time sensitive,
but it is susceptible to glitches. Level must be held high (or low) for a specific duration (which
can be a pain but is not susceptible to glitches).
10/12