# CMPSS Module

The comparator subsystem (CMPSS) API provides a set of functions for programming the digital circuits of a pair of analog comparators. Functions are provided to configure each comparator and its corresponding 12-bit DAC and digital filter and to get both the latched and unlatched status of their output. There are also functions to configure the optional ramp generator circuit and to route incoming sync signals from the ePWM module.

The output signals of the CMPSS (referred to as CTRIPH, CTRIPOUTH, CTRIPL, and CTRIPOUTL) may be routed to GPIOs or other internal destinations using the X-BARs. See the X-BAR driver for details.

group `cmpss_api`

  Defines

  `CMPSS_HICMP_CTL_M` (CMPSS_COMPCTL_COMPHSOURCE

  | \

  CMPSS_COMPCTL_COMPHINV

  | \

  CMPSS_COMPCTL_ASYNCHEN)
  `CMPSS_LOCMP_CTL_M` (CMPSS_COMPCTL_COMPLSOURCE

  | \

  CMPSS_COMPCTL_COMPLINV

  | \

  CMPSS_COMPCTL_ASYNCLEN)
  `CMPSS_INSRC_DAC` 0x0000U

    Input driven by internal DAC.

  `CMPSS_INSRC_PIN` 0x0001U

    Input driven by external pin.

  `CMPSS_INV_INVERTED` 0x0002U

    Comparator output is inverted.

  `CMPSS_OR_ASYNC_OUT_W_FILT` 0x0040U

    Asynch comparator output feeds into OR with latched digital filter output.

  `CMPSS_TRIPOUT_ASYNC_COMP` 0x0000U

    Asynchronous comparator output drives CTRIPOUT.

  `CMPSS_TRIPOUT_SYNC_COMP` 0x0010U

    Synchronous comparator output drives CTRIPOUT.

  `CMPSS_TRIPOUT_FILTER` 0x0020U

    Filter output drives CTRIPOUT.

  `CMPSS_TRIPOUT_LATCH` 0x0030U

    Latched filter output drives CTRIPOUT.

  `CMPSS_TRIP_ASYNC_COMP` 0x0000U

    Asynchronous comparator output drives CTRIP.

  `CMPSS_TRIP_SYNC_COMP` 0x0004U

    Synchronous comparator output drives CTRIP.

  `CMPSS_TRIP_FILTER` 0x0008U

    Filter output drives CTRIP.

  `CMPSS_TRIP_LATCH` 0x000CU

    Latched filter output drives CTRIP.

  `CMPSS_STS_HI_FILTOUT` 0x0001U

    High digital filter output.

  `CMPSS_STS_HI_LATCHFILTOUT` 0x0002U

    Latched value of high digital filter output.

  `CMPSS_STS_LO_FILTOUT` 0x0100U

    Low digital filter output.

  `CMPSS_STS_LO_LATCHFILTOUT` 0x0200U

    Latched value of low digital filter output.

  `CMPSS_DACVAL_SYSCLK` 0x0000U

    DAC value updated from SYSCLK.

  `CMPSS_DACVAL_PWMSYNC` 0x0080U

    DAC value updated from PWMSYNC.

  `CMPSS_DACREF_VDDA` 0x0000U

    VDDA is the voltage reference.

  `CMPSS_DACREF_VDAC` 0x0020U

    VDAC is the voltage reference.

  `CMPSS_DACSRC_SHDW` 0x0000U

    DAC value updated from shadow register.

  `CMPSS_DACSRC_RAMP` 0x0001U

    DAC value is updated from the ramp register.

  Functions

  void `CMPSS_enableModule`(uint32_t base)

    Enables the CMPSS module.

    This function enables the CMPSS module passed into the

    base parameter.
    Parameters

      - `base`: is the base address of the CMPSS module.

    Return

      None.

  void `CMPSS_disableModule`(uint32_t base)

    Disables the CMPSS module.

    This function disables the CMPSS module passed into the

    base parameter.
    Parameters

      - `base`: is the base address of the CMPSS module.

    Return

      None.

  void `CMPSS_configHighComparator`(uint32_t base, uint16_t config)

    Sets the configuration for the high comparator.

    This function configures a comparator. The

    config parameter is the result of a logical OR operation between a CMPSS_INSRC_xxx value and if desired, CMPSS_INV_INVERTED and CMPSS_OR_ASYNC_OUT_W_FILT values.
    Parameters

      - `base`: is the base address of the CMPSS module.

      - `config`: is the configuration of the high comparator.

    The CMPSS_INSRC_xxx term can take on the following values to specify the high comparator negative input source:

    - CMPSS_INSRC_DAC - The internal DAC.

    - CMPSS_INSRC_PIN - An external pin.

    CMPSS_INV_INVERTED may be ORed into config if the comparator output should be inverted.

    CMPSS_OR_ASYNC_OUT_W_FILT may be ORed into config if the asynchronous comparator output should be fed into an OR gate with the latched digital filter output before it is made available for CTRIPH or CTRIPOUTH.

    Return

      None.

  void `CMPSS_configLowComparator`(uint32_t base, uint16_t config)

    Sets the configuration for the low comparator.

    This function configures a comparator. The

    config parameter is the result of a logical OR operation between a CMPSS_INSRC_xxx value and if desired, CMPSS_INV_INVERTED and CMPSS_OR_ASYNC_OUT_W_FILT values.
    Parameters

      - `base`: is the base address of the CMPSS module.

      - `config`: is the configuration of the low comparator.

    The CMPSS_INSRC_xxx term can take on the following values to specify the low comparator negative input source:

    - CMPSS_INSRC_DAC - The internal DAC.

    - CMPSS_INSRC_PIN - An external pin.

    CMPSS_INV_INVERTED may be ORed into config if the comparator output should be inverted.

    CMPSS_OR_ASYNC_OUT_W_FILT may be ORed into config if the asynchronous comparator output should be fed into an OR gate with the latched digital filter output before it is made available for CTRIPL or CTRIPOUTL.

    Return

      None.

  void `CMPSS_configOutputsHigh`(uint32_t base, uint16_t config)

    Sets the output signal configuration for the high comparator.

    This function configures a comparator’s output signals CTRIP and CTRIPOUT. The

    config parameter is the result of a logical OR operation between the CMPSS_TRIPOUT_xxx and CMPSS_TRIP_xxx values.
    Parameters

      - `base`: is the base address of the CMPSS module.

      - `config`: is the configuration of the high comparator output signals.

    The CMPSS_TRIPOUT_xxx term can take on the following values to specify which signal drives CTRIPOUTH:

    - CMPSS_TRIPOUT_ASYNC_COMP - The asynchronous comparator output.

    - CMPSS_TRIPOUT_SYNC_COMP - The synchronous comparator output.

    - CMPSS_TRIPOUT_FILTER - The output of the digital filter.

    - CMPSS_TRIPOUT_LATCH - The latched output of the digital filter.

    The CMPSS_TRIP_xxx term can take on the following values to specify which signal drives CTRIPH:

    - CMPSS_TRIP_ASYNC_COMP - The asynchronous comparator output.

    - CMPSS_TRIP_SYNC_COMP - The synchronous comparator output.

    - CMPSS_TRIP_FILTER - The output of the digital filter.

    - CMPSS_TRIP_LATCH - The latched output of the digital filter.

    Return

      None.

  void `CMPSS_configOutputsLow`(uint32_t base, uint16_t config)

    Sets the output signal configuration for the low comparator.

    This function configures a comparator’s output signals CTRIP and CTRIPOUT. The

    config parameter is the result of a logical OR operation between the CMPSS_TRIPOUT_xxx and CMPSS_TRIP_xxx values.
    Parameters

      - `base`: is the base address of the CMPSS module.

      - `config`: is the configuration of the low comparator output signals.

    The CMPSS_TRIPOUT_xxx term can take on the following values to specify which signal drives CTRIPOUTL:

    - CMPSS_TRIPOUT_ASYNC_COMP - The asynchronous comparator output.

    - CMPSS_TRIPOUT_SYNC_COMP - The synchronous comparator output.

    - CMPSS_TRIPOUT_FILTER - The output of the digital filter.

    - CMPSS_TRIPOUT_LATCH - The latched output of the digital filter.

    The CMPSS_TRIP_xxx term can take on the following values to specify which signal drives CTRIPL:

    - CMPSS_TRIP_ASYNC_COMP - The asynchronous comparator output.

    - CMPSS_TRIP_SYNC_COMP - The synchronous comparator output.

    - CMPSS_TRIP_FILTER - The output of the digital filter.

    - CMPSS_TRIP_LATCH - The latched output of the digital filter.

    Return

      None.

  uint16_t `CMPSS_getStatus`(uint32_t base)

    Gets the current comparator status.

    This function returns the current status for the comparator, specifically the digital filter output and latched digital filter output.

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      Returns the current interrupt status, enumerated as a bit field of the following values:

      - CMPSS_STS_HI_FILTOUT - High digital filter output

      - CMPSS_STS_HI_LATCHFILTOUT - Latched value of high digital filter output

      - CMPSS_STS_LO_FILTOUT - Low digital filter output

      - CMPSS_STS_LO_LATCHFILTOUT - Latched value of low digital filter output

  void `CMPSS_configDAC`(uint32_t base, uint16_t config)

    Sets the configuration for the internal comparator DACs.

    This function configures the comparator’s internal DAC. The

    config parameter is the result of a logical OR operation between the CMPSS_DACVAL_xxx, CMPSS_DACREF_xxx, and CMPSS_DACSRC_xxx.
    Parameters

      - `base`: is the base address of the CMPSS module.

      - `config`: is the configuration of the internal DAC.

    The CMPSS_DACVAL_xxx term can take on the following values to specify when the DAC value is loaded from its shadow register:

    - CMPSS_DACVAL_SYSCLK - Value register updated on system clock.

    - CMPSS_DACVAL_PWMSYNC - Value register updated on PWM sync.

    The CMPSS_DACREF_xxx term can take on the following values to specify which voltage supply is used as reference for the DACs:

    - CMPSS_DACREF_VDDA - VDDA is the voltage reference for the DAC.

    - CMPSS_DACREF_VDAC - VDAC is the voltage reference for the DAC.

    The CMPSS_DACSRC_xxx term can take on the following values to specify the DAC value source for the high comparator’s internal DAC:

    - CMPSS_DACSRC_SHDW - The user-programmed DACVALS register.

    - CMPSS_DACSRC_RAMP - The ramp generator RAMPSTS register

    Note

      The CMPSS_DACVAL_xxx and CMPSS_DACREF_xxx terms apply to both the high and low comparators. CMPSS_DACSRC_xxx will only affect the high comparator’s internal DAC.

    Return

      None.

  void `CMPSS_setDACValueHigh`(uint32_t base, uint16_t value)

    Sets the value of the internal DAC of the high comparator.

    This function sets the 12-bit value driven by the internal DAC of the high comparator. This function will load the value into the shadow register from which the actual DAC value register will be loaded. To configure which event causes this shadow load to take place, use

    CMPSS_configDAC().
    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: is the value actively driven by the DAC.

    Return

      None.

  void `CMPSS_setDACValueLow`(uint32_t base, uint16_t value)

    Sets the value of the internal DAC of the low comparator.

    This function sets the 12-bit value driven by the internal DAC of the low comparator. This function will load the value into the shadow register from which the actual DAC value register will be loaded. To configure which event causes this shadow load to take place, use

    CMPSS_configDAC().
    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: is the value actively driven by the DAC.

    Return

      None.

  void `CMPSS_initFilterHigh`(uint32_t base)

    Initializes the digital filter of the high comparator.

    This function initializes all the samples in the high comparator digital filter to the filter input value.

    Parameters

      - `base`: is the base address of the comparator module.

    Note

      See CMPSS_configFilterHigh() for the proper initialization sequence to avoid glitches.

    Return

      None.

  void `CMPSS_initFilterLow`(uint32_t base)

    Initializes the digital filter of the low comparator.

    This function initializes all the samples in the low comparator digital filter to the filter input value.

    Parameters

      - `base`: is the base address of the comparator module.

    Note

      See CMPSS_configFilterLow() for the proper initialization sequence to avoid glitches.

    Return

      None.

  uint16_t `CMPSS_getDACValueHigh`(uint32_t base)

    Gets the value of the internal DAC of the high comparator.

    This function gets the value of the internal DAC of the high comparator. The value is read from the

    active registernot the shadow register to which CMPSS_setDACValueHigh() writes.
    Parameters

      - `base`: is the base address of the comparator module.

    Return

      Returns the value driven by the internal DAC of the high comparator.

  uint16_t `CMPSS_getDACValueLow`(uint32_t base)

    Gets the value of the internal DAC of the low comparator.

    This function gets the value of the internal DAC of the low comparator. The value is read from the

    active registernot the shadow register to which CMPSS_setDACValueLow() writes.
    Parameters

      - `base`: is the base address of the comparator module.

    Return

      Returns the value driven by the internal DAC of the low comparator.

  void `CMPSS_clearFilterLatchHigh`(uint32_t base)

    Causes a software reset of the high comparator digital filter output latch.

    This function causes a software reset of the high comparator digital filter output latch. It will generate a single pulse of the latch reset signal.

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_clearFilterLatchLow`(uint32_t base)

    Causes a software reset of the low comparator digital filter output latch.

    This function causes a software reset of the low comparator digital filter output latch. It will generate a single pulse of the latch reset signal.

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_setMaxRampValue`(uint32_t base, uint16_t value)

    Sets the ramp generator maximum reference value.

    This function sets the ramp maximum reference value that will be loaded into the ramp generator.

    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: the ramp maximum reference value.

    Return

      None.

  uint16_t `CMPSS_getMaxRampValue`(uint32_t base)

    Gets the ramp generator maximum reference value.

    Return

      Returns the latched ramp maximum reference value that will be loaded into the ramp generator.

    Parameters

      - `base`: is the base address of the comparator module.

  void `CMPSS_setRampDecValue`(uint32_t base, uint16_t value)

    Sets the ramp generator decrement value.

    This function sets the value that is subtracted from the ramp value on every system clock cycle.

    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: is the ramp decrement value.

    Return

      None.

  uint16_t `CMPSS_getRampDecValue`(uint32_t base)

    Gets the ramp generator decrement value.

    Return

      Returns the latched ramp decrement value that is subtracted from the ramp value on every system clock cycle.

    Parameters

      - `base`: is the base address of the comparator module.

  void `CMPSS_setRampDelayValue`(uint32_t base, uint16_t value)

    Sets the ramp generator delay value.

    This function sets the value that configures the number of system clock cycles to delay the start of the ramp generator decrementer after a PWMSYNC event is received. Delay value can be no greater than 8191.

    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: is the 13-bit ramp delay value.

    Return

      None.

  uint16_t `CMPSS_getRampDelayValue`(uint32_t base)

    Gets the ramp generator delay value.

    Return

      Returns the latched ramp delay value that is subtracted from the ramp value on every system clock cycle.

    Parameters

      - `base`: is the base address of the comparator module.

  void `CMPSS_setHysteresis`(uint32_t base, uint16_t value)

    Sets the comparator hysteresis settings.

    This function sets the amount of hysteresis on the comparator inputs. The

    value parameter indicates the amount of hysteresis desired. Passing in 0 results in none, passing in 1 results in typical hysteresis, passing in 2 results in 2x of typical hysteresis, and so on where value x of typical hysteresis is the amount configured.
    Parameters

      - `base`: is the base address of the comparator module.

      - `value`: is the amount of hysteresis on the comparator inputs.

    Return

      None.

  void `CMPSS_enableLatchResetOnPWMSYNCHigh`(uint32_t base)

    Enables reset of HIGH comparator digital filter output latch on PWMSYNC

    This function enables EPWMSYNCPER reset of High comparator digital filter output latch

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_disableLatchResetOnPWMSYNCHigh`(uint32_t base)

    Disables reset of HIGH comparator digital filter output latch on PWMSYNC

    This function disables EPWMSYNCPER reset of High comparator digital filter output latch

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_enableLatchResetOnPWMSYNCLow`(uint32_t base)

    Enables reset of LOW comparator digital filter output latch on PWMSYNC

    This function enables EPWMSYNCPER reset of Low comparator digital filter output latch

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_disableLatchResetOnPWMSYNCLow`(uint32_t base)

    Disables reset of LOW comparator digital filter output latch on PWMSYNC

    This function disables EPWMSYNCPER reset of Low comparator digital filter output latch

    Parameters

      - `base`: is the base address of the comparator module.

    Return

      None.

  void `CMPSS_configFilterHigh`(uint32_t base, uint16_t samplePrescale, uint16_t sampleWindow, uint16_t threshold)

    Configures the digital filter of the high comparator.

    This function configures the operation of the digital filter of the high comparator.

    Parameters

      - `base`: is the base address of the comparator module.

      - `samplePrescale`: is the number of system clock cycles between samples.

      - `sampleWindow`: is the number of FIFO samples to monitor.

      - `threshold`: is the majority threshold of samples to change state.

    The samplePrescale parameter specifies the number of system clock cycles not be passed as this parameter. The prescaler used by digital filter is 1 more than samplePrescale value. So, the input provided should be 1 less than the expected prescaler.

    The sampleWindow parameter configures the size of the window of FIFO samples taken from the input that will be monitored to determine when to change the filter output. This sample window may be no larger than 32 samples.

    The threshold parameter configures the threshold value to be used by the digital filter.

    The filter output resolves to the majority value of the sample window where majority is defined by the value passed into the threshold parameter. For proper operation, the value of threshold must be greater than sampleWindow / 2.

    To ensure proper operation of the filter, the following is the recommended function call sequence for initialization:

    1. Configure and enable the comparator using CMPSS_configHighComparator() and CMPSS_enableModule()

    2. Configure the digital filter using CMPSS_configFilterHigh()

    3. Initialize the sample values using CMPSS_initFilterHigh()

    4. Configure the module output signals CTRIP and CTRIPOUT using CMPSS_configOutputsHigh()

    Return

      None.

  void `CMPSS_configFilterLow`(uint32_t base, uint16_t samplePrescale, uint16_t sampleWindow, uint16_t threshold)

    Configures the digital filter of the low comparator.

    This function configures the operation of the digital filter of the low comparator.

    Parameters

      - `base`: is the base address of the comparator module.

      - `samplePrescale`: is the number of system clock cycles between samples.

      - `sampleWindow`: is the number of FIFO samples to monitor.

      - `threshold`: is the majority threshold of samples to change state.

    The samplePrescale parameter specifies the number of system clock cycles not be passed as this parameter. The prescaler used by digital filter is 1 more than samplePrescale value. So, the input provided should be 1 less than the expected prescaler.

    The sampleWindow parameter configures the size of the window of FIFO samples taken from the input that will be monitored to determine when to change the filter output. This sample window may be no larger than 32 samples.

    The threshold parameter configures the threshold value to be used by the digital filter.

    The filter output resolves to the majority value of the sample window where majority is defined by the value passed into the threshold parameter. For proper operation, the value of threshold must be greater than sampleWindow / 2.

    To ensure proper operation of the filter, the following is the recommended function call sequence for initialization:

    1. Configure and enable the comparator using CMPSS_configLowComparator() and CMPSS_enableModule()

    2. Configure the digital filter using CMPSS_configFilterLow()

    3. Initialize the sample values using CMPSS_initFilterLow()

    4. Configure the module output signals CTRIP and CTRIPOUT using CMPSS_configOutputsLow()

    Return

      None.

  void `CMPSS_configLatchOnPWMSYNC`(uint32_t base, bool highEnable, bool lowEnable)

    Configures whether or not the digital filter latches are reset by PWMSYNC

    This function configures whether or not the digital filter latches in both the high and low comparators should be reset by PWMSYNC. If the

    highEnable parameter is true, the PWMSYNC will be allowed to reset the high comparator’s digital filter latch. If it is false, the ability of the PWMSYNC to reset the latch will be disabled. The lowEnable parameter has the same effect on the low comparator’s digital filter latch.
    Parameters

      - `base`: is the base address of the comparator module.

      - `highEnable`: indicates filter latch settings in the high comparator.

      - `lowEnable`: indicates filter latch settings in the low comparator.

    Return

      None.

  void `CMPSS_configRamp`(uint32_t base, uint16_t maxRampVal, uint16_t decrementVal, uint16_t delayVal, uint16_t pwmSyncSrc, bool useRampValShdw)

    Configures the comparator subsystem’s ramp generator.

    This function configures many of the main settings of the comparator subsystem’s ramp generator. The

    maxRampVal parameter should be passed the ramp maximum reference value that will be loaded into the ramp generator. The decrementVal parameter should be passed the decrement value that will be subtracted from the ramp generator on each system clock cycle. The delayVal parameter should be passed the 13-bit number of system clock cycles the ramp generator should delay before beginning to decrement the ramp generator after a PWMSYNC signal is received.
    Parameters

      - `base`: is the base address of the comparator module.

      - `maxRampVal`: is the ramp maximum reference value.

      - `decrementVal`: value is the ramp decrement value.

      - `delayVal`: is the ramp delay value.

      - `pwmSyncSrc`: is the number of the PWMSYNC source.

      - `useRampValShdw`: indicates if the max ramp shadow should be used.

    These three values may be be set individually using the CMPSS_setMaxRampValue(), CMPSS_setRampDecValue(), and CMPSS_setRampDelayValue() APIs.

    The number of the PWMSYNC signal to be used to reset the ramp generator should be specified by passing it into the pwmSyncSrc parameter. For instance, passing a 2 into pwmSyncSrc will select PWMSYNC2.

    To indicate whether the ramp generator should reset with the value from the ramp max reference value shadow register or with the latched ramp max reference value, use the useRampValShdw parameter. Passing it true will result in the latched value being bypassed. The ramp generator will be loaded right from the shadow register. A value of false will load the ramp generator from the latched value.

    Return

      None.

The two comparators are referred to as the high comparator and the low comparator. Accordingly, many API functions come in pairs with both a “High” and a “Low” version. See the device’s Technical Reference Manual for diagrams showing what resources the comparators share and what they contain separately.

The code for this module is contained in driverlib/cmpss.c, with driverlib/cmpss.h containing the API declarations for use by applications.