Navigation

Saturday, 11 April 2015

Interrupts in Microcontrollers

Interrupts can be defined as a hardware triggered software event. They are used in microcontroller programming to ensure that events occur in real time.

To implement interrupts, the condition or event is placed inside the Interrupt Service Routine (ISR). Say, when we press a switch we want a response within a specified period, this if statement followed by the corresponding action is placed in the ISR. The ISR is always called at a frequency/period given by the value written into the RELOAD register.

Another use of interrupt is producing a sound at a particular frequency. This is achieved because interrupts are implemented at a given frequency, so the frequency of the interrupt will be the frequency of the sound produced. Other uses are in obtaining sensor readings at every specified time.

In short, interrupts are used whenever we want to produce an output at a particular time irrespective of the line of code or step currently being executed by the microcontroller in the infinite loop. When the hardware event is triggered, the software will round up its current line of execution, then jump to the ISR to execute the codes, after execution, program flow would return to where it left off in the infinite loop.

No comments:

Post a Comment