cy_ctdac_8h

Header file for the CTDAC driver

Version

2.0.2

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_CTDAC_DRV_VERSION_MAJOR

Driver major version.

CY_CTDAC_DRV_VERSION_MINOR

Driver minor version.

CY_CTDAC_ID

CTDAC driver identifier.

CY_CTDAC_DEINIT

De-init value for CTDAC registers.

CY_CTDAC_UNSIGNED_MID_CODE_VALUE

Middle code value for unsigned values.

CY_CTDAC_UNSIGNED_MAX_CODE_VALUE

Maximum code value for unsigned values.

CY_CTDAC_FAST_CLKCFG_TYPE

Clock divider type for quick clock setup.

CY_CTDAC_FAST_CLKCFG_NUM

Clock divider number for quick clock setup.

CY_CTDAC_FAST_CLKCFG_DIV

Clock divider integer value for quick clock setup.

Divides PERI clock by 100.

Enums

enum cy_en_ctdac_update_t

cy_en_ctdac_update_t: Configure the mode for how the DAC value is updated.

All the modes require a CTDAC clock except for Direct write.

Values:

enumerator CY_CTDAC_UPDATE_DIRECT_WRITE

DAC value is updated with a direct write by calling to Cy_CTDAC_SetValue.

enumerator CY_CTDAC_UPDATE_BUFFERED_WRITE

DAC value stored with Cy_CTDAC_SetValueBuffered is updated on the next CTDAC clock edge.

enumerator CY_CTDAC_UPDATE_STROBE_EDGE_SYNC

DAC value stored with Cy_CTDAC_SetValueBuffered is updated on the next CTDAC clock edge after a rising edge of the strobe.

enumerator CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE

DAC value stored with Cy_CTDAC_SetValueBuffered is updated on the rising edge of the strobe input.

enumerator CY_CTDAC_UPDATE_STROBE_LEVEL

DAC value stored with Cy_CTDAC_SetValueBuffered is updated on every CTDAC clock edge while the strobe line is high.

enum cy_en_ctdac_format_t

cy_en_ctdac_format_t: Configure the format in which the DAC value register is decoded.

Values:

enumerator CY_CTDAC_FORMAT_UNSIGNED

Unsigned 12-bit DAC.

No value decoding

enumerator CY_CTDAC_FORMAT_SIGNED

Virtual signed.

Add 0x800 to the 12-bit DAC value

enum cy_en_ctdac_deep_sleep_t

cy_en_ctdac_deep_sleep_t: Enable or disable the CTDAC hardware during Deep Sleep.

Values:

enumerator CY_CTDAC_DEEPSLEEP_DISABLE

DAC is disabled during Deep Sleep power mode.

enumerator CY_CTDAC_DEEPSLEEP_ENABLE

DAC remains enabled during Deep Sleep power mode.

enum cy_en_ctdac_output_mode_t

cy_en_ctdac_output_mode_t: Configure the output state of the CTDAC.

Values:

enumerator CY_CTDAC_OUTPUT_HIGHZ

DAC output is tri-state.

enumerator CY_CTDAC_OUTPUT_VALUE

DAC Output is enabled and drives the programmed value.

enumerator CY_CTDAC_OUTPUT_VALUE_PLUS1

DAC Output enabled and drives the programmed value plus 1.

enumerator CY_CTDAC_OUTPUT_VSSA

Output is pulled to Vssa through a 1.1 MOhm (typ) resistor.

enumerator CY_CTDAC_OUTPUT_VREF

Output is pulled to Vref through a 1.1 MOhm (typ) resistor.

enum cy_en_ctdac_deglitch_t

cy_en_ctdac_deglitch_t: Configure the deglitch mode.

See the Deglitch section for more information on how deglitching works.

Values:

enumerator CY_CTDAC_DEGLITCHMODE_NONE

Disable deglitch.

enumerator CY_CTDAC_DEGLITCHMODE_UNBUFFERED

Deglitch through the CO6 switch.

enumerator CY_CTDAC_DEGLITCHMODE_BUFFERED

Deglitch through the CTB COS switch.

enumerator CY_CTDAC_DEGLITCHMODE_BOTH

Deglitch through both CO6 and CTB COS switches.

enum cy_en_ctdac_ref_source_t

cy_en_ctdac_ref_source_t: Configure the reference source for the CTDAC.

