* Question
What Are the Functions of the Digital Comparison (DC) Module?
* Answer
The Digital Comparison (DC) module is typically an auxiliary function of a microcontroller’s analog-to-digital converter (ADC). It automatically compares completed ADC conversion results with programmable threshold values and generates an event or interrupt when a selected condition is met.
Monitoring Selected Analog Inputs
The DC module can monitor one or more enabled ADC channels. After the ADC completes a conversion, the digital result is passed to the comparator automatically.
The DC module does not usually initiate sampling or conversion itself. A software command, timer, event, or other ADC trigger is still required.
Comparing Results with Thresholds
Two programmable values define the comparison limits:
- Low threshold
- High threshold
The module can test whether an ADC result is:
- Below the low threshold
- Equal to or above the low threshold
- Below the high threshold
- Equal to or above the high threshold
- Within the window between the low and high thresholds
The exact comparison options depend on the microcontroller.
Generating Interrupts or Events
When the selected comparison condition becomes true, the module can set a status flag and generate an interrupt. The processor therefore does not need to read and compare every ADC sample in software.
This hardware-based monitoring reduces CPU workload and can provide a faster response to threshold crossings.
Identifying the Triggering Input
When several analog channels are monitored, some DC modules record the identifier of the channel that caused the comparison event. Software can then determine which sensor or input crossed its limit before taking the appropriate action.
Supporting Different Data Formats
The threshold values must normally use the same format as the ADC output. Depending on the device, the comparator may support:
- Signed or unsigned results
- Integer or fractional data
- Single-ended or differential ADC measurements
- Different ADC resolutions
Incorrect threshold formatting can cause unexpected comparison results.
Common Applications
Digital comparison is useful for:
- Battery-voltage supervision
- Overvoltage and undervoltage detection
- Temperature-limit monitoring
- Pressure or level alarms
- Current protection
- Sensor-window detection
- Event-driven data acquisition
- Low-CPU-overhead system monitoring
For example, the DC module can generate an interrupt only when a temperature-sensor reading moves outside an acceptable range. The processor can remain available for other work instead of continuously polling the ADC.
Microchip describes its ADC digital comparator as a hardware function that monitors selected conversion results, compares them with programmable upper and lower limits, and generates an interrupt when the configured condition occurs.
