Datasheet

2012 Microchip Technology Inc. DS30575A-page 471
PIC18F97J94 FAMILY
22.7.4 THRESHOLD DETECT
INTERRUPTS
The A/D module can generate an interrupt and set the
ADIF flag based on Threshold Detect operation. This
is based on completion of a Threshold Detect
sequence and/or the occurrence of a valid compari-
son. When Threshold Detect is enabled (ASENA = 1),
A/D module interrupt generation is governed by the
ASINTMDx bits (ADCON5H<1:0>), superseding any
configuration implemented by the SMPIx bits
(ADCON2L<6:2>). For information on alternative
interrupt settings, refer to Section 22.6.1 “Number of
Conversions Per Interrupt”.
The Threshold Detect interrupt is configured by the
ASINTMD<1:0> bits (ADCON5H<1:0>). Options
include interrupt after a scan sequence, interrupt after
a scan sequence with a valid match, interrupt after a
valid match (without waiting for the sequence to end) or
no interrupt.
22.7.5 COMPARISON MODE EXAMPLES
The following examples show the effect of valid
comparisons on the results buffer and the
Compare Hit registers. In each figure, changes within
the registers are indicated in bold.
For the sake of simplicity, the examples assume a
device with only 16 analog inputs. Devices with a
greater number of channels, and thus, larger results
buffers and two Compare Hit registers, will function in a
similar fashion.
22.7.5.1 Simple Comparisons (Greater And
Less Than Results)
When the Compare Mode bits, CM<1:0>
(ADCON5L<1:0>), are programmed as '0x', the
converter compares the sampled value to see if it is
greater than (CM<1:0> = 01), or less than (CM<1:0> =
00), the threshold value in the buffer location. If the
condition is met, both of the following occur:
The Compare Hit bit (CHHn) for the correspond-
ing channel is set.
If the Write Mode bits, WM<1:0>
(ADCON5L<3:2>), are programmed to '01', the
converted value is written to the buffer, replacing
the threshold value. If WM<1:0> = 10, the
converted value is discarded.
The changes to the result buffer and the Compare Hit
register are shown in Figure 22-13. Note that they are
the same for both types of simple comparison.
Note: When using any comparison mode,
always use channel indexed buffer
storage (BUFREGEN = 1). Otherwise,
the threshold values for other channels
may be overwritten, resulting in
unpredictable comparisons.