The CVD switch is closed when Vdda is the reference source.

Values:

enumerator CY_CTDAC_REFSOURCE_EXTERNAL

Use an external source from Opamp1 of the CTB as the reference.

CVD switch is open.

enumerator CY_CTDAC_REFSOURCE_VDDA

Use Vdda as the reference.

CVD switch is closed.

enum cy_en_ctdac_output_buffer_t

cy_en_ctdac_output_buffer_t: Configure the output to be buffered or unbuffered.

The CO6 switch is closed when the output is unbuffered to Pin 6 of the CTDAC port. See the device datasheet for the CTDAC port.

Values:

enumerator CY_CTDAC_OUTPUT_BUFFERED

Buffer the output through the CTB OA0.

enumerator CY_CTDAC_OUTPUT_UNBUFFERED

Send output to a direct pin.

enum cy_en_ctdac_switch_state_t

cy_en_ctdac_switch_state_t: Switch state, either open or closed, to be used in Cy_CTDAC_SetAnalogSwitch.

Values:

enumerator CY_CTDAC_SWITCH_OPEN

Open the switch.

enumerator CY_CTDAC_SWITCH_CLOSE

Close the switch.

enum cy_en_ctdac_switches_t

cy_en_ctdac_switches_t: Switch mask to be used in Cy_CTDAC_SetAnalogSwitch.

Values:

enumerator CY_CTDAC_SWITCH_CVD_MASK

Switch for the reference source, Vdda or external.

enumerator CY_CTDAC_SWITCH_CO6_MASK

Switch for the output, buffered or direct.

enum cy_en_ctdac_status_t

cy_en_ctdac_status_t: Return states for Cy_CTDAC_Init, Cy_CTDAC_DeInit, and Cy_CTDAC_FastInit.

Values:

enumerator CY_CTDAC_SUCCESS

Initialization completed successfully.

enumerator CY_CTDAC_BAD_PARAM

Input pointers were NULL and Initialization could not be completed.

Functions

cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t *config)

Initialize all CTDAC configuration registers.


    /* Scenario: Configure the CTDAC to use VDDA as the reference source with an unbuffered output.
     * A 500 kHz peripheral clock is enabled and connected to the CTDAC for buffered writes. */
    
    cy_en_ctdac_status_t status;
    
    const cy_stc_ctdac_config_t config =
    {
        /* .refSource       = */ CY_CTDAC_REFSOURCE_VDDA,           /* Use VDDA as reference. */
        /* .formatMode      = */ CY_CTDAC_FORMAT_SIGNED,            /* Set the register format to signed. */
        /* .updateMode      = */ CY_CTDAC_UPDATE_BUFFERED_WRITE,    /* Set the update mode to buffered write. */
        /* .deglitchMode    = */ CY_CTDAC_DEGLITCHMODE_UNBUFFERED,  /* Enable deglitching on the unbuffered output path. */
        /* .outputMode      = */ CY_CTDAC_OUTPUT_VALUE,             /* Enable the output to drive the register value. */
        /* .outputBuffer    = */ CY_CTDAC_OUTPUT_UNBUFFERED,        /* Output is unbuffered to pin. */
        /* .deepSleep       = */ CY_CTDAC_DEEPSLEEP_ENABLE,         /* Enable the CTDAC to operate in Deep Sleep mode. */
        /* .deglitchCycles  = */ 34uL,                              /* Set the deglitch time to 700 ns. */
                                                                    /* Deglitch time = (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ */
        /* .value           = */ 0uL,                               /* With signed format, set the initial output voltage to Vdda/2. */
        /* .nextValue       = */ 0uL,
        /* .enableInterrupt = */ true,                              /* Enable interrupt. */
        /* .configClock     = */ true,                              /* Configure and connect the CTDAC clock. */
        /* .dividerType     = */ CY_SYSCLK_DIV_8_BIT,               /* Use the 8-bit clock dividers for the CTDAC clock source. */
        /* .dividerNum      = */ 0uL,                               /* Select divider number 0. */
        /* .dividerIntValue = */ 99uL,                              /* Set the CTDAC clock frequency to 500 kHz based on a 50 MHz PeriClk. */
                                                                    /* CTDAC clock frequency = PERI_CLOCK_FREQ / (dividerIntValue + 1) */
        /* .dividerFracValue= */ CY_CTDAC_DEINIT,
    };

    status = Cy_CTDAC_Init(CTDAC0, &config);

    if (CY_CTDAC_SUCCESS == status)
    {
        /* Turn on the hardware block. */
        Cy_CTDAC_Enable(CTDAC0);
    }
