17.4.6 Comparator

Each ADC channel has a dedicated digital comparator that compares each conversion result from ADnCHxRES register or the channel data from ADnCHxDATA register with thresholds stored in the ADnCHxCMPLO and ADnCHxCMPHI registers. The comparator source selection between ADnCHxRES and ADnCHxDATA registers is controlled by CMPVAL bit (ADnCHxCON2[29]). When CMPVAL bit is zero, the ADnCHxRES register is used, and when CMPVAL bit is set, the ADnCHxDATA register is selected for the comparator operation. The following comparison criteria can be set by the CMPMOD[2:0] bits (ADnCHxCON2[14:12]):

  • Out of bounds (CMPMOD[2:0] bits = ‘001’) when the comparator data source is less than ADnCHxCMPLO or greater than ADnCHxCMPHI.
  • In bounds (CMPMOD[2:0] bits = ‘010’) when the comparator data source is greater or equal to ADnCHxCMPLO and less or equal to ADnCHxCMPHI.
  • Greater than (CMPMOD[2:0] bits = ‘011’) when the comparator data source is greater or equal to ADnCHxCMPLO.
  • Less or equal (CMPMOD[2:0] bits = ‘100’) when the comparator data source is less or equal to ADnCHxCMPLO.
For all other CMPMOD[2:0] bits options the digital comparator is disabled.

Each channel can be programmed to generate the comparator interrupt upon a set number of the criteria match events. The number of the match events is set by ADCMPCNT[9:0] bits (ADnCHxCON2[9:0]). The ADCMPSTAT[9:0] bits (ADnCHxCON2[25:16]) hold the current number the match events occurred. The comparator can count consecutive or accumulative match events. This is selected by CMPCNTMOD bit (ADnCHxCON2[28]). If the CMPCNTMOD bit is zero, then the comparator will generate an event only when a number of consecutive match events is detected. If the CMPCNTMOD bit is set, then the comparator will accumulate/count the match events and generate the interrupt when the event number will exceed the number programmed in ADCMPCNT[9:0] bits. When the comparison match event is detected, the corresponding channel CMPxFLG bit in ADnCMPSTAT register and the ADnCMPxIF interrupt flag are set.