MTB CAT1 Peripheral driver library
Comparator Functions

General Description

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. More...
 
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. More...
 
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. More...
 
uint32_t Cy_CTB_CompGetStatus (const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
 Return the comparator output status. More...
 

Function Documentation

◆ Cy_CTB_CompSetConfig()

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.

Parameters
basePointer to structure describing registers
compNumCY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
levelConfigure output to produce a pulse or level output signal
bypassConfigure output to be clock synchronized or unsynchronized
hystEnable or disable input hysteresis
Returns
None
Function Usage
/* 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. */
/* Configure the comparator properties. */
Cy_CTB_CompSetConfig(CTBM0, CY_CTB_OPAMP_0, level, bypass, hyst);

◆ Cy_CTB_CompGetConfig()

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.

Parameters
basePointer to structure describing registers
compNumCY_CTB_OPAMP_0 or CY_CTB_OPAMP_1
Returns
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
/* 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. */
}

◆ Cy_CTB_CompSetInterruptEdgeType()

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.

Parameters
basePointer to structure describing registers
compNumCY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
edgeEdge type that will trigger an interrupt. Select a value from cy_en_ctb_comp_edge_t.
Returns
None
Function Usage
/* 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);

◆ Cy_CTB_CompGetStatus()

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.

Parameters
basePointer to structure describing registers
compNumCY_CTB_OPAMP_0 or CY_CTB_OPAMP_1. CY_CTB_OPAMP_NONE and CY_CTB_OPAMP_BOTH are invalid options.
Returns
The comparator status. A value of 0 is returned if compNum is invalid.
  • 0: Status is low
  • 1: Status is high
Function Usage
/* 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. */
}