The MCHP High-Speed Analog Comparator block configures the on-chip analog comparators for fast threshold detection applications. These comparators provide critical real-time monitoring for motor control overcurrent protection, power supply fault detection, and zero-crossing detection. With response times in the nanosecond range, they can directly trigger PWM fault events without CPU intervention.
Sub-microsecond response time for critical fault protection
Multiple comparator instances (up to 4 per device)
Internal DAC reference or external voltage reference
Programmable hysteresis for noise immunity
Direct PWM fault input integration
Configurable output state monitoring
1-4 Comparators
1-4 Comparators
1-4 Comparators
1-4 Comparators Note: The number of available comparators varies by device. Check the MCHP Master block configuration to see which comparators are available for your selected chip.
| Parameter | Description | Options |
|---|---|---|
| Comparator 1/2/3/4 Enable | Enable or disable each comparator instance | on, off |
| Comparator Pin | Select input pin for positive comparator input | Device-specific pin list |
| External Reference Pin | Select pin for external voltage reference (negative input) | Device-specific pin list or Internal DAC |
| Parameter | Description | Range |
|---|---|---|
| CMREF (DAC Reference) | Internal DAC voltage reference setting | 0 to 4095 (12-bit) |
| External Reference Range | Voltage range for external reference input | Device-specific ranges |
| External Reference Voltage | Actual voltage when using external reference | User-defined (for simulation) |
| Parameter | Description | Options |
|---|---|---|
| HYSSEL (Hysteresis Select) | Hysteresis voltage level for noise immunity | None, 5mV, 10mV, 15mV (device-dependent) |
| HYSPOL (Hysteresis Polarity) | Direction of hysteresis application | Rising edge, Falling edge |
| COMP (Comparator Mode) | Operating mode and speed selection | Normal, High-speed |
| FLTREN (Filter Enable) | Enable digital filtering on output | Enabled, Disabled |
| DACOE (DAC Output Enable) | Enable DAC output to pin | Enabled, Disabled |
| State Output | Enable comparator state output port | Enabled, Disabled |
| Register | Description | Configured By |
|---|---|---|
| CMxCON | Comparator x control register | Operating mode, polarity, enable |
| CMxMSKCON | Comparator x mask control | PWM blanking configuration |
| CMxFLTR | Comparator x filter register | Digital filter settings |
| CVRCON | Comparator voltage reference control | Internal DAC configuration |
| CMxDAC | Comparator x DAC data register | DAC reference voltage value |
CMxCON = 0x8000; // Comparator enabled | (CPOL « 13) // Output polarity | (COE « 14) // Output enable | (CREF « 12) // Reference select | (CCH « 0); // Channel select
Implement fast overcurrent detection for a 3-phase motor drive using 3.3V/A current sensing with 2.5A trip threshold.
// In Simulink model: // 1. Add MCHP_HighSpeed_AnalogComparator block // 2. Connect State Output to PWM_HS block Fault Input // 3. Configure PWM Fault mode: Cycle-by-cycle current limit // 4. Result: Automatic PWM shutdown within 200ns of overcurrent DAC_Voltage = (CMREF / 4095) * Vref; // Calculate threshold // For 8.25V with 3.3V Vref: CMREF = 2730
Monitor DC bus voltage with 400V trip threshold using external voltage divider (100:1 ratio).
// Voltage divider calculation: // DC Bus: 0-450V โ Comparator input: 0-4.5V (via 100:1 divider) // Trip at 400V โ 4.0V at comparator input // CMREF = (4.0V / 3.3V) * 4095 = 4095 (saturated, use 3.3V trip) // Adjust divider for better resolution: // Use 120:1 divider โ 400V = 3.33V // CMREF = (3.33 / 3.3) * 4095 = ~4120 โ Use 4095
Detect AC line zero-crossing for Power Factor Correction (PFC) synchronization at 50Hz/60Hz.
Detect signal peaks for envelope detection in communication or audio applications.
// Peak detector hardware: // 1. Input signal โ AN3 (Comparator positive input) // 2. RC peak detector โ AN4 (Comparator negative input) // 3. Output triggers on signal peak exceeding RC voltage // Hysteresis prevents multiple triggers: // - Rising edge: Trigger when Input > (Reference + 20mV) // - Reset when Input < (Reference - 20mV) // Time constant: ฯ = R ร C // For audio (20Hz-20kHz): ฯ = 10ms โ R=10kฮฉ, C=1ยตF
The comparator output can directly trigger PWM fault events for immediate protection without CPU intervention. Simulink Connection: 1. MCHP_HighSpeed_AnalogComparator [State Output] โ 2. MCHP_PWM_HS [Fault Input Port] PWM Fault Configuration: - Fault Mode: Cycle-by-cycle current limit - Fault Action: Force outputs LOW - Fault Clear: Automatic after fault condition removed - Response Time: < 500ns (hardware-based)
Configure PWM blanking to prevent false triggers during switching transients: CMxMSKCON Configuration: - MASKSEL: Select PWM generator for blanking - BLNKMD: Blanking mode (leading edge, trailing edge, both) - BLNKDUR: Blanking duration (0-4095 cycles) // Example: 2ยตs blanking at 100MHz PWM BLNKDUR = 200; // 2ยตs ร 100MHz = 200 cycles
| Issue | Possible Cause | Solution |
|---|---|---|
| Comparator always triggered | Reference voltage too low or input offset | Verify DAC voltage calculation and input signal range |
| Intermittent false triggers | Insufficient hysteresis or noise coupling | Increase HYSSEL value and improve PCB layout |
| Slow response time | Normal mode selected or filtering enabled | Switch to High-speed mode and disable FLTREN |
| PWM blanking not working | Incorrect blanking window configuration | Verify MASKSEL and BLNKDUR settings |
| State output not updating | State Output parameter disabled | Enable State Output in block parameters |
| Pin assignment errors | Selected pin not available on device | Check MCHP Master block for valid pin options |
Testing Comparator Operation:
| Parameter | Normal Mode | High-Speed Mode |
|---|---|---|
| Response Time | 500ns typical | 100-200ns typical |
| Propagation Delay | 300-600ns | 80-150ns |
| Current Consumption | 10ยตA typical | 50ยตA typical |
| Input Offset Voltage | ยฑ5mV typical | ยฑ10mV typical |
Device Datasheet: Comparator module electrical specifications
Family Reference Manual: Comparator module detailed operation
Application Notes:
[AN1106] - Comparator-Based PWM Fault Protection
[AN2743] - Peak Current Mode Control with Slope Compensation
Code Examples: Check MCHP Blockset examples folder for motor control applications