High-Speed Analog Comparator Block Icon
Fast threshold detection and PWM integration for motor control and power applications

Overview

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

Typical Applications

  • Overcurrent Protection: Motor drive current limit detection
  • Overvoltage/Undervoltage: DC bus voltage monitoring
  • Zero-Crossing Detection: AC line synchronization
  • PWM Blanking: Noise immunity during switching
  • Peak Detection: Signal peak monitoring

Device Family Support

dsPIC33EP

1-4 Comparators

dsPIC33EV

1-4 Comparators

dsPIC33CK

1-4 Comparators

dsPIC33CH

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.

Block Parameters

Comparator Enable Configuration

ParameterDescriptionOptions
Comparator 1/2/3/4 EnableEnable or disable each comparator instanceon, off
Comparator PinSelect input pin for positive comparator inputDevice-specific pin list
External Reference PinSelect pin for external voltage reference (negative input)Device-specific pin list or Internal DAC

Reference Voltage Configuration

ParameterDescriptionRange
CMREF (DAC Reference)Internal DAC voltage reference setting0 to 4095 (12-bit)
External Reference RangeVoltage range for external reference inputDevice-specific ranges
External Reference VoltageActual voltage when using external referenceUser-defined (for simulation)

Comparator Operating Mode

ParameterDescriptionOptions
HYSSEL (Hysteresis Select)Hysteresis voltage level for noise immunityNone, 5mV, 10mV, 15mV (device-dependent)
HYSPOL (Hysteresis Polarity)Direction of hysteresis applicationRising edge, Falling edge
COMP (Comparator Mode)Operating mode and speed selectionNormal, High-speed
FLTREN (Filter Enable)Enable digital filtering on outputEnabled, Disabled
DACOE (DAC Output Enable)Enable DAC output to pinEnabled, Disabled
State OutputEnable comparator state output portEnabled, Disabled

Register Configuration

Key Registers

RegisterDescriptionConfigured By
CMxCONComparator x control registerOperating mode, polarity, enable
CMxMSKCONComparator x mask controlPWM blanking configuration
CMxFLTRComparator x filter registerDigital filter settings
CVRCONComparator voltage reference controlInternal DAC configuration
CMxDACComparator x DAC data registerDAC reference voltage value

CMxCON Register Bits (Example)

CMxCON = 0x8000; // Comparator enabled | (CPOL « 13) // Output polarity | (COE « 14) // Output enable | (CREF « 12) // Reference select | (CCH « 0); // Channel select

Practical Examples

Example 1: Motor Overcurrent Protection

Objective:

Implement fast overcurrent detection for a 3-phase motor drive using 3.3V/A current sensing with 2.5A trip threshold.

Configuration:

  • Comparator 1 Enable: on
  • Comparator 1 Pin: AN0 (current sense input)
  • External Reference Pin: Internal DAC
  • CMREF (DAC Value): 2730 (for 2.5A ร— 3.3V/A = 8.25V โ†’ ~2730 @ 12-bit)
  • HYSSEL: 10mV (noise immunity)
  • HYSPOL: Rising edge
  • COMP Mode: High-speed
  • State Output: Enabled โ†’ Connect to PWM Fault Input

Implementation Notes:

// 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

Example 2: DC Bus Overvoltage Detection

Objective:

Monitor DC bus voltage with 400V trip threshold using external voltage divider (100:1 ratio).

Configuration:

  • Comparator 2 Enable: on
  • Comparator 2 Pin: AN1 (DC bus sense, scaled to 0-4V)
  • External Reference Pin: Internal DAC
  • CMREF (DAC Value): 4095 (max for 400V/100 = 4.0V)
  • HYSSEL: 15mV (prevent chattering)
  • HYSPOL: Rising edge
  • FLTREN: Enabled (50ns digital filter)
  • State Output: Enabled โ†’ Feed to fault handler

Hardware Setup:

// 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

Example 3: Zero-Crossing Detection for PFC

Objective:

Detect AC line zero-crossing for Power Factor Correction (PFC) synchronization at 50Hz/60Hz.

Configuration:

  • Comparator 3 Enable: on
  • Comparator 3 Pin: AN2 (AC line sense, isolated and scaled)
  • External Reference Pin: Internal DAC
  • CMREF (DAC Value): 2048 (mid-scale for zero-crossing)
  • HYSSEL: 5mV (tight threshold)
  • HYSPOL: Both edges (detect rising and falling)
  • COMP Mode: High-speed
  • State Output: Enabled โ†’ Trigger interrupt for sync

Signal Processing:

Example 4: Peak Detection with Hysteresis

Objective:

Detect signal peaks for envelope detection in communication or audio applications.

Configuration:

  • Comparator 4 Enable: on
  • Comparator 4 Pin: AN3 (signal input)
  • External Reference Pin: AN4 (tracking reference from RC circuit)
  • HYSSEL: 20mV (prevent multiple triggers)
  • HYSPOL: Rising edge
  • FLTREN: Disabled (preserve fast edges)
  • State Output: Enabled โ†’ Feed to capture module

Application Circuit:

// 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

Integration with PWM Blocks

PWM Fault Input Connection

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)

Blanking Window Integration

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

Troubleshooting

Common Issues and Solutions

IssuePossible CauseSolution
Comparator always triggeredReference voltage too low or input offsetVerify DAC voltage calculation and input signal range
Intermittent false triggersInsufficient hysteresis or noise couplingIncrease HYSSEL value and improve PCB layout
Slow response timeNormal mode selected or filtering enabledSwitch to High-speed mode and disable FLTREN
PWM blanking not workingIncorrect blanking window configurationVerify MASKSEL and BLNKDUR settings
State output not updatingState Output parameter disabledEnable State Output in block parameters
Pin assignment errorsSelected pin not available on deviceCheck MCHP Master block for valid pin options

Debugging Tips

Testing Comparator Operation:

  • Verify Reference Voltage: If DACOE enabled, measure DAC output voltage
  • Monitor State Output: Add LED or scope probe to state output pin
  • Test Hysteresis: Slowly vary input voltage and verify switching thresholds
  • Check Response Time: Use oscilloscope to measure input-to-output delay
  • Validate PWM Integration: Trigger fault and verify PWM shutdown timing

Performance Characteristics

Timing Specifications

ParameterNormal ModeHigh-Speed Mode
Response Time500ns typical100-200ns typical
Propagation Delay300-600ns80-150ns
Current Consumption10ยตA typical50ยตA typical
Input Offset Voltageยฑ5mV typicalยฑ10mV typical
  • [MCHP High-Speed Analog Comparator with Slope Compensation] - Extended version with slope compensation for peak current mode control
  • [MCHP PWM High-Speed] - PWM block with fault input integration
  • [MCHP ADC High-Speed] - Fast ADC for complementary measurements
  • [MCHP Operational Amplifier] - Signal conditioning for comparator inputs

References

  • 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

See Also

Application Notes