Return

Status of initialization, CY_CTDAC_SUCCESS or CY_CTDAC_BAD_PARAM

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • config: Pointer to structure containing configuration data

cy_en_ctdac_status_t Cy_CTDAC_DeInit(CTDAC_Type *base, bool deInitRouting)

Reset CTDAC registers back to power on reset defaults.

note

Does not disable the clock.

    /* Scenario: The CTDAC is no longer used or needs to be disabled. */
    
    /* Disable and reset the CTDAC including switches. */
    (void) Cy_CTDAC_DeInit(CTDAC0, true);
Return

Status of initialization, CY_CTDAC_SUCCESS, or CY_CTDAC_BAD_PARAM

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • deInitRouting: If true, all switches are reset to their default state. If false, switch registers are untouched.

cy_en_ctdac_status_t Cy_CTDAC_FastInit(CTDAC_Type *base, const cy_stc_ctdac_fast_config_t *config)

Initialize the CTDAC to one of the common use modes.

This function provides a quick and easy method of configuring the CTDAC when using the PDL driver for device configuration.

The other configuration options are set to:

A separate call to Cy_CTDAC_Enable is needed to turn on the hardware.

The following code snippets configures VDDA as the reference source and routes the output directly to Pin 6 (unbuffered).

Return

Status of initialization, CY_CTDAC_SUCCESS or CY_CTDAC_BAD_PARAM

Function Usage

Parameters


    /* Scenario: Quickly configure the CTDAC using one of the common use cases
     * provided by the driver. The Cy_CTDAC_Fast_VddaRef_UnbufferedOut configuration
     * will use VDDA as the reference source and route the output directly to P9.6. */
    cy_en_ctdac_status_t status;
    
    status = Cy_CTDAC_FastInit(CTDAC0, &Cy_CTDAC_Fast_VddaRef_UnbufferedOut);

    if (CY_CTDAC_SUCCESS == status)
    {
        /* Turn on the hardware block. */
        Cy_CTDAC_Enable(CTDAC0);
    }

The following code snippet shows how the CTDAC and CTB blocks can quickly be configured to work together. The code configures the CTDAC to use a buffered output, a buffered reference source from the internal bandgap voltage, and closes all required analog routing switches.

Function Usage

../../../_images/ctdac_fast_init_funcusage.png

    /* Scenario: Quickly configure the CTDAC and CTB blocks to work together.
     * The CTDAC uses the internal AREF bandgap reference buffered with Opamp1
     * and Opamp0 buffers the CTDAC output to P9.2. */
    
    cy_en_ctdac_status_t ctdacStatus;
    cy_en_ctb_status_t ctbStatus;
    
    /* The AREF block must be initialized and enabled to provide a 1.2 V voltage reference
     * for the CTDAC and the current references for the opamps. */
    (void) Cy_SysAnalog_Init(&Cy_SysAnalog_Fast_Local);
    Cy_SysAnalog_Enable();
    
    /* Buffer the reference and output of the CTDAC. */
    ctdacStatus = Cy_CTDAC_FastInit(CTDAC0, &Cy_CTDAC_Fast_OA1Ref_BufferedOut);
    
    /* Buffer the CTDAC output using Opamp0 to P9.2.
     * Buffer the internal AREF bandgap voltage for the CTDAC reference using Opamp1. */
    ctbStatus = Cy_CTB_FastInit(CTBM0, &Cy_CTB_Fast_Opamp0_Vdac_Out, &Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref);

    if ((CY_CTB_SUCCESS == ctbStatus) && (CY_CTDAC_SUCCESS == ctdacStatus))
    {
        /* Turn on the buffers before turning on the CTDAC. */
        Cy_CTB_Enable(CTBM0);
        Cy_CTDAC_Enable(CTDAC0);
    }
    

__STATIC_INLINE void Cy_CTDAC_Enable (CTDAC_Type *base)

Power up the CTDAC hardware block.

Return

None

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_Disable (CTDAC_Type *base)

Turn off the hardware block.

