Page 145 - Understanding Automotive Electronics
P. 145

2735 | CH 4  Page 132  Tuesday, March 10, 1998  11:06 AM



                4                     MICROCOMPUTER INSTRUMENTATION AND CONTROL




                                      Interrupts

                Interrupts cause the      An efficient alternative to polling uses control circuitry called an
                CPU to jump to a spe-  interrupt.  An interrupt is an electrical signal that is generated outside of the
                cific location in the pro-  CPU and is connected to an input on the CPU. The interrupt causes the
                gram. By signaling the   CPU to temporarily discontinue the program execution and to perform some
                microprocessor for ser-  operation on data coming from an external device. A slow ADC, for instance,
                vice only when needed,   could use an interrupt line to tell the processor when it is finished converting.
                interrupts are more effi-  When an interrupt occurs, the processor automatically jumps to a designated
                cient than polling.   program location and executes the interrupt service subroutine. For the
                                      ADC, this would be a subroutine to read in the conversion result. When the
                                      interrupt subroutine is done, the computer returns to the place where it left
                                      off in the program as if nothing had happened. (Recall the previous
                                      discussion on the jump-to-subroutine instruction.) Interrupts reduce the
                                      amount of time the computer spends dealing with the various peripheral
                                      devices.
                                          Another important use for interrupts is in timekeeping. Suppose that a
                                      system is being used that requires things to be done at particular times; for
                                      instance, sampling an analog signal is a timed process.  A special component
                                      called a timer could be used.  A timer is a device that works like a digital
                                      watch.  A square-wave clock signal is counted in counter registers like the one
                                      discussed in Chapter 3. The timer can be programmed to turn on the
                                      interrupt line when it reaches a certain count and then reset itself (start over).
                                      It may be inside the CPU itself or it may be contained in peripheral devices in
                                      the microcomputer system. Timers have many automotive applications (as
                                      shown later).
                                          Such a technique is sometimes used to trigger the output of a new
                                      number to a DAC at regular intervals. The microcomputer simply programs
                                      the timer for the desired amount of time by presetting the counter to some
                                      starting value other than zero. Each time the timer counts out the programmed
                                      number of pulses, it interrupts the computer. The interrupt service subroutine
                                      then gets the new binary number that has been put into memory by the
                                      microcomputer and transfers this number to the DAC data latches at the input
                                      to the DAC.
                                      Vectored Interrupts
                                          All of the interrupt activity is completely invisible to the program that
                                      gets interrupted. In other words, the interrupted program doesn’t know it was
                                      interrupted because its execution continues without program modification
                                      with minimum delay. Interrupts allow the computer to handle two or more
                                      things almost simultaneously. In some systems, one interrupt line may be
                                      used by more than one device. For instance, two or more ADCs may use the
                                      same interrupt line to indicate when either is ready. In this case, the computer
                                      doesn’t know which device caused the interrupt. The computer could poll all



                132                   UNDERSTANDING AUTOMOTIVE ELECTRONICS
   140   141   142   143   144   145   146   147   148   149   150