One microcontroller serves multiple external interrupts
By Abel Raynus, Armatron International, Melrose, MA -- 2/1/2001
In designing µC-based systems, you often face a situation in which the µC
has to respond to an external event happening at an uncertain moment in time.
One example is receiving an echo from an object in a pulse-range measuring
system. In these situations, you would usually use an external interrupt.
Unfortunately, low-end, small, inexpensive µCs have only one external-interrupt
vector address, so the µC can execute only one interrupt-service routine. What
do you do if the design objectives call for the µC to react to several
interrupts coming from different sources and to process each of them in a
different way? Figure 1 shows a design technique that solves the problem. The method is applicable to any µC, such as the 16-pin OTP MC68HC705KJ1 from Motorola. This µC has two options for handling external interrupts: via the IRQ pin triggered by a negative edge or via the pins pA0 to pA3 triggered by a positive edge. You can choose these options as well as the capability to have edge or edge-and-level triggering by setting the proper bits in the MOR (mask-option register).When you set pins pA0 to pA3 as external-interrupt inputs, they connect inside the µC as an OR gate. Hence, you can trigger this µC from five external-interrupt sources. If the number of sources exceeds five, you can wire them through an OR gate to any of the external-interrupt pins. To illustrate the method in the simplest way, assume only three interrupt sources, represented by pushbutton switches S1 to S3 (Figure 1). You can simplify the interrupt-service routines to operate with only two LEDs. The use of the LEDs provides the opportunity to visualize and verify the interrupt process. After initialization, both LEDs turns off. The system waits for the first interrupt from S1. As a result of the interrupt, the green LED turns on. The system again waits for the next interrupt from S2, and the red LED turns on. During the waiting period, the µC can perform some function, which can differ for different projects. Service routines in real applications are much more complicated than just lighting LEDs. But those details are unimportant for illustrating this method.
The third external interrupt from S3 switches off both LEDs, and the µC again waits for an interrupt from S1. The limitation of this method is that the sequence of incoming interrupts must be known, but this constraint is unproblematic for most applications. Listing 1 shows the µC program. (You can also download the associated assembly software from the zip file that contains Listing 1.) The key to the method is to prepare the number-address of the interrupt-service routine for the next expected interrupt in the special register Disp (dispatcher). In this case, the µC executes every external interrupt with its own individual interrupt routine. The routine adds a delay of 200 msec for debouncing the switches; you can eliminate the delay if it is unnecessary for the interrupt signals.
© 2009, Reed Business Information, a division of Reed Elsevier Inc. All Rights Reserved.

