Initialization Functions

group group_ctdac_functions_init

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

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