MOTOROLA
10-38
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
percent of the period, control how quickly the OC1 service routine must finish (OC2
and OC3 must be scheduled in time to occur as early as 50 percent of the way to the
next PWM pulse start). The OC1 interrupt service takes almost 100 cycles, but OC2
and OC3 are updated somewhat before the end of the routine. Thus, the theoretical
minimum period is about 140 cycles (two times 70 cycles, where 70 cycles is the ap-
proximate latency time from an OC1 interrupt request to when OC2 and OC3 have
been updated). Because the example was set up so that period is specified by the
number of cycles in one percent of the period, a value of two makes period equal 200
cycles, which is acceptable; whereas, a value of one makes period equal 100 cycles,
which is too small.
This example is only one of many ways to generate PWM signals in the M68HC11.
Example 10–7 demonstrates an alternate way, which uses only one output compare.
The approach used in that example does not allow the duty cycle to be too close to 0
or 100 percent because there is a minimum latency requirement between any two suc-
cessive edges on the PWM output signal. In general, any approach will be subject to
some unique set of limitations. As with many engineering problems, there is no single
best solution; the user will have to select the best method based on all the application
requirements.
10.4.3 Forced Output Compares
The output-compare force mechanism provides a convenient way to change timer out-
put pin states without actually setting up and waiting for an output-compare match.
The force mechanism is useful to force an initial state at the start of a timing sequence
or to force an output compare earlier than it was scheduled. Consider the case where
the user has scheduled an output compare to occur at a certain time, but as the time
approaches, the user decides instead the compare should occur as soon as possible.
(This case is an actual situation that arises in spark timing control in some automotive
engine control applications.) In the older M6801 Family MCU, the user had to read the
timer counter, add a small value to it corresponding to a software delay, and write this
value to the output-compare register so that a compare match would occur at the next
E-clock cycle after the compare register update. With the force mechanism in the
M68HC11 Family, the user writes to the CFORC register to force any combination of
output-compare channels to trigger.
To use the output-compare force mechanism, the user would write to the CFORC reg-
ister with ones in the bit positions corresponding to the output-compare channels to be
forced. Writing a zero to a bit in the CFORC register has no effect on the correspond-
ing output-compare channel. At the next timer count after the write to CFORC, the
forced channels will trigger their programmed pin actions to occur. The forced actions
are synchronized to the timer counter clock, which is slower than E if a prescale factor
has been specified (PR1, PR0). As shown in
Figure 10-1
, the output-compare force
signal causes pin action but does not affect the OCxF bit nor generate interrupts.
Normally, the force mechanism would not be used in conjunction with the automatic
pin action that toggles the corresponding output-compare pin. Consider the case pre-
viously described where a force is being used to trigger the pin action earlier than it
was scheduled to occur. The user might easily fall into the trap of forcing a toggle just