Return

None

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_SetValue (CTDAC_Type *base, int32_t value)

Set the CTDAC_VAL register (DAC hardware is updated on the next PeriClk cycle).

Only the least significant 12 bits have an effect. Sign extension of negative values is unnecessary and is ignored by the hardware. The way in which the CTDAC interprets the 12-bit data is controlled by Cy_CTDAC_SetSignMode.

note

Call this function only when the update mode is set to Direct write. Calling this function for any other update mode will not have the intended effect.

    /* Scenario: The update mode has been configured for Direct writes.
     * To update the DAC value in this mode, Cy_CTDAC_SetValue() must be called. */
    
    /* Output Vref/2 (unsigned mode). */
    Cy_CTDAC_SetValue(CTDAC0, 0x800);
    
    /* DAC output is updated on the next PeriClk cycle. */
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • value: Value to write into the CTDAC_VAL register

__STATIC_INLINE void Cy_CTDAC_SetValueBuffered (CTDAC_Type *base, int32_t value)

Set the CTDAC_VAL_NEXT register.

The value is transferred to the CTDAC_VAL register on the next edge of the CTDAC clock. Only the least significant 12 bits have an effect. Sign extension of negative values is unnecessary and is ignored by the hardware. The way in which the CTDAC interprets the 12-bit data is controlled by Cy_CTDAC_SetSignMode.

note

Calling this function in Direct write mode will not update the DAC output. Call this function for all modes that use buffered values (i.e. uses a clock).

    /* Scenario: The update mode has been configured for Buffered writes.
     * To update the DAC value in this mode, a clock is required and
     * Cy_CTDAC_SetValueBuffered() is used. */
        
    /* Output Vref/2 (signed mode). */
    Cy_CTDAC_SetValueBuffered(CTDAC0, 0x000);   
    
    /* The rising edge of the DAC clock initiates an update to the DAC value.
     * Wait for an interrupt to signal that the DAC is ready for a new value. */
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • value: Value to write into the CTDAC_VAL_NEXT register

void Cy_CTDAC_SetSignMode(CTDAC_Type *base, cy_en_ctdac_format_t formatMode)

Set whether to interpret the DAC value as signed or unsigned.

In unsigned mode, the DAC value register is used without any decoding. In signed mode, the MSB is inverted by adding 0x800 to the DAC value. This converts the lowest signed number, 0x800, to the lowest unsigned number, 0x000.

    /* Set the format of the DAC value register to be signed. */
    Cy_CTDAC_SetSignMode(CTDAC0, CY_CTDAC_FORMAT_SIGNED);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • formatMode: Mode can be signed or unsigned. See cy_en_ctdac_format_t for values.

void Cy_CTDAC_SetDeepSleepMode(CTDAC_Type *base, cy_en_ctdac_deep_sleep_t deepSleep)

Enable or disable the DAC hardware operation in Deep Sleep mode.

    /* Scenario: The CTDAC is used as the reference voltage for a comparator
     * to wake up the device from Deep Sleep mode. The comparator has been configured
     * to operate in Deep Sleep mode. */
    
    /* Keep the CTDAC on in Deep Sleep mode. */
    Cy_CTDAC_SetDeepSleepMode(CTDAC0, CY_CTDAC_DEEPSLEEP_ENABLE);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • deepSleep: Enable or disable Deep Sleep operation. Select value from cy_en_ctdac_deep_sleep_t.

void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMode)

Set the output mode of the CTDAC:

    /* Scenario: The Sample and Hold (S/H) capacitor in the CTB block is used to
     * maintain the DAC output voltage for a duration of time so that
     * the DAC output can be turned off to save power. */
    
    /* Turn off DAC output. */
    Cy_CTDAC_SetOutputMode(CTDAC0, CY_CTDAC_OUTPUT_HIGHZ);
    
    /* The DAC output will need to turn on and sampled periodically to maintain
     * an acceptable voltage level across the S/H capacitor. */
    
Return

None

Function Usage

Parameters

void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchMode)

Enable deglitching on the unbuffered path, buffered path, both, or disable deglitching.

