Page 195 - Programming Microcontrollers in C
P. 195

180    Chapter 4  Small 8-Bit Systems

                          microcontroller crystal frequency. An input capture operation de­
                          tects the occurrence of an input and transfers the contents of the
                          16-bit counter into the input capture register. This transfer will al­
                          ways set a flag, and it can cause a CPU interrupt if desired. With an
                          input capture system, precise measurement of time interval is pos­
                          sible. Details such as phase between two waveforms can be determined
                          or slight differences in frequencies between several signals can be
                          detected. The input capture provides far more accurate time mea­
                          surement than can be obtained with either synchronous polling or
                          asynchronous interrupt time measurements. There is a tiny inherent
                          delay between the occurrence of the input and the setting of the input
                          capture register. Such a measurement made by polling an input would
                          require that the computer have a free running counter available to
                          interrogate when the input is detected. Then, the computer would
                          have to be assigned totally to the job of watching the input for the
                          impending transition. When the transition is detected, the value of
                          the counter would have to be read to determine the time of the tran­
                          sition. Of course, this sequence of operations would require several
                          computer clock cycles per test, and also several cycles would be re­
                          quired to read the counter. Therefore, the accuracy of the time
                          measurement would be compromised by these necessary time delays.
                              An asynchronous interrupt method to determine the time inter­
                          val is better than a polled method, but even this method has built-in
                          errors that make it an impractical means to measure time intervals
                          accurately. The input capture register input system resolves most of
                          the problems associated with accurate measurement of time inter­
                          vals with a microcomputer.
                              Another type of timing problem exists. Suppose that the time
                          that an event is to occur has been calculated. If the time of occur­
                          rence is to be accurate, we have a situation like that discussed above.
                          The processor will have to spend all of its time watching the clock to
                          determine when the correct time has arrived. Any time spent on other
                          tasks during this measurement interval will be a latency during which
                          the processor cannot determine if the specified time has arrived. In
                          this case, the accuracy of the event time will be degraded by the time
                          spent on other tasks.
                              The 16-bit timer avoids this type of problem nicely. An output
                          compare system is used. The time of occurrence is calculated rela­
   190   191   192   193   194   195   196   197   198   199   200