
MOTOROLA
10-4
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
desired delay would be added to this captured value and stored to an output-compare
register. Since both input captures and output compares are referenced to the same
16-bit counter, the delay can be controlled to the resolution of the free-running counter
independent of software latencies. Details about the implementation of the input-cap-
ture functions as well as more specific examples of how to use input-capture functions
in the MC68HC11A8 are included in
10.3 Input-Capture Functions
.
10.1.3 Output-Compare Concept
The output-compare function is also a fundamental element of the timer architecture
of the MC68HC11A8. For the MCU, physical time is represented by the count in the
16-bit free-running counter. This counter is the central element in the main timer sys-
tem. Output-compare functions are used to program an action to occur at a specific
time (when this 16-bit counter reaches a specific value). For each of the five output-
compare functions, there is a separate 16-bit compare register and a dedicated 16-bit
comparator. The value in the compare register is compared to the value of the free-
running counter on every bus cycle. When the compare register matches the counter
value, an output is generated, which sets an output-compare status flag and initiates
the automatic actions for that output-compare function. Optional automatic actions ini-
tiated by an output compare include generation of a hardware interrupt request and
state changes at the related timer output pin(s).
One of the easiest uses of an output-compare function is to produce a pulse of a spe-
cific duration. First, a value corresponding to the leading edge of the pulse is written
to the output-compare register. The output compare is configured to automatically set
the corresponding output either high or low, depending on the polarity of the pulse be-
ing produced. After this compare occurs, the output compare is reprogrammed to au-
tomatically change the output pin back to its inactive level at the next compare. A value
corresponding to the width of the pulse is added to the original output-compare regis-
ter value, and this result is written to the output-compare register. Since the pin-state
changes occur automatically at specific values of the free-running counter, the pulse
width can be controlled accurately to the resolution of the free-running counter inde-
pendent of software latencies. By repeating the actions for generating pulses, an out-
put signal of a specific frequency and duty cycle can be generated.
Another use of the output-compare function is to generate a specific delay. For exam-
ple, to produce a 10-ms delay to time programming of an EEPROM byte, follow the
initial programming steps to the point where the programming supply has been en-
abled (EEPGM bit has been written to one). Read the current value of the main timer
counter and add a number corresponding to 10 ms (if the count rate is 2 MHz, the val-
ue corresponding to 10 ms would be 20,000
10
or $4E20). Write this sum to the output-
compare register so that an interrupt will occur when the counter gets to this value. In
this example, the actual EEPROM programming time started just before the current
time was read from the counter and ended after responding to the output compare and
turning off EEPGM. The small delays for setting up the output compare and the latency
for responding to the output compare are not considered because they only make the
EEPROM programming time longer by a few microseconds. A more advanced user of
output-compare functions will learn how to correct for these details, although it is often