Basic Configuration Functions

group group_ctdac_functions_basic

This set of functions are for configuring basic usage of the CTDAC.

Functions

__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.