cy_ctb_8h¶
Header file for the CTB driver
- Version
2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
- Copyright
Copyright 2017-2020 Cypress Semiconductor Corporation SPDX-License-Identifier: Apache-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defines
-
CY_CTB_DRV_VERSION_MAJOR
¶ Driver major version.
-
CY_CTB_DRV_VERSION_MINOR
¶ Driver minor version.
-
CY_CTB_ID
¶ CTB driver identifier.
Enums
-
enum
cy_en_ctb_opamp_sel_t
¶ cy_en_ctb_opamp_sel_t: Most functions allow you to configure a single opamp or both opamps at once.
The Cy_CTB_SetInterruptMask function can be called with CY_CTB_OPAMP_NONE and interrupts will be disabled.
Values:
-
enumerator
CY_CTB_OPAMP_NONE
¶ For disabling interrupts for both opamps.
Used with Cy_CTB_SetInterruptMask
-
enumerator
CY_CTB_OPAMP_0
¶ For configuring Opamp0.
-
enumerator
CY_CTB_OPAMP_1
¶ For configuring Opamp1.
-
enumerator
CY_CTB_OPAMP_BOTH
¶ For configuring both Opamp0 and Opamp1.
-
enumerator
-
enum
cy_en_ctb_deep_sleep_t
¶ cy_en_ctb_deep_sleep_t: Enable or disable CTB while in Deep Sleep mode.
Values:
-
enumerator
CY_CTB_DEEPSLEEP_DISABLE
¶ CTB is disabled during Deep Sleep power mode.
-
enumerator
CY_CTB_DEEPSLEEP_ENABLE
¶ CTB remains enabled during Deep Sleep power mode.
-
enumerator
-
enum
cy_en_ctb_power_t
¶ cy_en_ctb_power_t: Configure the power mode of each opamp.
Each power setting consumes different levels of current and supports a different input range and gain bandwidth.
Opamp Power
IDD
Gain bandwidth
OFF
0
NA
LOW
350 uA
1 MHz
MEDIUM
600 uA
3 MHz for 1X, 2.5 MHz for 10x
HIGH
1.5 mA
8 MHz for 1X, 6 MHz for 10x
Values:
-
enumerator
CY_CTB_POWER_OFF
¶ Opamp is off.
-
enumerator
CY_CTB_POWER_LOW
¶ Low power: IDD = 350 uA, GBW = 1 MHz for both 1x and 10x.
-
enumerator
CY_CTB_POWER_MEDIUM
¶ Medium power: IDD = 600 uA, GBW = 3 MHz for 1x and 2.5 MHz for 10x.
-
enumerator
CY_CTB_POWER_HIGH
¶ High power: IDD = 1500 uA, GBW = 8 MHz for 1x and 6 MHz for 10x.
-
enumerator
-
enum
cy_en_ctb_mode_t
¶ cy_en_ctb_mode_t: The output stage of each opamp can be configured for low-drive strength (1X) to drive internal circuits, for high-drive strength (10X) to drive external circuits, or as a comparator.
Values:
-
enumerator
CY_CTB_MODE_OPAMP1X
¶ Configure opamp for low drive strength for internal connections (1x)
-
enumerator
CY_CTB_MODE_OPAMP10X
¶ Configure opamp high drive strength for driving a device pin (10x)
-
enumerator
CY_CTB_MODE_COMP
¶ Configure opamp as a comparator.
-
enumerator
-
enum
cy_en_ctb_pump_t
¶ cy_en_ctb_pump_t: Each opamp has a charge pump to increase the input range to the rails.
When the charge pump is enabled, the input range is 0 to VDDA. When disabled, the input range is 0 to VDDA - 1.5 V.
Charge Pump
Input Range (V)
OFF
0 to VDDA-1.5
ON
0 to VDDA
Note that in Deep Sleep mode, the charge pump is disabled so the input range is reduced.
Values:
-
enumerator
CY_CTB_PUMP_DISABLE
¶ Charge pump is disabled for an input range of 0 to VDDA - 1.5 V.
-
enumerator
CY_CTB_PUMP_ENABLE
¶ Charge pump is enabled for an input range of 0 to VDDA.
-
enumerator
-
enum
cy_en_ctb_comp_edge_t
¶ cy_en_ctb_comp_edge_t: Configure the type of edge that will trigger a comparator interrupt or disable the interrupt entirely.
Values:
-
enumerator
CY_CTB_COMP_EDGE_DISABLE
¶ Disabled, no interrupts generated.
-
enumerator
CY_CTB_COMP_EDGE_RISING
¶ Rising edge generates an interrupt.
-
enumerator
CY_CTB_COMP_EDGE_FALLING
¶ Falling edge generates an interrupt.
-
enumerator
CY_CTB_COMP_EDGE_BOTH
¶ Both edges generate an interrupt.
-
enumerator
-
enum
cy_en_ctb_comp_level_t
¶ cy_en_ctb_comp_level_t: Configure the comparator DSI trigger output level when output is synchronized.
Values:
-
enumerator
CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE
¶ Send pulse on DSI for each edge of comparator output.
-
enumerator
CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL
¶ DSI output is synchronized version of comparator output.
-
enumerator
-
enum
cy_en_ctb_comp_bypass_t
¶ cy_en_ctb_comp_bypass_t: Bypass the comparator output synchronization for DSI trigger.
Values:
-
enumerator
CY_CTB_COMP_BYPASS_SYNC
¶ Comparator output is synchronized for DSI trigger.
-
enumerator
CY_CTB_COMP_BYPASS_NO_SYNC
¶ Comparator output is not synchronized for DSI trigger.
-
enumerator
-
enum
cy_en_ctb_comp_hyst_t
¶ cy_en_ctb_comp_hyst_t: Disable or enable the 10 mV hysteresis for the comparator.
Values:
-
enumerator
CY_CTB_COMP_HYST_DISABLE
¶ Disable hysteresis.
-
enumerator
CY_CTB_COMP_HYST_10MV
¶ Enable the 10 mV hysteresis.
-
enumerator
-
enum
cy_en_ctb_switch_state_t
¶ cy_en_ctb_switch_state_t: Switch state, either open or closed, to be used in Cy_CTB_SetAnalogSwitch.
Values:
-
enumerator
CY_CTB_SWITCH_OPEN
¶ Open the switch.
-
enumerator
CY_CTB_SWITCH_CLOSE
¶ Close the switch.
-
enumerator
-
enum
cy_en_ctb_switch_register_sel_t
¶ cy_en_ctb_switch_register_sel_t: The switch register to be used in Cy_CTB_SetAnalogSwitch.
The CTB has three registers for configuring the switch routing matrix.
Values:
-
enumerator
CY_CTB_SWITCH_OA0_SW
¶ Switch register for Opamp0.
-
enumerator
CY_CTB_SWITCH_OA1_SW
¶ Switch register for Opamp1.
-
enumerator
CY_CTB_SWITCH_CTD_SW
¶ Switch register for CTDAC routing.
-
enumerator
-
enum
cy_en_ctb_oa0_switches_t
¶ cy_en_ctb_oa0_switches_t: Switch masks for Opamp0 to be used in Cy_CTB_SetAnalogSwitch.
Values:
-
enumerator
CY_CTB_SW_OA0_POS_AMUXBUSA_MASK
¶ Switch A00: Opamp0 non-inverting input to AMUXBUS A.
-
enumerator
CY_CTB_SW_OA0_POS_PIN0_MASK
¶ Switch A20: Opamp0 non-inverting input to Pin 0 of CTB device port.
-
enumerator
CY_CTB_SW_OA0_POS_PIN6_MASK
¶ Switch A30: Opamp0 non-inverting input to Pin 6 of CTB device port.
-
enumerator
CY_CTB_SW_OA0_NEG_PIN1_MASK
¶ Switch A11: Opamp0 inverting input to Pin 1 of CTB device port.
-
enumerator
CY_CTB_SW_OA0_NEG_OUT_MASK
¶ Switch A81: Opamp0 inverting input to Opamp0 output.
-
enumerator
CY_CTB_SW_OA0_OUT_SARBUS0_MASK
¶ Switch D51: Opamp0 output to sarbus0.
-
enumerator
CY_CTB_SW_OA0_OUT_SHORT_1X_10X_MASK
¶ Switch D81: Short Opamp0 1x with 10x outputs.
-
enumerator
-
enum
cy_en_ctb_oa1_switches_t
¶ cy_en_ctb_oa1_switches_t: Switch masks for Opamp1 to be used in Cy_CTB_SetAnalogSwitch.
Values:
-
enumerator
CY_CTB_SW_OA1_POS_AMUXBUSB_MASK
¶ Switch A03: Opamp1 non-inverting input to AMUXBUS B.
-
enumerator
CY_CTB_SW_OA1_POS_PIN5_MASK
¶ Switch A13: Opamp1 non-inverting input to Pin 5 of CTB device port.
-
enumerator
CY_CTB_SW_OA1_POS_PIN7_MASK
¶ Switch A43: Opamp1 non-inverting input to Pin 7 of CTB device port.
-
enumerator
CY_CTB_SW_OA1_POS_AREF_MASK
¶ Switch A73: Opamp1 non-inverting input to device Analog Reference (AREF)
-
enumerator
CY_CTB_SW_OA1_NEG_PIN4_MASK
¶ Switch A22: Opamp1 inverting input to Pin 4 of CTB device port.
-
enumerator
CY_CTB_SW_OA1_NEG_OUT_MASK
¶ switch A82: Opamp1 inverting input to Opamp1 output
-
enumerator
CY_CTB_SW_OA1_OUT_SARBUS0_MASK
¶ Switch D52: Opamp1 output to sarbus0.
-
enumerator
CY_CTB_SW_OA1_OUT_SARBUS1_MASK
¶ Switch D62: Opamp1 output to sarbus1.
-
enumerator
CY_CTB_SW_OA1_OUT_SHORT_1X_10X_MASK
¶ Switch D82: Short Opamp1 1x with 10x outputs.
-
enumerator
-
enum
cy_en_ctb_ctd_switches_t
¶ cy_en_ctb_ctd_switches_t: Switch masks for CTDAC to CTB routing to be used in Cy_CTB_SetAnalogSwitch.
Values:
-
enumerator
CY_CTB_SW_CTD_REF_OA1_OUT_MASK
¶ Switch CRD: Opamp1 output to CTDAC reference.
-
enumerator
CY_CTB_SW_CTD_REFSENSE_OA1_NEG_MASK
¶ Switch CRS: CTDAC reference sense to Opamp1 inverting input.
-
enumerator
CY_CTB_SW_CTD_OUT_OA1_NEG_MASK
¶ Switch COR: CTDAC output to Opamp1 inverting input.
-
enumerator
CY_CTB_SW_CTD_OUT_PIN6_MASK
¶ Switch C6H: CTDAC output to P6 of CTB device port.
-
enumerator
CY_CTB_SW_CTD_OUT_CHOLD_MASK
¶ Switch COS: CTDAC output to hold cap (deglitch capable).
-
enumerator
CY_CTB_SW_CTD_OUT_OA0_1X_OUT_MASK
¶ Switch COB: Drive CTDAC output with opamp0 1x output during hold mode.
-
enumerator
CY_CTB_SW_CTD_CHOLD_CONNECT_MASK
¶ Switch CHD: Hold cap connection.
-
enumerator
CY_CTB_SW_CTD_CHOLD_OA0_POS_MASK
¶ Switch CA0: Hold cap to Opamp0 non-inverting input.
-
enumerator
CY_CTB_SW_CTD_CHOLD_OA0_POS_ISOLATE_MASK
¶ Switch CIS: Opamp0 non-inverting input isolation (for hold cap)
-
enumerator
CY_CTB_SW_CTD_CHOLD_LEAKAGE_REDUCTION_MASK
¶ Switch ILR: Hold cap leakage reduction (drives far side of isolation switch CIS)
-
enumerator
-
enum
cy_en_ctb_switch_sar_seq_t
¶ cy_en_ctb_switch_sar_seq_t: Masks for CTB switches that can be controlled by the SAR sequencer.
These masks are used in Cy_CTB_EnableSarSeqCtrl and Cy_CTB_DisableSarSeqCtrl.
The SAR ADC subsystem supports analog routes through three CTB switches on SARBUS0 and SARBUS1. This control allows for pins on the CTB dedicated port to route to the SAR ADC input channels:
D51: Connects the inverting terminal of OA0 to SARBUS0
D52: Connects the inverting terminal of OA1 to SARBUS0
D62: Connects the inverting terminal of OA1 to SARBUS1
Values:
-
enumerator
CY_CTB_SW_SEQ_CTRL_D51_MASK
¶ Enable SAR sequencer control of the D51 switch.
-
enumerator
CY_CTB_SW_SEQ_CTRL_D52_D62_MASK
¶ Enable SAR sequencer control of the D52 and D62 switches.
-
enumerator
CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK
¶ Enable SAR sequencer control of all three switches.
-
enum
cy_en_ctb_compensation_cap_t
¶ cy_en_ctb_compensation_cap_t: Each opamp also has a programmable compensation capacitor block, that optimizes the stability of the opamp performance based on output load.
The compensation cap will be set by the driver based on the opamp drive strength (1x or 10x) selection.
Values:
-
enumerator
CY_CTB_OPAMP_COMPENSATION_CAP_OFF
¶ No compensation.
-
enumerator
CY_CTB_OPAMP_COMPENSATION_CAP_MIN
¶ Minimum compensation - for 1x drive.
-
enumerator
CY_CTB_OPAMP_COMPENSATION_CAP_MED
¶ Medium compensation.
-
enumerator
CY_CTB_OPAMP_COMPENSATION_CAP_MAX
¶ Maximum compensation - for 10x drive.
-
enumerator
-
enum
cy_en_ctb_boost_en_t
¶ cy_en_ctb_boost_en_t: Enable or disable the gain booster.
The gain booster will be set by the driver based on the opamp drive strength (1x or 10x) selection.
Values:
-
enumerator
CY_CTB_OPAMP_BOOST_DISABLE
¶ Disable gain booster - for 10x drive.
-
enumerator
CY_CTB_OPAMP_BOOST_ENABLE
¶ Enable gain booster - for 1x drive.
-
enumerator
-
enum
cy_en_ctb_sample_hold_mode_t
¶ cy_en_ctb_sample_hold_mode_t: Sample and hold modes for firmware sampling of the CTDAC output.
To perform a sample or a hold, a preparation step must first be executed to open the required switches.
Call Cy_CTB_DACSampleAndHold with CY_CTB_SH_PREPARE_SAMPLE or CY_CTB_SH_PREPARE_HOLD
Enable or disable CTDAC output
Call Cy_CTB_DACSampleAndHold with CY_CTB_SH_SAMPLE or CY_CTB_SH_HOLD
Values:
-
enumerator
CY_CTB_SH_DISABLE
¶ The hold capacitor is not connected - this disables sample and hold.
-
enumerator
CY_CTB_SH_PREPARE_SAMPLE
¶ Prepares the required switches for a following sample.
-
enumerator
CY_CTB_SH_SAMPLE
¶ Performs a sample of the voltage.
-
enumerator
CY_CTB_SH_PREPARE_HOLD
¶ Prepares the required switches for a following hold.
-
enumerator
CY_CTB_SH_HOLD
¶ Performs a hold of the previously sampled voltage.
-
enum
cy_en_ctb_iptat_t
¶ cy_en_ctb_iptat_t: AREF IPTAT bias current output for the CTB.
The CTB bias current can be 1 uA (normal) or 100 nA (low current).
Values:
-
enumerator
CY_CTB_IPTAT_NORMAL
¶ 1 uA bias current to the CTB
-
enumerator
CY_CTB_IPTAT_LOW
¶ 100 nA bias current to the CTB
-
enumerator
-
enum
cy_en_ctb_clk_pump_source_t
¶ cy_en_ctb_clk_pump_source_t: CTB charge pump clock sources.
The CTB pump clock can come from:
a dedicated divider clock in the SRSS
one of the CLK_PERI dividers
Values:
-
enumerator
CY_CTB_CLK_PUMP_SRSS
¶ Use the dedicated pump clock from SRSSp.
-
enumerator
CY_CTB_CLK_PUMP_PERI
¶ Use one of the CLK_PERI dividers.
-
enumerator
CY_CTB_CLK_PUMP_DEEPSLEEP
¶ Use the Deep Sleep Clock (Deep Sleep Clock) - applicable for PASS_v2 only.
-
enum
cy_en_ctb_current_mode_t
¶ cy_en_ctb_current_mode_t: High level opamp current modes.
Values:
-
enumerator
CY_CTB_CURRENT_HIGH_ACTIVE
¶ Uses 1 uA reference current with charge pump enabled.
Available in Active and Low Power
-
enumerator
CY_CTB_CURRENT_HIGH_ACTIVE_DEEPSLEEP
¶ Uses 1 uA reference current with charge pump disabled.
Available in all power modes
-
enumerator
CY_CTB_CURRENT_LOW_ACTIVE_DEEPSLEEP
¶ Uses 100 nA reference current with charge pump disabled.
Available in all power modes
-
enumerator
-
enum
cy_en_ctb_status_t
¶ cy_en_ctb_status_t: Return states for Cy_CTB_Init, Cy_CTB_OpampInit, Cy_CTB_DeInit, and Cy_CTB_FastInit.
Values:
-
enumerator
CY_CTB_SUCCESS
¶ Initialization completed successfully.
-
enumerator
CY_CTB_BAD_PARAM
¶ Input pointers were NULL and initialization could not be completed.
-
enumerator
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.
Parameters are usually set only once, at initialization.
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.note
This function call disables a whole CTB block, call Cy_CTB_Enable after this function call.
- Function Usage
/* 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. */ cy_en_ctb_status_t status; /* 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); }
- Parameters
base – Pointer to structure describing registers
config – Pointer to structure containing configuration data for entire CTB
- Returns
Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM
-
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.
/* 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. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
config – Pointer to structure containing configuration data
- Returns
Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM
-
cy_en_ctb_status_t
Cy_CTB_DeInit
(CTBM_Type *base, bool deInitRouting) Reset CTB registers back to power on reset defaults.
- Parameters
base – Pointer to structure describing registers
deInitRouting – If 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_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:
.deepSleep = CY_CTB_DEEPSLEEP_DISABLE
.oaPump = CY_CTB_PUMP_ENABLE
.oaCompEdge = CY_CTB_COMP_EDGE_BOTH
.oaCompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL
.oaCompBypass = CY_CTB_COMP_BYPASS_SYNC
.oaCompHyst = CY_CTB_COMP_HYST_10MV
.oaCompIntrEn = true
note
This function call disables a whole CTB block, call Cy_CTB_Enable after this function call.
/* 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. */ cy_en_ctb_status_t status; status = Cy_CTB_FastInit(CTBM0, &Cy_CTB_Fast_Opamp0_Comp, &Cy_CTB_Fast_Opamp1_Opamp10x); if (CY_CTB_SUCCESS == status){ Cy_CTB_Enable(CTBM0); } /* Call Cy_CTB_SetAnalogSwitch function to configure routing if desired. */
- Function Usage
- Parameters
base – Pointer to structure describing registers
config0 – Pointer to structure containing configuration data for quick initialization of Opamp0. Defined your own or use one of the provided structures:
config1 – Pointer 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
-
void
Cy_CTB_Enable
(CTBM_Type *base) Power up the CTB hardware block.
- Parameters
base – Pointer to structure describing registers
- Returns
None
-
void
Cy_CTB_Disable
(CTBM_Type *base) Power down the CTB hardware block.
- Parameters
base – Pointer to structure describing registers
- Returns
None
-
void
Cy_CTB_SetDeepSleepMode
(CTBM_Type *base, cy_en_ctb_deep_sleep_t deepSleep) Enable or disable the entire CTB (not per opamp) in Deep Sleep mode.
If enabled, the AREF block must also be enabled for Deep Sleep to provide the needed reference currents to the opamps (see Cy_SysAnalog_SetDeepSleepMode). Additionally, ensure that only internal CTB switches are used for routing. Switches on AMUXBUSA and AMUXBUSB are not enabled in Deep Sleep. See the Configuration Dependencies section for more information.
note
In Deep Sleep mode, the charge pumps are disabled so the input range of the opamps is reduced to 0 V to VDDA - 1.5 V.
/* Scenario: The opamps are no longer needed to function in Deep Sleep mode * so disable Deep Sleep operation. */ Cy_CTB_SetDeepSleepMode(CTBM0, CY_CTB_DEEPSLEEP_DISABLE); /* This is a low level function that only configures the CTB block. * The preferred method is the Cy_CTB_SetCurrentMode() as it is a high * level function that configures both the CTB and the AREF block. */
- Function Usage
- Parameters
base – Pointer to structure describing registers
deepSleep – CY_CTB_DEEPSLEEP_DISABLE or CY_CTB_DEEPSLEEP_ENABLE from cy_en_ctb_deep_sleep_t.
- Returns
None
-
void
Cy_CTB_SetOutputMode
(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_mode_t mode) Set the opamp output mode to 1x drive, 10x drive, or comparator mode.
/* Scenario: Start using Opamp0 as a comparator instead of an opamp by * turning off the 1x and 10x output stages. The comparator functionality * has already been configured with Cy_CTB_CompSetConfig() or during initialization. */ Cy_CTB_SetOutputMode(CTBM0, CY_CTB_OPAMP_0, CY_CTB_MODE_COMP);
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
mode – Opamp mode selection. Select a value from cy_en_ctb_mode_t.
- Returns
None
-
void
Cy_CTB_SetPower
(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_power_t power, cy_en_ctb_pump_t pump) Configure the power level and charge pump for a specific opamp.
At higher power levels, the opamp consumes more current but provides more gain bandwidth. Enabling the charge pump increases current but provides rail-to-rail input range. Disabling the charge pump limits the input range to VDDA - 1.5 V. See the device datasheet for performance specifications.
/* Scenario: Opamp0 is no longer needed so turn it off to save power. * Opamp1 is still being used but the full input range and bandwidth is not needed * so turn off the charge pump and reduce the power level to medium to save power. */ Cy_CTB_SetPower(CTBM0, CY_CTB_OPAMP_0, CY_CTB_POWER_OFF, CY_CTB_PUMP_DISABLE); Cy_CTB_SetPower(CTBM0, CY_CTB_OPAMP_1, CY_CTB_POWER_MEDIUM, CY_CTB_PUMP_DISABLE);
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
power – Power mode selection. Select a value from cy_en_ctb_power_t.
pump – Enable or disable the charge pump. Select a value from cy_en_ctb_pump_t.
- Returns
None
-
void
Cy_CTB_DACSampleAndHold
(CTBM_Type *base, cy_en_ctb_sample_hold_mode_t mode) Perform sampling and holding of the CTDAC output.
To perform a sample or a hold, a preparation step must first be executed to open the required switches. Because of this, each sample or hold requires three function calls:
Call this function to prepare for a sample or hold
Enable or disable the CTDAC output
Call this function again to perform a sample or hold
It takes 10 us to perform a sample of the CTDAC output to provide time for the capacitor to settle to the new value.
/* Scenario: Opamp0 has been configured as a buffer for the CTDAC output * with the sample and hold (S/H) capacitor connected. * This code samples the CTDAC output once. */ /* Prepare for sample. */ Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_PREPARE_SAMPLE); /* Turn on DAC output. */ Cy_CTDAC_SetOutputMode(CTDAC0, CY_CTDAC_OUTPUT_VALUE); /* Sample DAC output. */ Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_SAMPLE); /* Allow time for voltage to settle across the hold capacitor. */ Cy_SysLib_DelayUs(10);
/* Scenario: Turn off the CTDAC output to save power and * hold the output voltage across the S/H capcitor. * The DAC output needs to be turned on and sampled periodically. * See the device datasheet for the hold duration. */ /* Prepare for hold. */ Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_PREPARE_HOLD); /* Turn off DAC output. */ Cy_CTDAC_SetOutputMode(CTDAC0, CY_CTDAC_OUTPUT_HIGHZ); /* Hold voltage. */ Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_HOLD);
- Function Usage
- Function Usage
- Parameters
base – Pointer to structure describing registers
mode – Mode to prepare or perform a sample or hold, or disable the ability
- Returns
None
-
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);
- 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
- Returns
None
-
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. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_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.
-
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);
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
edge – Edge type that will trigger an interrupt. Select a value from cy_en_ctb_comp_edge_t.
- Returns
None
-
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. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_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
-
void
Cy_CTB_OpampSetOffset
(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint32_t trim) Override the CTB opamp offset factory trim.
The trim is a six bit value and the MSB is a direction bit.
Bit 5
Bits 4:0
Note
0
00000
Negative trim direction - minimum setting
0
11111
Negative trim direction - maximum setting
1
00000
Positive trim direction - minimum setting
1
11111
Positive trim direction - maximum setting
/* Scenario: Calibrate the offset trim by iterating through all the possible trim values. */ uint8_t trim; for (trim = 0u; trim <= 0x3F; trim++) { Cy_CTB_OpampSetOffset(CTBM0, CY_CTB_OPAMP_0, trim); /* Do something after changing the offset trim. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
trim – Trim value from 0 to 63
- Returns
None
-
uint32_t
Cy_CTB_OpampGetOffset
(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum) Return the current CTB opamp offset trim value.
/* Scenario: Save the factory offset trim before changing it. */ uint32_t factoryOffset; factoryOffset = Cy_CTB_OpampGetOffset(CTBM0, CY_CTB_OPAMP_0);
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1
- Returns
Offset trim value
-
void
Cy_CTB_OpampSetSlope
(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint32_t trim) Override the CTB opamp slope factory trim.
The offset of the opamp will vary across temperature. This trim compensates for the slope of the offset across temperature. This compensation uses a bias current from the Analog Reference block. To disable it, set the trim to 0.
The trim is a six bit value and the MSB is a direction bit.
Bit 5
Bits 4:0
Note
0
00000
Negative trim direction - minimum setting
0
11111
Negative trim direction - maximum setting
1
00000
Positive trim direction - minimum setting
1
11111
Positive trim direction - maximum setting
/* Scenario: Calibrate the slope trim by iterating through all the possible trim values. */ uint8_t trim; for (trim = 0u; trim <= 0x3F; trim++) { Cy_CTB_OpampSetSlope(CTBM0, CY_CTB_OPAMP_0, trim); /* Do something after changing the slope trim. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
trim – Trim value from 0 to 63
- Returns
None
-
uint32_t
Cy_CTB_OpampGetSlope
(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum) Return the CTB opamp slope trim value.
/* Scenario: Save the factory slope trim before changing it. */ uint32_t factorySlope; factorySlope = Cy_CTB_OpampGetSlope(CTBM0, CY_CTB_OPAMP_0);
- Function Usage
- Parameters
base – Pointer to structure describing registers
opampNum – CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1
- Returns
Slope trim value
-
void
Cy_CTB_SetAnalogSwitch
(CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_ctb_switch_state_t state) Provide firmware control of the CTB switches.
Each call to this function can open a set of switches or close a set of switches in one register.
/* Scenario: OA0 has been configured as an opamp with 10x output drive using the * pre-defined Cy_CTB_Fast_Opamp0_Opamp10x configuration. The 10x output has * a dedicated connection to Pin 9.2. * * Call SetAnalogSwitch to route the non-inverting input of OA0 to Pin 9.0 * and the inverting input to Pin 9.1. * * Note that the CTB port may vary based on device. */ /* Select OA0 switch register. */ cy_en_ctb_switch_register_sel_t switchSelect = CY_CTB_SWITCH_OA0_SW; /* Select two switches for Pin 0 and Pin 1 of the CTB port. */ uint32_t switchMask = CY_CTB_SW_OA0_POS_PIN0_MASK | CY_CTB_SW_OA0_NEG_PIN1_MASK; /* Set the state of the switches to closed */ cy_en_ctb_switch_state_t state = CY_CTB_SWITCH_CLOSE; Cy_CTB_SetAnalogSwitch(CTBM0, switchSelect, switchMask, state);
- Function Usage
- Parameters
base – Pointer to structure describing registers
switchSelect – A value of the enum cy_en_ctb_switch_register_sel_t to select the switch register
switchMask – The mask of the switches to either open or close. The switch masks can be found in the following enums: cy_en_ctb_oa0_switches_t, cy_en_ctb_oa1_switches_t, and cy_en_ctb_ctd_switches_t. Use the enum that is consistent with the provided register.
state – CY_CTB_SWITCH_OPEN or CY_CTB_SWITCH_CLOSE
- Returns
None
-
uint32_t
Cy_CTB_GetAnalogSwitch
(const CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect) Return the open or closed state of the specified analog switch.
/* Scenario: Query if the positive terminal of Opamp0 is connected to P9.0 or not. */ uint32_t switchMask; switchMask = Cy_CTB_GetAnalogSwitch(CTBM0, CY_CTB_SWITCH_OA0_SW); if ((uint32_t) CY_CTB_SW_OA0_POS_PIN0_MASK == (switchMask & ((uint32_t) CY_CTB_SW_OA0_POS_PIN0_MASK))) { /* The positive terminal of OA0 is connected to P9.0. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
switchSelect – A value of the enum cy_en_ctb_switch_register_sel_t to select the switch register
- Returns
The state of the switches in the provided register. Compare this value to the switch masks in the following enums: cy_en_ctb_oa0_switches_t, cy_en_ctb_oa1_switches_t, and cy_en_ctb_ctd_switches_t.
-
__STATIC_INLINE void Cy_CTB_OpenAllSwitches (CTBM_Type *base)
Open all the switches and disable all hardware (SAR Sequencer and DSI) control of the switches.
Primarily used as a quick method of re-configuring all analog connections that are sparsely closed.
/* Scenario: Reset all the switches to destroy all previous connections. */ Cy_CTB_OpenAllSwitches(CTBM0);
- Function Usage
- Parameters
base – Pointer to structure describing registers
- Returns
None
-
__STATIC_INLINE void Cy_CTB_EnableSarSeqCtrl (CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask)
Enable SAR sequencer control of specified switch(es).
This allows the SAR ADC to use routes through the CTB when configuring its channels.
There are three switches in the CTB that can be enabled by the SAR sequencer.
D51: This switch connects the negative input of Opamp0 to the SARBUS0
D52: This switch connects the positive input of Opamp1 to the SARBUS0
D62: This switch connects the positive input of Opamp1 to the SARBUS1
/* Scenario: The SAR ADC has been configured to sample the opamp outputs. * Enable SAR sequencer control of all three switches in the CTB. */ Cy_CTB_EnableSarSeqCtrl(CTBM0, CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK);
- Function Usage
- Parameters
base – Pointer to structure describing registers
switchMask – The switch or switches in which to enable SAR sequencer control. Use an enumerated value from cy_en_ctb_switch_sar_seq_t.
- Returns
None
-
__STATIC_INLINE void Cy_CTB_DisableSarSeqCtrl (CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask)
Disable SAR sequencer control of specified switch(es).
/* Scenario: The SAR ADC no longer needs to sample the opamp outputs. * Disable SAR sequencer control of all three switches in the CTB. */ Cy_CTB_DisableSarSeqCtrl(CTBM0, CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK);
- Function Usage
- Parameters
base – Pointer to structure describing registers
switchMask – The switch or switches in which to disable SAR sequencer control. Use an enumerated value from cy_en_ctb_switch_sar_seq_t.
- Returns
None
-
__STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatus (const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Return the status of the interrupt when the configured comparator edge is detected.
/* Scenario: Both opamps have been configured as comparators with interrupts enabled. * Retrieve the interrupt status to determine which interrupt was triggered. */ uint32_t intrStatus; intrStatus = Cy_CTB_GetInterruptStatus(CTBM0, CY_CTB_OPAMP_BOTH); /* Clear both comparator interrupts so that subsequent interrupts can be handled. */ Cy_CTB_ClearInterrupt(CTBM0, CY_CTB_OPAMP_BOTH); if (CY_CTB_OPAMP_0 == (intrStatus & CY_CTB_OPAMP_0)) { /* Do something when comparator 0 interrupt occurs. */ } if (CY_CTB_OPAMP_1 == (intrStatus & CY_CTB_OPAMP_1)) { /* Do something when comparator 1 interrupt occurs. */ }
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
- Returns
The interrupt status. If compNum is CY_CTB_OPAMP_BOTH, cast the returned status to cy_en_ctb_opamp_sel_t to determine which comparator edge (or both) was detected.
0: Edge was not detected
Non-zero: Configured edge type was detected
-
__STATIC_INLINE void Cy_CTB_ClearInterrupt (CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Clear the CTB comparator triggered interrupt.
The interrupt must be cleared with this function so that the hardware can set subsequent interrupts and those interrupts can be forwarded to the interrupt controller, if enabled.
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
- Returns
None
-
__STATIC_INLINE void Cy_CTB_SetInterrupt (CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Force the CTB interrupt to trigger using software.
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
- Returns
None
-
__STATIC_INLINE void Cy_CTB_SetInterruptMask (CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Configure the CTB comparator edge interrupt to be forwarded to the CPU interrupt controller.
/* Scenario: Enable interrupt request for both comparators. */ Cy_CTB_SetInterruptMask(CTBM0, CY_CTB_OPAMP_BOTH);
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_NONE, CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH. Calling this function with CY_CTB_OPAMP_NONE will disable all interrupt requests.
- Returns
None
-
__STATIC_INLINE uint32_t Cy_CTB_GetInterruptMask (const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Return whether the CTB comparator edge interrupt output is forwarded to the CPU interrupt controller as configured by Cy_CTB_SetInterruptMask.
/* Scenario: Check if comparator 0 interrupts are enabled. If not, enable it. */ uint32_t intrMask; intrMask = Cy_CTB_GetInterruptMask(CTBM0, CY_CTB_OPAMP_0); if (0UL == intrMask) { Cy_CTB_SetInterruptMask(CTBM0, CY_CTB_OPAMP_0); }
- Function Usage
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
- Returns
The interrupt mask. If compNum is CY_CTB_OPAMP_BOTH, cast the returned mask to cy_en_ctb_opamp_sel_t to determine which comparator interrupt output (or both) is forwarded.
0: Interrupt output not forwarded to interrupt controller
Non-zero: Interrupt output forwarded to interrupt controller
-
__STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked (const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum)
Return the CTB comparator edge output interrupt state after being masked.
This is the bitwise AND of Cy_CTB_GetInterruptStatus and Cy_CTB_GetInterruptMask.
- Parameters
base – Pointer to structure describing registers
compNum – CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH
- Returns
If compNum is CY_CTB_OPAMP_BOTH, cast the returned value to cy_en_ctb_opamp_sel_t to determine which comparator interrupt output (or both) is detected and masked.
0: Configured edge not detected or not masked
Non-zero: Configured edge type detected and masked
-
void
Cy_CTB_SetCurrentMode
(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode) High level function to configure the current modes of the opamps.
This function configures all opamps of the CTB to the same current mode. These modes are differentiated by the reference current level, the opamp input range, and the Deep Sleep mode operation.
The reference current level is set using Cy_CTB_SetIptatLevel
When 1 uA current level is used in Deep Sleep,
All generators in the AREF must be enabled in Deep Sleep. That is, Cy_SysAnalog_SetDeepSleepMode is called with CY_SYSANALOG_DEEPSLEEP_IPTAT_IZTAT_VREF.
When 100 nA current level is used,
Cy_CTB_EnableRedirect is called to route the AREF IPTAT reference to the opamp IZTAT and disable the opamps IPTAT.
The IPTAT generator is enabled in Deep Sleep. That is, Cy_SysAnalog_SetDeepSleepMode is called with CY_SYSANALOG_DEEPSLEEP_IPTAT_2 unless it is already configured for CY_SYSANALOG_DEEPSLEEP_IPTAT_IZTAT_VREF.
note
The IPTAT level is a chip wide configuration so multiple opamps cannot operate at different IPTAT levels. When calling Cy_CTB_SetCurrentMode for a CTB instance on the device, it should be called for all other CTB instances as well.
Current Mode
IPTAT Level
Input Range
Deep Sleep Operation
1 uA
Rail-to-Rail (charge pump enabled)
Disabled in Deep Sleep
1 uA
0 - VDDA-1.5 V (charge pump disabled)
Enabled in Deep Sleep
100 nA
0 - VDDA-1.5 V (charge pump disabled)
Enabled in Deep Sleep
note
The output range of the opamp is 0.2 V to VDDA - 0.2 V (depending on output load).
/* Scenario: Configure all CTBs on the device to use a 1 uA IPTAT reference. * Enable the charge pump and disable Deep Sleep operation for both opamps in the specified CTB block. */ Cy_CTB_SetCurrentMode(CTBM0, CY_CTB_CURRENT_HIGH_ACTIVE);
- Function Usage
- Parameters
base – Pointer to structure describing registers
currentMode – Current mode selection
- Returns
None
-
__STATIC_INLINE void Cy_CTB_SetIptatLevel (cy_en_ctb_iptat_t iptat)
Set the IPTAT reference level to 1 uA or 100 nA.
The IPTAT generator is used by the CTB for slope offset drift.
/* Scenario: Configure all CTBs on the device to use a 100 nA IPTAT reference * for ultra low power. In order for the opamps to function with a 100 nA * IPTAT reference, Cy_CTB_EnableRedirect() must be called. * * This is a low level function that only configures the IPTAT reference level. * The preferred method is the Cy_CTB_SetCurrentMode() as it is a high * level function that configures both the IPTAT reference and the current * redirection. */ Cy_CTB_SetIptatLevel(CY_CTB_IPTAT_LOW);
- Function Usage
- Parameters
iptat – Value from enum cy_en_ctb_iptat_t
- Returns
None
-
__STATIC_INLINE void Cy_CTB_SetPumpClkSource (PASS_Type *base, cy_en_ctb_clk_pump_source_t pumpClk)
Set the clock source for both charge pumps in the CTB.
Recall that each opamp has its own charge pump. The clock can come from:
CY_CTB_CLK_PUMP_SRSS - a dedicated clock pump divider Pump Clock. Call the following functions to configure the pump clock from the SRSS:
CY_CTB_CLK_PUMP_PERI - one of the peripheral clock dividers Peripherals Clock Dividers. Call the following functions to configure a Peri Clock divider as the pump clock:
Cy_SysClk_PeriphAssignDivider with the IP block set to PCLK_PASS_CLOCK_PUMP_PERI
CY_CTB_CLK_PUMP_DEEPSLEEP - a PASS_v2 deep sleep clock source Deep Sleep Clock. Call the following functions to configure the Deep Sleep Clock Source:
Cy_SysAnalog_Init with proper Deep Sleep Clock source and divider settings and either:
Cy_SysClk_ClkMfSetDivider (if needed)
- Function Usage
/* Scenario: Use a 24 Mhz clock from the SRSS for the charge pump clock. */ /* Set the source to clock Path 0, which has been configured for 100 MHz FLL. */ Cy_SysClk_ClkPumpSetSource(CY_SYSCLK_PUMP_IN_CLKPATH0); /* Divide the 100 Mhz by 4. */ Cy_SysClk_ClkPumpSetDivider(CY_SYSCLK_PUMP_DIV_4); Cy_SysClk_ClkPumpEnable(); /* Select the source for the pump clock to be from the SRSS. */ Cy_CTB_SetPumpClkSource(PASS, CY_CTB_CLK_PUMP_SRSS);
/* Scenario: Use a 25 Mhz clock from the PeriClk dividers for the charge pump clock. */ uint32_t dividerNum = 1UL; uint32_t dividerValue = 1UL; /* Use the 8-bit divider type and divider number 1 from the PeriClk, which has been configured for 50 MHz. */ Cy_SysClk_PeriphAssignDivider(PCLK_PASS_CLOCK_PUMP_PERI, CY_SYSCLK_DIV_8_BIT, dividerNum); /* Divide the 50 MHz PeriClk by 2 (dividerValue + 1). */ Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, dividerNum, dividerValue); Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, dividerNum); /* Select the source for the pump clock to be from the PeriClk dividers. */ Cy_CTB_SetPumpClkSource(PASS, CY_CTB_CLK_PUMP_PERI);
/* Scenario: Use a 2 Mhz MF clock for the charge pump clock. */ Cy_SysClk_MfoEnable(true); Cy_SysClk_ClkMfSetDivider(1UL); Cy_SysClk_ClkMfEnable(); Cy_CTB_SetPumpClkSource(PASS, CY_CTB_CLK_PUMP_DEEPSLEEP);
- Parameters
base – Pointer to the PASS register structure.
pumpClk – Clock source selection (PumpClk, PeriClk or Deep Sleep Clock) for the pump. Select a value from cy_en_ctb_clk_pump_source_t
- Returns
None
-
__STATIC_INLINE void Cy_CTB_EnableRedirect (void)
Normally, the AREF IZTAT is routed to the CTB IZTAT and the AREF IPTAT is routed to the CTB IPTAT:
CTB.IZTAT = AREF.IZTAT
CTB.IPTAT = AREF.IPTAT
However, the AREF IPTAT can be redirected to the CTB IZTAT and the CTB IPTAT is off.
CTB.IZTAT = AREF.IPTAT
CTB.IPTAT = HiZ
The redirection applies to all opamps on the device and should be used when the IPTAT bias level is set to 100 nA (see Cy_CTB_SetIptatLevel).
When the CTB.IPTAT is HiZ, the CTB cannot compensate for the slope of the offset across temperature.
/* Scenario: All CTBs on the device have been configured to use * a 100 nA IPTAT reference. Redirect the AREF IPTAT current to the CTB IZTAT * for proper functionality. * * This is a low level function that only enables the current redirection. * The preferred method is the Cy_CTB_SetCurrentMode() as it is a high * level function that configures both the current redirection and the * IPTAT reference. */ Cy_CTB_EnableRedirect();
- Function Usage
- Returns
None
-
__STATIC_INLINE void Cy_CTB_DisableRedirect (void)
Disable the redirection of the AREF IPTAT to the CTB IZTAT for all opamps on the device as enabled by Cy_CTB_EnableRedirect.
- Returns
None
Variables
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Unused
Configure Opamp0 as unused - powered down.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Comp
Configure Opamp0 as a comparator.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Opamp1x
Configure Opamp0 as an opamp with 1x drive.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Opamp10x
Configure Opamp0 as an opamp with 10x drive.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Diffamp
Configure Opamp0 as one stage of a differential amplifier.
The opamp is in 10x drive and the switches shown are closed.
See the device datasheet for the dedicated CTB port.
To be used with Cy_CTB_FastInit and Cy_CTB_Fast_Opamp1_Diffamp.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Vdac_Out
Configure Opamp0 as a buffer for the CTDAC output.
The buffer is in 10x drive and the switches shown are closed. Configure the CTDAC for output buffer mode by calling Cy_CTDAC_FastInit with Cy_CTDAC_Fast_VddaRef_BufferedOut or Cy_CTDAC_Fast_OA1Ref_BufferedOut.
See the device datasheet for the dedicated CTB port.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa0_t
Cy_CTB_Fast_Opamp0_Vdac_Out_SH
Configure Opamp0 as a buffer for the CTDAC output with the sample and hold capacitor connected.
The buffer is in 10x drive and the switches shown are closed. Configure the CTDAC for output buffer mode by calling Cy_CTDAC_FastInit with Cy_CTDAC_Fast_VddaRef_BufferedOut or Cy_CTDAC_Fast_OA1Ref_BufferedOut.
See the device datasheet for the dedicated CTB port.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Unused
Configure Opamp1 as unused - powered down.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Comp
Configure Opamp1 as a comparator.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Opamp1x
Configure Opamp1 as an opamp with 1x drive.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Opamp10x
Configure Opamp1 as an opamp with 10x drive.
No routing is configured.
See Cy_CTB_FastInit.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Diffamp
Configure Opamp1 as one stage of a differential amplifier.
The opamp is in 10x drive and the switches shown are closed.
See the device datasheet for the dedicated CTB port.
To be used with Cy_CTB_FastInit and Cy_CTB_Fast_Opamp0_Diffamp.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref
Configure Opamp1 as a buffer for the CTDAC reference.
The reference comes from the internal analog reference block (AREF). The buffer is in 1x drive and the switches shown are closed. Configure the CTDAC to use the buffered reference by calling Cy_CTDAC_FastInit with Cy_CTDAC_Fast_OA1Ref_UnbufferedOut or Cy_CTDAC_Fast_OA1Ref_BufferedOut.
See Cy_CTB_FastInit.
Note the AREF block needs to be configured using a separate driver.
-
const cy_stc_ctb_fast_config_oa1_t
Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5
Configure Opamp1 as a buffer for the CTDAC reference.
The reference comes from Pin 5. The buffer is in 1x drive and the switches shown are closed. Configure the CTDAC to use the buffered reference by calling Cy_CTDAC_FastInit with Cy_CTDAC_Fast_OA1Ref_UnbufferedOut or Cy_CTDAC_Fast_OA1Ref_BufferedOut.
See the device datasheet for the dedicated CTB port.
See Cy_CTB_FastInit.
-
struct
cy_stc_ctb_config_t
¶ - #include <>
Configuration structure to set up the entire CTB to be used with Cy_CTB_Init.
Public Members
-
cy_en_ctb_deep_sleep_t
deepSleep
¶ Enable or disable the CTB during Deep Sleep.
-
cy_en_ctb_power_t
oa0Power
¶ Opamp0 power mode: off, low, medium, or high.
-
cy_en_ctb_mode_t
oa0Mode
¶ Opamp0 usage mode: 1x drive, 10x drive, or as a comparator.
-
cy_en_ctb_pump_t
oa0Pump
¶ Opamp0 charge pump: enable to increase input range for rail-to-rail operation.
-
cy_en_ctb_comp_edge_t
oa0CompEdge
¶ Opamp0 comparator edge detection: disable, rising, falling, or both.
-
cy_en_ctb_comp_level_t
oa0CompLevel
¶ Opamp0 comparator DSI (trigger) output: pulse or level.
-
cy_en_ctb_comp_bypass_t
oa0CompBypass
¶ Opamp0 comparator DSI (trigger) output synchronization.
-
cy_en_ctb_comp_hyst_t
oa0CompHyst
¶ Opamp0 comparator hysteresis: enable for 10 mV hysteresis.
-
bool
oa0CompIntrEn
¶ Opamp0 comparator interrupt enable.
-
cy_en_ctb_power_t
oa1Power
¶ Opamp1 power mode: off, low, medium, or high.
-
cy_en_ctb_mode_t
oa1Mode
¶ Opamp1 usage mode: 1x drive, 10x drive, or as a comparator.
-
cy_en_ctb_pump_t
oa1Pump
¶ Opamp1 charge pump: enable to increase input range for rail-to-rail operation.
-
cy_en_ctb_comp_edge_t
oa1CompEdge
¶ Opamp1 comparator edge detection: disable, rising, falling, or both.
-
cy_en_ctb_comp_level_t
oa1CompLevel
¶ Opamp1 comparator DSI (trigger) output: pulse or level.
-
cy_en_ctb_comp_bypass_t
oa1CompBypass
¶ Opamp1 comparator DSI (trigger) output synchronization.
-
cy_en_ctb_comp_hyst_t
oa1CompHyst
¶ Opamp1 comparator hysteresis: enable for 10 mV hysteresis.
-
bool
oa1CompIntrEn
¶ Opamp1 comparator interrupt enable.
-
bool
configRouting
¶ Configure or ignore routing related registers.
-
uint32_t
oa0SwitchCtrl
¶ Opamp0 routing control.
-
uint32_t
oa1SwitchCtrl
¶ Opamp1 routing control.
-
uint32_t
ctdSwitchCtrl
¶ Routing control between the CTDAC and CTB blocks.
-
cy_en_ctb_deep_sleep_t
-
struct
cy_stc_ctb_opamp_config_t
¶ - #include <>
This configuration structure is used to initialize only one opamp of the CTB without impacting analog routing.
This structure is used with Cy_CTB_OpampInit.
Public Members
-
cy_en_ctb_deep_sleep_t
deepSleep
¶ Enable or disable the CTB during Deep Sleep.
-
cy_en_ctb_power_t
oaPower
¶ Opamp power mode: off, low, medium, or high.
-
cy_en_ctb_mode_t
oaMode
¶ Opamp usage mode: 1x drive, 10x drive, or as a comparator.
-
cy_en_ctb_pump_t
oaPump
¶ Opamp charge pump: enable to increase input range for rail-to-rail operation.
-
cy_en_ctb_comp_edge_t
oaCompEdge
¶ Opamp comparator edge detection: disable, rising, falling, or both.
-
cy_en_ctb_comp_level_t
oaCompLevel
¶ Opamp comparator DSI (trigger) output: pulse or level.
-
cy_en_ctb_comp_bypass_t
oaCompBypass
¶ Opamp comparator DSI (trigger) output synchronization.
-
cy_en_ctb_comp_hyst_t
oaCompHyst
¶ Opamp comparator hysteresis: enable for 10 mV hysteresis.
-
bool
oaCompIntrEn
¶ Opamp comparator interrupt enable.
-
cy_en_ctb_deep_sleep_t
-
struct
cy_stc_ctb_fast_config_oa0_t
¶ - #include <>
This configuration structure is used to quickly initialize Opamp0 for the most commonly used configurations.
Other configuration options are set to:
.oa0Pump = CY_CTB_PUMP_ENABLE
.oa0CompEdge = CY_CTB_COMP_EDGE_BOTH
.oa0CompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL
.oa0CompBypass = CY_CTB_COMP_BYPASS_SYNC
.oa0CompHyst = CY_CTB_COMP_HYST_10MV
.oa0CompIntrEn = true
Public Members
-
cy_en_ctb_power_t
oa0Power
¶ Opamp0 power mode: off, low, medium, or high.
-
cy_en_ctb_mode_t
oa0Mode
¶ Opamp0 usage mode: 1x drive, 10x drive, or as a comparator.
-
uint32_t
oa0SwitchCtrl
¶ Opamp0 routing control.
-
uint32_t
ctdSwitchCtrl
¶ Routing control between the CTDAC and CTB blocks.
-
struct
cy_stc_ctb_fast_config_oa1_t
¶ - #include <>
This configuration structure is used to quickly initialize Opamp1 for the most commonly used configurations.
Other configuration options are set to:
.oa1Pump = CY_CTB_PUMP_ENABLE
.oa1CompEdge = CY_CTB_COMP_EDGE_BOTH
.oa1CompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL
.oa1CompBypass = CY_CTB_COMP_BYPASS_SYNC
.oa1CompHyst = CY_CTB_COMP_HYST_10MV
.oa1CompIntrEn = true
Public Members
-
cy_en_ctb_power_t
oa1Power
¶ Opamp1 power mode: off, low, medium, or high.
-
cy_en_ctb_mode_t
oa1Mode
¶ Opamp1 usage mode: 1x drive, 10x drive, or as a comparator.
-
uint32_t
oa1SwitchCtrl
¶ Opamp1 routing control.
-
uint32_t
ctdSwitchCtrl
¶ Routing control between the CTDAC and CTB blocks.