The deglitch mode should match the configured output path.

    /* Scenario: The CTDAC is configured to stay on in Deep Sleep mode.
     * Before entering Deep Sleep mode, the deglitch switches must be
     * turned off so that switches along the output path are guaranteed to be closed. */
    
    Cy_CTDAC_SetDeglitchMode(CTDAC0, CY_CTDAC_DEGLITCHMODE_NONE);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • deglitchMode: Deglitching mode selection. See cy_en_ctdac_deglitch_t for values.

void Cy_CTDAC_SetDeglitchCycles(CTDAC_Type *base, uint32_t deglitchCycles)

Set the number of deglitch cycles (0 to 63) that will be used.

To calculate the deglitch time:

  (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ

The optimal deglitch time is 700 ns.

    /* Scenario: The PeriClk frequency has been changed during run-time.
     * Update the deglitch cycles so that the optimal deglitch time of 700 ns
     * can be maintained. */
    #define PERICLK_FREQ_MHZ                (50)
    #define DEGLITCH_TARGET_TIME_NS         (700uL)
    #define FACTOR_NANO_TO_MICRO            (1000uL)
    
    uint32_t deglitchCycles = ((PERICLK_FREQ_MHZ * DEGLITCH_TARGET_TIME_NS) / FACTOR_NANO_TO_MICRO) - 1uL;
    
    Cy_CTDAC_SetDeglitchCycles(CTDAC0, deglitchCycles);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • deglitchCycles: Number of cycles to deglitch

void Cy_CTDAC_SetRef(CTDAC_Type *base, cy_en_ctdac_ref_source_t refSource)

Set the CTDAC reference source to Vdda or an external reference.

The external reference must come from Opamp1 of the CTB.

    /* Scenario: Change the reference source of the CTDAC to be VDDA
     * so that no buffers from the CTB are needed. */
    Cy_CTDAC_SetRef(CTDAC0, CY_CTDAC_REFSOURCE_VDDA);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • refSource: The reference source. Select a value from cy_en_ctdac_ref_source_t.

void Cy_CTDAC_SetAnalogSwitch(CTDAC_Type *base, uint32_t switchMask, cy_en_ctdac_switch_state_t state)

Provide firmware control of the CTDAC switches.

Each call to this function can open a set of switches or close a set of switches.

note

The switches are configured by the reference source and output mode selections during initialization.

    /* Scenario: In addition to buffering the DAC output through Opamp0 of the connecting
     * CTB, route the DAC output to a dedicated device pin by closing the CO6 switch. */
    
    Cy_CTDAC_SetAnalogSwitch(CTDAC0, (uint32_t) CY_CTDAC_SWITCH_CO6_MASK, CY_CTDAC_SWITCH_CLOSE);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • switchMask: The mask of the switches to either open or close. Select one or more values from cy_en_ctdac_switches_t and “OR” them together.

  • state: Open or close the switch(es). Select a value from cy_en_ctdac_switch_state_t.

__STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch (const CTDAC_Type *base)

Return the state (open or close) of the CTDAC switches.

note

The switches will be managed by the reference source and output mode selections when initializing the hardware.

Return

Switch state. Compare this value to the masks found in cy_en_ctdac_switches_t.

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_SetSwitchCO6 (CTDAC_Type *base, cy_en_ctdac_switch_state_t state)

Open or close switch CO6 that controls whether the output gets routed directly to a pin or through Opamp0 of the CTB.

This function calls Cy_CTDAC_SetAnalogSwitch with the switchMask set to CY_CTDAC_SWITCH_CO6_MASK.

note

The switches is configured by the output mode selections during initialization.

note

This switch will temporarily be opened for deglitching if the deglitch mode is CY_CTDAC_DEGLITCHMODE_UNBUFFERED or CY_CTDAC_DEGLITCHMODE_BOTH.

    /* Scenario: In addition to buffering the DAC output through Opamp0 of the connecting
     * CTB, route the DAC output to a dedicated device pin by closing the CO6 switch. */
    
    Cy_CTDAC_SetSwitchCO6(CTDAC0, CY_CTDAC_SWITCH_CLOSE);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • state: State of the switch, open or close.

__STATIC_INLINE void Cy_CTDAC_OpenAllSwitches (CTDAC_Type *base)

Open all switches in the CTDAC (CO6 and CVD).

    /* Scenario: Reset all the switches to destroy all previous connections. */
    
    Cy_CTDAC_OpenAllSwitches(CTDAC0);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus (const CTDAC_Type *base)

Return the interrupt status which gets set by the hardware when the CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register.

Once set, the CTDAC_VAL_NXT register is ready to accept a new value.

note

Interrupts are available in all update modes except Direct write.

    /* Scenario: The CTDAC has interrupts enabled. Retrieve the interrupt
     * status to determine if the CTDAC is ready to accept a new value. */
    
    uint8_t intrStatus;
    
    /* Get the interrupt status for a specific CTDAC instance on the device. */
    intrStatus = Cy_CTDAC_GetInterruptStatus(CTDAC0);

    /* If the interrupt status is 1, the CTDAC is ready to accept a new value. */
    if (1UL == intrStatus)
    {
        /* Set the next value to output. */
    }
Return

  • 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL

  • 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_ClearInterrupt (CTDAC_Type *base)

Clear the interrupt that was set by the hardware when the CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register.

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.

note

Interrupts are available in all update modes except Direct write.

Return

None

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_SetInterrupt (CTDAC_Type *base)

Force the CTDAC interrupt to trigger using software.

note

Interrupts are available in all update modes except Direct write.

Return

None

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTDAC_SetInterruptMask (CTDAC_Type *base, uint32_t mask)

Configure the CTDAC interrupt to be forwarded to the CPU interrupt controller.

note

Interrupts are available in all update modes except Direct write.

    /* Scenario: DMA will be used to update the DAC value. Disable the CTDAC interrupt. */
    
    Cy_CTDAC_SetInterruptMask(CTDAC0, 0UL);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • mask: The CTDAC only has one interrupt so the mask is one bit.

    • 0: Disable CTDAC interrupt request (will not be forwarded to CPU interrupt controller)

    • 1: Enable CTDAC interrupt request (will be forwarded to CPU interrupt controller)

__STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask (const CTDAC_Type *base)

Return whether the CTDAC interrupt is forwarded to the CPU interrupt controller as configured by Cy_CTDAC_SetInterruptMask.

note

Interrupts are available in all update modes except Direct write.

Return

The CTDAC only has one interrupt so the return value is either 0 or 1.

  • 0: Interrupt output not forwarded to CPU interrupt controller

  • 1: Interrupt output forwarded to CPU interrupt controller

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked (const CTDAC_Type *base)

Return the bitwise AND of Cy_CTDAC_GetInterruptStatus and Cy_CTDAC_SetInterruptMask.

When high, the DAC interrupt is asserted and the interrupt is forwarded to the CPU interrupt controller.

note

Interrupts are available in all update modes except Direct write.

Return

  • 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL or not masked

  • 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL and masked

Parameters
  • base: Pointer to structure describing registers

cy_en_syspm_status_t Cy_CTDAC_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)

