CAT2 Peripheral Driver Library
Initialization Functions

This set of functions is for initializing, enabling, and disabling the CTB. More...

Functions

cy_en_ctb_status_t Cy_CTB_Init (CTBM_Type *base, const cy_stc_ctb_config_t *config)
 Initializes or restores the CTB and both opamps per provided settings. More...
 
cy_en_ctb_status_t Cy_CTB_OpampInit (CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, const cy_stc_ctb_opamp_config_t *config)
 Initializes each opamp separately without impacting analog routing. More...
 
cy_en_ctb_status_t Cy_CTB_DeInit (CTBM_Type *base, bool deInitRouting)
 Resets CTB registers back to power on reset defaults. More...
 
void Cy_CTB_Enable (CTBM_Type *base)
 Powers up the CTB hardware block. More...
 
void Cy_CTB_Disable (CTBM_Type *base)
 Powers down the CTB hardware block. More...
 

Detailed Description

This set of functions is for initializing, enabling, and disabling the CTB.

Function Documentation

◆ Cy_CTB_Init()

cy_en_ctb_status_t Cy_CTB_Init ( CTBM_Type *  base,
const cy_stc_ctb_config_t config 
)

Initializes or restores the CTB and both opamps per provided settings.

Parameters are usually set only once at initialization.

Note
This function call disables a whole CTB block, call Cy_CTB_Enable after this function call.
Parameters
baseThe pointer to structure-describing registers.
configThe pointer to a structure containing configuration data for the entire CTB.
Returns
The status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM
Function Usage
The following code snippet configures Opamp0 as a comparator and Opamp1 as an opamp follower with an external (10x) drive. The terminals are routed to external pins by closing the switches shown.
/* Scenario: Configure Opamp0 and Opamp1 as follows:
* Opamp0:
* - Mode: Comparator
* - Inverting input: P1.1
* - Non-inverting input: P1.6
* - Comparator output: P1.2 through HSIOM switches
* Opamp1:
* - Mode: OpAmp follower with external (10x) drive
* - Non-inverting input: P1.5
* - Output: P1.4
*
* Note: The CTB dedicated port may vary depending on the device.
*/
/* Configure and enable the charge pump clock and analog reference currents
* before using the CTB. See Configuration Dependencies section in the driver overview for more information. */
/* Initialization structure for Opamp0. */
const cy_stc_ctb_opamp_config_t opamp0Config =
{
/* .power = */ CY_CTB_POWER_MEDIUM,
/* .outputMode = */ CY_CTB_MODE_COMP, /* Configure as a comparator. */
/* .pump = */ true,
/* .compEdge = */ CY_CTB_COMP_EDGE_BOTH, /* Both edges of the comparator will trigger an interrupt. */
/* .compLevel = */ CY_CTB_COMP_TRIGGER_OUT_LEVEL, /* Comparator digital output is synchronized to comparator status. */
/* .compBypass = */ true,
/* .compHyst = */ true, /* Enable 10 mV hysteresis. */
/* .compIntrEn = */ true, /* Enable interrupt. */
/* .switchCtrl = */ CY_CTB_SW_OA0_POS_PIN0 | CY_CTB_SW_OA0_NEG_PIN1 /* Close switches A20 and A11. */
};
/* Initialization structure for Opamp1. */
const cy_stc_ctb_opamp_config_t opamp1Config =
{
/* .power = */ CY_CTB_POWER_MEDIUM,
/* .outputMode = */ CY_CTB_MODE_OPAMP_EXTERNAL, /* Configure as an OpAmp with external (10x) drive. */
/* .pump = */ true,
/* .compEdge = */ CY_CTB_COMP_EDGE_DISABLE, /* Ignore comparator settings. */
/* .compLevel = */ CY_CTB_COMP_TRIGGER_OUT_LEVEL, /* Comparator digital output is synchronized to comparator status. */
/* .compBypass = */ true,
/* .compHyst = */ false,
/* .compIntrEn = */ false,
/* .switchCtrl = */ CY_CTB_SW_OA1_NEG_OUT | CY_CTB_SW_OA1_OUT_SHORT_IN_EXT | CY_CTB_SW_OA1_POS_PIN5, /* Close switches A13, A82, and D82. */
};
/* Define initialization structure. */
const cy_stc_ctb_config_t config =
{
/* .deepSleep = */ false,
/* .oa0 = */ &opamp0Config,
/* .oa1 = */ &opamp1Config,
};
status = Cy_CTB_Init(CTBM0, &config);
/* Route comparator 0 digital output to P1.2 using HSIOM. */
Cy_GPIO_Pin_FastInit(GPIO_PRT1, 2UL, CY_GPIO_DM_STRONG_IN_OFF, 0UL, P3_5_GPIO);
if (CY_CTB_SUCCESS == status){
Cy_CTB_Enable(CTBM0);
}

