Design Idea
Microcontroller becomes multifunctional
Edited by Bill Travis
By Abel Raynus, Armatron International, Melrose, MA -- EDN, 10/25/2001
A microcontroller, by default, can execute only one program at a time. What do you do if, in a given project, you need to perform more than one operation at a time? Add more microcontrollers to the design? In certain cases it's unnecessary. Consider a real-life situation (Figure 1). The microcontroller constantly generates on its Pulse output pin a sequence of pulses with 25-msec duration and a repetition rate of 1 or 4 sec, depending on the state of the Rate input pin. LED illumination accompanies the pulse generation. Suppose that the microcontroller must simultaneously and independently perform some other functions using the rest of its six I/O pins. You can benefit from the fact that the pulse duration is much smaller than the repetition period. During this relatively long period, the microcontroller may not just wait for the generation of the next pulse, but, instead, it may perform some other operation. You organize the pulse-generating program as an interrupt-service routine and the rest of the program as a main program. To avoid any interference between these parts of the software, the interrupt-service routine execution time should be shorter than the smallest period of pulse repetition.
Listing 1 is the assembly routine for multifunctional operation. To make the interrupt program repeatable after the predetermined time interval, the best choice is to use the microcontroller's internal timer. This microcontroller has two timing options: timer-overflow interrupt and RTI (real-time interrupt). For a 2-MHz operating frequency, the timer overflow occurs every 0.51 msec. You can program the RTI period to be as long as 65.5 msec (with RT1-to-RT0=1-to-1). To simplify the counters, it is reasonable to choose the largest value: 65.5 msec. Then, to make the repetition periods equal to 1 and 4 sec, you create the counters modulo 16 and 62 accordingly in the RTI routine (Listing 1). You can see in Listing 1 that the microcontroller waits for a high level on its Start pin to begin pulse generation and LED lighting. During the interval between pulses, it performs the other operations, continuously checking the state of its Start pin. After receiving a low level on the Start pin, the microcontroller stops pulse generating and switches off the LED. Click here to download a zip file containing the listing and the software for multifunctional operation.
Is this the best Design Idea in this issue? Vote at www.ednmag.com.
















