Comparator Functions

group group_ctb_functions_comparator

This set of functions are specific to the comparator mode.

Functions

void Cy_CTB_CompSetConfig(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum, cy_en_ctb_comp_level_t level, cy_en_ctb_comp_bypass_t bypass, cy_en_ctb_comp_hyst_t hyst)

Configure the CTB comparator for pulse or level output, to bypass clock synchronization, and to enable hysteresis.

    /* Scenario: Opamp0 has been configured as a comparator instead of an opamp.
     * Configure the comparator such the trigger output signal tracks the comparator output,
     * the comparator output is synchronized for DSI, and hysteresis is enabled. */
    
    cy_en_ctb_comp_level_t level    = CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL;
    cy_en_ctb_comp_bypass_t bypass  = CY_CTB_COMP_BYPASS_SYNC;
    cy_en_ctb_comp_hyst_t hyst      = CY_CTB_COMP_HYST_10MV;
    
    /* Configure the comparator properties. */
    Cy_CTB_CompSetConfig(CTBM0, CY_CTB_OPAMP_0, level, bypass, hyst);
       
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • compNum: CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH

  • level: Configure output to produce a pulse or level output signal

  • bypass: Configure output to be clock synchronized or unsynchronized

  • hyst: Enable or disable input hysteresis

uint32_t Cy_CTB_CompGetConfig(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)

Return the CTB comparator operating configuration as set by Cy_CTB_CompSetConfig.

    /* Scenario: Determine if hysteresis is enabled in Comparator 0. */
    uint32_t compConfig;
    
    compConfig = Cy_CTB_CompGetConfig(CTBM0, CY_CTB_OPAMP_0);
    
    if ((uint32_t) CY_CTB_COMP_HYST_10MV == (compConfig & ((uint32_t) CY_CTB_COMP_HYST_10MV)))
    {
        /* Hysteresis is enabled in Comparator 0. */
    }
Return

The comparator configuration. Compare the register value with the masks in cy_en_ctb_comp_level_t, cy_en_ctb_comp_bypass_t, and cy_en_ctb_comp_hyst_t.

Function Usage

Parameters

void Cy_CTB_CompSetInterruptEdgeType(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum, cy_en_ctb_comp_edge_t edge)

Configure the type of edge that will trigger a comparator interrupt.

    /* Scenario: Configure both edges (rising and falling) to trigger an interrupt in Comparator 0. */
    
    Cy_CTB_CompSetInterruptEdgeType(CTBM0, CY_CTB_OPAMP_0, CY_CTB_COMP_EDGE_BOTH);
Return

None

Function Usage

Parameters

uint32_t Cy_CTB_CompGetStatus(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)

Return the comparator output status.

When the positive input voltage is greater than the negative input voltage, the comparator status is high. Otherwise, the status is low.

    /* Scenario: Get the comparator output status on Comparator 0 to determine
     * the if the positive input voltage is greater than or less than the
     * negative input voltage. */
    uint32_t status;
    
    status = Cy_CTB_CompGetStatus(CTBM0, CY_CTB_OPAMP_0);
    
    if (1UL == status)
    {
        /* Positive input voltage is greater than the negative input voltage. */
    }
    else
    {
        /* Positive input voltage is less than the negative input voltage. */
    }
Return

The comparator status. A value of 0 is returned if compNum is invalid.

  • 0: Status is low

  • 1: Status is high

Function Usage

Parameters