High level interface for interacting with the digital to analog converter (DAC).
This block drives a pin with a firmware configurable voltage. See the device datasheet for details on which pins support DAC output.
The DAC driver provides APIs to:
Call cyhal_dac_init to initialize a DAC instance by providing the DAC object ( obj ) and an output pin ( pin ).
See Use case 1: Simple DAC initialization.
The following snippet initializes a DAC resource and assigns the output to the specified pin using cyhal_dac_init. cyhal_dac_write is used to set the DAC output value. cyhal_dac_read is used to read back DAC register.
API Reference | |
DAC HAL Results | |
DAC specific return codes. | |
Enumerations | |
enum | cyhal_dac_ref_t { CYHAL_DAC_REF_VDDA , CYHAL_DAC_REF_VREF } |
Reference choices for the DAC. More... | |
Functions | |
cy_rslt_t | cyhal_dac_init (cyhal_dac_t *obj, cyhal_gpio_t pin) |
Initialize the DAC peripheral. More... | |
cy_rslt_t | cyhal_dac_init_cfg (cyhal_dac_t *obj, const cyhal_dac_configurator_t *cfg) |
Initialize the DAC peripheral using a configurator generated configuration struct. More... | |
void | cyhal_dac_free (cyhal_dac_t *obj) |
Release the dac object. More... | |
cy_rslt_t | cyhal_dac_set_reference (cyhal_dac_t *obj, cyhal_dac_ref_t ref) |
Set the DAC voltage reference. More... | |
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) More... | |
cy_rslt_t | cyhal_dac_write_mv (const cyhal_dac_t *obj, uint16_t value) |
Set the output voltage, as an unsigned number of millivolts. More... | |
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). More... | |
cy_rslt_t | cyhal_dac_set_power (cyhal_dac_t *obj, cyhal_power_level_t power) |
Changes the current operating power level of the DAC. More... | |
enum cyhal_dac_ref_t |
cy_rslt_t cyhal_dac_init | ( | cyhal_dac_t * | obj, |
cyhal_gpio_t | pin | ||
) |
Initialize the DAC peripheral.
By default, the reference will be set to CYHAL_DAC_REF_VDDA.
[out] | obj | Pointer to a DAC object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | pin | The dac pin name |
cy_rslt_t cyhal_dac_init_cfg | ( | cyhal_dac_t * | obj, |
const cyhal_dac_configurator_t * | cfg | ||
) |
Initialize the DAC peripheral using a configurator generated configuration struct.
[out] | obj | Pointer to a DAC object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | cfg | Configuration structure generated by a configurator. |
void cyhal_dac_free | ( | cyhal_dac_t * | obj | ) |
Release the dac object.
[in,out] | obj | The dac object |
cy_rslt_t cyhal_dac_set_reference | ( | cyhal_dac_t * | obj, |
cyhal_dac_ref_t | ref | ||
) |
Set the DAC voltage reference.
This determines the highest value that the DAC can output.
obj | The DAC object |
ref | The selected voltage reference. |
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)
[in] | obj | The dac object |
[in] | value | The 16-bit output value to set |
cy_rslt_t cyhal_dac_write_mv | ( | const cyhal_dac_t * | obj, |
uint16_t | value | ||
) |
Set the output voltage, as an unsigned number of millivolts.
It is an error to specify a value that is outside of the DAC's operating range.
[in] | obj | The dac object |
[in] | value | The number of millivolts to output set. |
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.
[in] | obj | The dac object |
cy_rslt_t cyhal_dac_set_power | ( | cyhal_dac_t * | obj, |
cyhal_power_level_t | power | ||
) |
Changes the current operating power level of the DAC.
If the power level is set to CYHAL_POWER_LEVEL_OFF, the DAC will be powered-off but it will retain its configuration, so it is not necessary to reconfigure it when changing the power level from CYHAL_POWER_LEVEL_OFF to any other value.
[in] | obj | dac object |
[in] | power | The power level to set |