Intel 8XC251SQ Microscope & Magnifier User Manual


 
9-7
PROGRAMMABLE COUNTER ARRAY
9.3.2 Compare Modes
The compare function provides the capability for operating the five modules as timers, event
counters, or pulse width modulators. Four modes employ the compare function: 16-bit software
timer mode, high-speed output mode, WDT mode, and PWM mode. In the first three of these, the
compare/capture module continuously compares the 16-bit PCA timer/counter value with the 16-
bit value pre-loaded into the module’s CCAPxH/CCAPxL register pair. In the PWM mode, the
module continuously compares the value in the low-byte PCA timer/counter register (CL) with
an 8-bit value in the CCAPxL module register. Comparisons are made three times per peripheral
cycle to match the fastest PCA timer/counter clocking rate (F
OSC
/4). For a description of periph-
eral cycle timing, see section 2.2.2, “Clock and Reset Unit.”
Setting the ECOMx bit in a module’s mode register (CCAPMx) selects the compare function for
that module (Figure 9-9 on page 9-15). To use the modules in the compare modes, observe the
following general procedure:
1. Select the module’s mode of operation.
2. Select the input signal for the PCA timer/counter.
3. Load the comparison value into the module’s compare/capture register pair.
4. Set the PCA timer/counter run control bit.
5. After a match causes an interrupt, clear the module’s compare/capture flag.
9.3.3 16-bit Software Timer Mode
To program a compare/capture module for the 16-bit software timer mode (Figure 9-3), set the
ECOMx and MATx bits in the module’s CCAPMx register. Table 9-3 lists the bit combinations
for selecting module modes.
A match between the PCA timer/counter and the compare/capture registers (CCAPxH/CCAPxL)
sets the module’s compare/capture flag (CCFx in the CCON register). This generates an interrupt
request if the corresponding interrupt enable bit (ECCFx in the CCAPMx register) is set. Since
hardware does not clear the compare/capture flag when the interrupt is processed, the user must
clear the flag in software. During the interrupt routine, a new 16-bit compare value can be written
to the compare/capture registers (CCAPxH/CCAPxL).
NOTE
To prevent an invalid match while updating these registers, user software
should write to CCAPxL first, then CCAPxH. A write to CCAPxL clears the
ECOMx bit disabling the compare function, while a write to CCAPxH sets the
ECOMx bit re-enabling the compare function.