PSoC 6 Hardware Abstraction Layer (HAL)
DAC (Digital to Analog Converter)

General Description

High level interface for interacting with the Cypress DAC.

This block drives a pin with a firmware configurable voltage. See the device datasheet for details on which pins support DAC output.

The cyhal_dac_write and cyhal_dac_read APIs are defined relative to the DAC's output voltage range, which is device dependent.

Macros

#define CYHAL_DAC_RSLT_BAD_ARGUMENT   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_DAC, 0))
 
#define CYHAL_DAC_RSLT_FAILED_INIT   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_DAC, 1))
 

Functions

cy_rslt_t cyhal_dac_init (cyhal_dac_t *obj, cyhal_gpio_t pin)
 
void cyhal_dac_free (cyhal_dac_t *obj)
 
void cyhal_dac_write (const cyhal_dac_t *obj, uint16_t value)
 
uint16_t cyhal_dac_read (cyhal_dac_t *obj)
 

Macro Definition Documentation

◆ CYHAL_DAC_RSLT_BAD_ARGUMENT

#define CYHAL_DAC_RSLT_BAD_ARGUMENT   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_DAC, 0))

Bad argument

◆ CYHAL_DAC_RSLT_FAILED_INIT

#define CYHAL_DAC_RSLT_FAILED_INIT   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_DAC, 1))

Failed to initialize DAC

Function Documentation

◆ cyhal_dac_init()

cy_rslt_t cyhal_dac_init ( cyhal_dac_t *  obj,
cyhal_gpio_t  pin 
)

Initialize the DAC peripheral

Configures the pin used by dac.

Parameters
[in]objThe dac object to initialize
[in]pinThe dac pin name
Returns
The status of the init request

◆ cyhal_dac_free()

void cyhal_dac_free ( cyhal_dac_t *  obj)

Release the dac object

Parameters
[in,out]objThe dac object

◆ cyhal_dac_write()

void cyhal_dac_write ( const cyhal_dac_t *  obj,
uint16_t  value 
)

Set the output voltage, as a normalized unsigned 16-bit value (where 0 is the lowest value the DAC can output and 0xFFFF is the highest)

Parameters
[in]objThe dac object
[in]valueThe 16-bit output value to set

◆ cyhal_dac_read()

uint16_t cyhal_dac_read ( cyhal_dac_t *  obj)

Read the current DAC output voltage setting, as a normalized unsigned 16-bit value (where 0 is the lowest value the DAC can output and 0xFFFF is the highest). Note: Depending on the precision of the underlying hardware, this may not precisely match the most recent value passed in to cyhal_dac_write.

Parameters
[in]objThe dac object
Returns
The 16-bit output value