MOTOROLA
10-18
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
EDGxB, EDGxA — Input Capture Edge Control (x = 1, 2, or 3)
These pairs of bits determine which edge(s) the input-capture functions will be sensi-
tive to. These bit pairs are encoded as shown in the following table:
10.3.2 Using Input Capture to Measure Period and Frequency
Timer Examples 10–1(a) and 10–1(b) show how to measure a period using an input-
capture function. A complete assembly listing for all timer section examples is shown
in
10.6 Listing of Timer Examples
. Timer Example 10–1(a) measures the time be-
tween two successive rising edges on an input signal at the PA2/IC1 pin. This program
uses the input-capture function in polled mode for demonstration because it is a little
simpler than the interrupt-driven operation. Other examples in this section will demon-
strate interrupt-driven operation, which is often a more flexible approach because the
MCU can be performing other tasks while waiting for a particular timer event.
Example 10–1(b) changes the period obtained from Example 10–1(a) into a frequency
to display the results in a more familiar form. Also, support routines are provided to
convert hexadecimal numbers into decimal numbers. When running the example, a
period is measured at the IC1 pin and displayed as a decimal period (in E cycles) and
as a frequency (in Hz). After printing the result, the program returns to its start and re-
peats continuously. Depending on the display-device speed and the signal at IC1, a
screen can be filled with results very quickly. To stop, just press the reset button on
the EVB board.
Figure 10-4
shows the critical instructions in the measurement of the period of the sig-
nal at the PA2/IC1 pin. The numbers in square brackets in the listings indicate the
number of MCU E cycles needed to execute each instruction. This information is used
in the timing analysis presented in
Figure 10-5
.
The timing analysis for Example 10–1 is shown in
Figure 10-5
, which is very detailed
to show exactly what occurs in an input capture. Software instructions are used to read
the first captured value, to prepare for the second capture, and to reset the input-cap-
ture flag. These instructions require a finite amount of time. If the period of the signal
being measured is too short, the second edge can come before the program is ready
for it. This period will determine the highest frequency that can be measured with this
example program. If the signal period being measured is longer than the range of the
16-bit timer counter, then two periods, which are exactly one overflow time apart, are
not distinguishable. Since this program does not consider overflows, this period will
determine the lowest frequency that can be measured with this program. These limi-
tations are program limits, and, as shown in other examples, the input-capture func-
tions can be used to measure much shorter or much longer periods.
EDGxB
0
0
1
1
EDGxA
0
1
0
1
Configuration
Capture Disabled
Capture on Rising Edges Only
Capture on Falling Edges Only
Capture on Any Edge (Rising or Falling)