Page 268 - Programming Microcontrollers in C
P. 268

Timer Operations    253

                          on time is poor and the maximum on time can be up to one clock
                          cycle shy of the base period. If you wish to have good performance
                          at both ends, minimum on time at the same time as maximum on
                          time, you can examine the on time in your program and if it is less
                          than 50% of the base time period, control the PWM by an interrupt
                          on reset. Otherwise, control the PWM by an interrupt on set.
                          Implementation of the code for this approach is left to the exercises.
                              Output compare operations  OC2 through  OC4 and the
                          programmable timer subsystem I4O5 are all identical. These versatile
                          timers can be used to generate complex timing waveforms that are
                          useful in keeping time, running stepper motors, etc. The examples
                          shown above demonstrate how these outputs can be converted into a
                          PWM digital to analog output. The coupling between OC1 and the
                          other outputs provides an excellent mechanism for synchronizing
                          two time events for the outside circuitry. Of course, these subsystems
                          can create events in time, but they are completely unable to measure
                          time. We will later examine the analysis of timed events that can be
                          measured with the help of the input capture subsystems.

                          EXERCISES
                          1. Write the code that will determine from the on time for the PWM
                            the interrupt operation that will allow the minimum off and maxi­
                            mum on time simultaneously.
                          2. Modify the code in Listing 5.4 to eliminate the need for a condi­
                            tional test if (OC1D.OC1D7 = = 1).


            Input Capture Subsystems

                              On the MC68HC11EX family, there are three input capture timers
                          and one timer that can be programmed as either an input capture or
                          an output compare. These sub-systems are used to measure time
                          interval. The same 16-bit timer used in the output compare systems
                          is used to support the input captures. When an input occurs on one of
                          the input capture pins, the value contained in the 16-bit timer is saved
                          in a register designated for that pin, a flag is set, and the processor
                          can request an interrupt. With input captures, we can measure period
                          and hence frequency (or speed). One of the leading applications where
                          the input capture is used is in automatic braking systems. We shall
   263   264   265   266   267   268   269   270   271   272   273