PSoC 6 Peripheral Driver Library
Initialization Functions

General Description

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

Functions

cy_en_ctb_status_t Cy_CTB_Init (CTBM_Type *base, const cy_stc_ctb_config_t *config)
 Initialize or restore the CTB and both opamps according to the 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)
 Initialize each opamp separately without impacting analog routing. More...
 
cy_en_ctb_status_t Cy_CTB_DeInit (CTBM_Type *base, bool deInitRouting)
 Reset CTB registers back to power on reset defaults. More...
 
cy_en_ctb_status_t Cy_CTB_FastInit (CTBM_Type *base, const cy_stc_ctb_fast_config_oa0_t *config0, const cy_stc_ctb_fast_config_oa1_t *config1)
 Initialize each opamp of the CTB to one of the common use modes. More...
 
__STATIC_INLINE void Cy_CTB_Enable (CTBM_Type *base)
 Power up the CTB hardware block. More...
 
__STATIC_INLINE void Cy_CTB_Disable (CTBM_Type *base)
 Power down the CTB hardware block. More...
 

Function Documentation

◆ Cy_CTB_Init()

cy_en_ctb_status_t Cy_CTB_Init ( CTBM_Type base,
const cy_stc_ctb_config_t config 
)

Initialize or restore the CTB and both opamps according to the 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
basePointer to structure describing registers
configPointer to structure containing configuration data for entire CTB
Returns
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 10x drive. The terminals are routed to external pins by closing the switches shown.

ctb_init_funcusage.png
/* Scenario: Configure Opamp0 and Opamp1 as follows:
* Opamp0:
* - Mode: Comparator
* - Inverting input: P9.1
* - Non-inverting input: P9.0
* - Comparator output: P9.2 through HSIOM switches
* Opamp1:
* - Mode: Opamp follower with 10x drive
* - Non-inverting input: P9.5
* - Output: P9.3
*
* 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. */
/* Define initialization structure. */
const cy_stc_ctb_config_t config =
{
/* .deepSleep = */ CY_CTB_DEEPSLEEP_DISABLE,
/* Opamp0 configuration */
/* .oa0Power = */ CY_CTB_POWER_MEDIUM,
/* .oa0Mode = */ CY_CTB_MODE_COMP, /* Configure as a comparator. */
/* .oa0Pump = */ CY_CTB_PUMP_ENABLE,
/* .oa0CompEdge = */ CY_CTB_COMP_EDGE_BOTH, /* Both edges of the comparator will trigger an interrupt. */
/* .oa0CompLevel = */ CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL, /* Comparator digital output is synchronized to comparator status. */
/* .oa0CompBypass = */ CY_CTB_COMP_BYPASS_SYNC,
/* .oa0CompHyst = */ CY_CTB_COMP_HYST_10MV, /* Enable 10 mV hysteresis. */
/* .oa0CompIntrEn = */ true, /* Enable interrupt. */
/* Opamp1 configuration */
/* .oa1Power = */ CY_CTB_POWER_MEDIUM,
/* .oa1Mode = */ CY_CTB_MODE_OPAMP10X, /* Configure as an opamp with 10x drive. */
/* .oa1Pump = */ CY_CTB_PUMP_ENABLE,
/* .oaCompEdge = */ CY_CTB_COMP_EDGE_DISABLE, /* Ignore comparator settings. */
/* .oaCompLevel = */ CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL,
/* .oaCompBypass = */ CY_CTB_COMP_BYPASS_SYNC,
/* .oaCompHyst = */ CY_CTB_COMP_HYST_DISABLE,
/* .oa10CompIntrEn = */ false,
/* .configRouting = */ true,
/* .oa0SwitchCtrl = */ (uint32_t) (CY_CTB_SW_OA0_POS_PIN0_MASK | CY_CTB_SW_OA0_NEG_PIN1_MASK), /* Close switches A20 and A11. */
/* .oa1SwitchCtrl = */ (uint32_t) (CY_CTB_SW_OA1_NEG_OUT_MASK | CY_CTB_SW_OA1_OUT_SHORT_1X_10X_MASK | CY_CTB_SW_OA1_POS_PIN5_MASK), /* Close switches A13, A82, and D82. */
/* .ctdSwitchCtrl = */ (uint32_t) CY_CTB_SW_CTD_CHOLD_OA0_POS_ISOLATE_MASK, /* Close switch CIS. */
};
status = Cy_CTB_Init(CTBM0, &config);
/* Route comparator 0 digital output to P9.2 using HSIOM. */
Cy_GPIO_Pin_FastInit(GPIO_PRT9, 2UL, CY_GPIO_DM_STRONG_IN_OFF, 0UL, P9_2_PASS_DSI_CTB_CMP0);
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 
)

Initialize 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
basePointer to structure describing registers
opampNumCY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
configPointer to structure containing configuration data
Returns
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 =
{
/* .deepSleep = */ CY_CTB_DEEPSLEEP_DISABLE,
/* .oaPower = */ CY_CTB_POWER_MEDIUM,
/* .oaMode = */ CY_CTB_MODE_COMP, /* Configure as a comparator. */
/* .oaPump = */ CY_CTB_PUMP_ENABLE,
/* .oaCompEdge = */ CY_CTB_COMP_EDGE_BOTH, /* Both edges of the comparator will trigger an interrupt. */
/* .oaCompLevel = */ CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL, /* Comparator digital output is synchronized to comparator status. */
/* .oaCompBypass = */ CY_CTB_COMP_BYPASS_SYNC,
/* .oaCompHyst = */ CY_CTB_COMP_HYST_10MV, /* Enable 10 mV hysteresis. */
/* .oaCompIntrEn = */ true, /* Enable interrupt. */
};
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 
)

Reset CTB registers back to power on reset defaults.

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

◆ Cy_CTB_FastInit()

cy_en_ctb_status_t Cy_CTB_FastInit ( CTBM_Type base,
const cy_stc_ctb_fast_config_oa0_t config0,
const cy_stc_ctb_fast_config_oa1_t config1 
)

Initialize each opamp of the CTB to one of the common use modes.

This function provides a quick and easy method of configuring the CTB using pre-defined configurations. Only routing switches required for the selected mode are configured, leaving final input and output connections to the user. Additional use modes that relate to the CTDAC are provided to support easy configuration of the CTDAC output buffer and input reference buffer.

The fast configuration structures define the opamp power, mode, and routing. This function sets the other configuration options of the CTB to:

Note
This function call disables a whole CTB block, call Cy_CTB_Enable after this function call.
Parameters
basePointer to structure describing registers
config0Pointer to structure containing configuration data for quick initialization of Opamp0. Defined your own or use one of the provided structures:
config1Pointer to structure containing configuration data for quick initialization of Opamp1. Defined your own or use one of the provided structures:
Returns
Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM
Function Usage
/* Scenario: Quickly configure Opamp0 as a comparator and Opamp1 as an opamp with 10x drive.
* No routing have been established, leaving final input and output connections to the user. */
/* 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. */
if (CY_CTB_SUCCESS == status){
Cy_CTB_Enable(CTBM0);
}
/* Call Cy_CTB_SetAnalogSwitch function to configure routing if desired. */

◆ Cy_CTB_Enable()

__STATIC_INLINE void Cy_CTB_Enable ( CTBM_Type base)

Power up the CTB hardware block.

Parameters
basePointer to structure describing registers
Returns
None

◆ Cy_CTB_Disable()

__STATIC_INLINE void Cy_CTB_Disable ( CTBM_Type base)

Power down the CTB hardware block.

Parameters
basePointer to structure describing registers
Returns
None