Callback to prepare the CTDAC before entering and after exiting Deep Sleep mode.

If deglitching is used, it is disabled before entering Deep Sleep to ensure the deglitch switches are closed. This is needed only if the CTDAC will be enabled in DeepSleep. Upon wakeup, deglitching will be re-enabled if it was previously used.

Return

See cy_en_syspm_status_t

Function Usage

    /* Scenario: The CTDAC has been configured to stay on in Deep Sleep mode.
     * Before putting the device into Deep Sleep mode, the CTDAC Deep Sleep
     * callback must be registered to ensure proper operation during and after Deep Sleep mode. */

    /* Set the base address pointer to the CTDAC hardware block. */
    static cy_stc_syspm_callback_params_t DeepSleepCallbackParams;
    static cy_stc_ctdac_context_t ctdacContext;
    DeepSleepCallbackParams.base = CTDAC0;
    DeepSleepCallbackParams.context = &ctdacContext;

    /* Attach the Cy_CTDAC_DeepSleepCallback function and set the callback parameters. */
    cy_stc_syspm_callback_t DeepSleepCallbackStruct;
    DeepSleepCallbackStruct.callback = &Cy_CTDAC_DeepSleepCallback;
    DeepSleepCallbackStruct.type = CY_SYSPM_DEEPSLEEP;
    DeepSleepCallbackStruct.callbackParams = &DeepSleepCallbackParams;

    /* Register the callback before entering Deep Sleep mode. */
    Cy_SysPm_RegisterCallback(&DeepSleepCallbackStruct);
    
    /* Put the device into Deep Sleep mode and wait for an interrupt to wake up. */
    Cy_SysPm_DeepSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
    