◆ Cy_CTB_OpampInit()

cy_en_ctb_status_t Cy_CTB_OpampInit ( CTBM_Type *  base,
cy_en_ctb_opamp_sel_t  opampNum,
const cy_stc_ctb_opamp_config_t config 
)

Initializes each opamp separately without impacting analog routing.

Intended for use by automatic analog routing and configuration tools to configure each opamp without having to integrate the settings with those of the other opamp first.

Can also be used to configure both opamps to have the same settings.

Parameters
baseThe pointer to structure-describing registers.
opampNumCY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
configThe pointer to a structure containing configuration data.
Returns
The status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM
Function Usage
/* Scenario: Configure Opamp0 as a comparator without touching Opamp1 or any routing. */
/* Configure and enable the charge pump clock and analog reference currents
* before using the CTB. See Configuration Dependencies section in the driver overview for more information. */
cy_en_ctb_status_t opamp0Status;
/* Initialization structure for Opamp0. */
const cy_stc_ctb_opamp_config_t opamp0Config =
{
/* .power = */ CY_CTB_POWER_MEDIUM,
/* .mode = */ CY_CTB_MODE_COMP, /* Configure as a comparator. */
/* .pump = */ true,
/* .compEdge = */ CY_CTB_COMP_EDGE_BOTH, /* Both edges of the comparator will trigger an interrupt. */
/* .compLevel = */ CY_CTB_COMP_TRIGGER_OUT_LEVEL, /* Comparator digital output is synchronized to comparator status. */
/* .compBypass = */ true,
/* .compHyst = */ true, /* Enable 10 mV hysteresis. */
/* .compIntrEn = */ true, /* Enable interrupt. */
/* .switchCtrl = */ 0UL, /* Don't touch routing. */
};
opamp0Status = Cy_CTB_OpampInit(CTBM0, CY_CTB_OPAMP_0, &opamp0Config);
if (CY_CTB_SUCCESS == opamp0Status)
{
/* Turn on the CTB block. */
Cy_CTB_Enable(CTBM0);
/* Call Cy_CTB_SetAnalogSwitch function to configure routing if desired. */
}

◆ Cy_CTB_DeInit()

cy_en_ctb_status_t Cy_CTB_DeInit ( CTBM_Type *  base,
bool  deInitRouting 
)

Resets CTB registers back to power on reset defaults.

Parameters
baseThe pointer to structure-describing registers.
deInitRoutingIf true, all analog routing switches are reset to their default state. If false, analog switch registers are untouched.
Returns
The status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM

◆ Cy_CTB_Enable()

void Cy_CTB_Enable ( CTBM_Type *  base)

Powers up the CTB hardware block.

Parameters
baseThe pointer to structure-describing registers.

◆ Cy_CTB_Disable()

void Cy_CTB_Disable ( CTBM_Type *  base)

Powers down the CTB hardware block.

Parameters
baseThe pointer to structure-describing registers.