Parameters

Variables

const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_VddaRef_UnbufferedOut

Configure CTDAC to use Vdda reference and output unbuffered.

See Cy_CTDAC_FastInit.

const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_VddaRef_BufferedOut

Configure CTDAC to use Vdda reference and output buffered through Opamp0 of CTB.

See Cy_CTDAC_FastInit.

To quickly configure Opamp0, call with Cy_CTB_FastInit with Cy_CTB_Fast_Opamp0_Vdac_Out or Cy_CTB_Fast_Opamp0_Vdac_Out_SH.

const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_UnbufferedOut

Configure CTDAC to use a buffered reference from Opamp1 of CTB and output unbuffered.

See Cy_CTDAC_FastInit.

To use the reference from the Analog Reference (AREF), call Cy_CTB_FastInit with Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref.

To use an external reference from a GPIO, call Cy_CTB_FastInit with Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5 for Pin 5 on the CTB port.

const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_BufferedOut

Configure CTDAC to use a buffered reference from Opamp1 of CTB and output buffered through Opamp0 of CTB.

See Cy_CTDAC_FastInit.

To quickly configure Opamp0, call with Cy_CTB_FastInit with Cy_CTB_Fast_Opamp0_Vdac_Out or Cy_CTB_Fast_Opamp0_Vdac_Out_SH.

To use the reference from the Analog Reference (AREF), call Cy_CTB_FastInit with Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref.

To use an external reference from a GPIO, call Cy_CTB_FastInit with Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5 for Pins 5 on the CTB port.

struct cy_stc_ctdac_config_t
#include <cy_ctdac.h>

Configuration structure to set up the entire CTDAC block to be used with Cy_CTDAC_Init.

Public Members

cy_en_ctdac_ref_source_t refSource

Reference source: Vdda or externally through Opamp1 of CTB.

cy_en_ctdac_format_t formatMode

Format of DAC value: signed or unsigned.

cy_en_ctdac_update_t updateMode

Update mode: direct or buffered writes or hardware, edge or level.

cy_en_ctdac_deglitch_t deglitchMode

Deglitch mode: disabled, buffered, unbuffered, or both.

cy_en_ctdac_output_mode_t outputMode

Output mode: enabled (value or value + 1), high-z, Vssa, or Vdda.

cy_en_ctdac_output_buffer_t outputBuffer

Output path: Buffered through Opamp0 of CTB or connected directly to Pin 6.

cy_en_ctdac_deep_sleep_t deepSleep

Enable or disable the CTDAC during Deep Sleep.

uint32_t deglitchCycles

Number of deglitch cycles from 0 to 63.

int32_t value

Current DAC value.

int32_t nextValue

Next DAC value for double buffering.

bool enableInterrupt

If true, enable interrupt when next value register is transferred to value register.

bool configClock

Configure or ignore clock information.

cy_en_divider_types_t dividerType

Specifies which type of divider to use.

Can be integer or fractional divider. Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE

uint32_t dividerNum

Specifies which divider of the selected type to configure.

Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE

uint32_t dividerIntValue

The integer divider value.

The divider value causes integer division of (divider value + 1). Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE or CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE

uint32_t dividerFracValue

The fractional divider value if using a fractional clock.

Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE or CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE

struct cy_stc_ctdac_fast_config_t
#include <cy_ctdac.h>

Configuration structure to quickly set up the CTDAC to be used with Cy_CTDAC_FastInit This structure provides a selection for the CTDAC reference source and output path.

The other configuration options are set to:

Public Members

cy_en_ctdac_ref_source_t refSource

Reference source: Vdda or externally through Opamp1 of CTB.

cy_en_ctdac_output_buffer_t outputBuffer

Output path: Buffered through Opamp0 of CTB or connected directly to Pin 6.

struct cy_stc_ctdac_context_t
#include <cy_ctdac.h>

CTDAC context structure.

All fields for the context structure are internal. Firmware never reads or writes these values. Firmware allocates the structure and provides the address of the structure when registering the Cy_CTDAC_DeepSleepCallback. Firmware must ensure that the defined instance of this structure remains in scope while the drive is in use.

Public Members

uint32_t deglitchModeBeforeSleep

Tracks the state of the deglitch mode before sleep so that it can be re-enabled after wakeup.