Digital to Analog Converter#


Introduction#

DAC stands for Digital-to-Analog Converter. An analog signal, such as voltage or current, is transformed from digital signals, which are generally represented by binary digits, using a digital-to-analog converter (DAC). A DAC's objective is to generate a continuous, accurate analog output signal that matches the digital data entered. The number of unique analog output levels that a DAC can generate is known as its resolution, and it is based on the number of bits in the digital input.

  • An 10-bit DAC, for instance, can provide 2 ^ 10 (1024) different output levels. Finer granularity and superior analog signal representation are offered by higher resolution DACs.

  • Digital-to-Analog Converter (DACs) are integral components in controllers across various applications.

  • Here are some common use cases:

  1. Audio Systems

  2. Telecommunications

  3. Control Systems

  4. Signal Processing etc.,


Configuration#

  • Configuring a Digital-to-Analog Converter (DAC) normally entails various parameters and settings to enable appropriate operation and precise conversion of digital signals to analog signals.

  • For more information on configuring available parameters refer to the respective peripheral example readme document.


Usage#

The common DAC functions can be used after the DAC Structures are specified, passing an instance of sl_dac_config_t. These functions will initiate and configure the DAC below, which is the flow for implementation.

  1. sl_si91x_dac_init

  2. sl_si91x_dac_set_configuration

  3. sl_si91x_dac_register_event_callback

  4. sl_si91x_dac_write_data

  5. sl_si91x_dac_start

  6. sl_si91x_dac_rewrite_data (For FIFO mode of DAC operation)

  7. sl_si91x_dac_deinit

Modules#

sl_dac_version_t

sl_dac_clock_config_t

sl_dac_config_t

Enumerations#

enum
SL_DAC_FIFO_MODE
SL_DAC_STATIC_MODE
SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC
SL_DAC_OPERATION_MODE_LAST
}

Enumeration for DAC operation mode.

enum
SL_DAC_FIFO_MODE_EVENT = 1
SL_DAC_STATIC_MODE_EVENT
}

Enumeration for DAC callback events.

enum
SL_DAC_ADC_CHANNEL_0
SL_DAC_ADC_CHANNEL_1
SL_DAC_ADC_CHANNEL_2
SL_DAC_ADC_CHANNEL_3
SL_DAC_ADC_CHANNEL_4
SL_DAC_ADC_CHANNEL_5
SL_DAC_ADC_CHANNEL_6
SL_DAC_ADC_CHANNEL_7
SL_DAC_ADC_CHANNEL_8
SL_DAC_ADC_CHANNEL_9
SL_DAC_ADC_CHANNEL_10
SL_DAC_ADC_CHANNEL_11
SL_DAC_ADC_CHANNEL_12
SL_DAC_ADC_CHANNEL_13
SL_DAC_ADC_CHANNEL_14
SL_DAC_ADC_CHANNEL_15
}

Enumeration for ADC channel this enum only used on Reference voltage for ADC mode of DAC.

Typedefs#

typedef void(*
sl_dac_callback_t)(uint8_t event)

Typedef for user supplied callback function which is called when a DAC samples completes.

Variables#

uint8_t

Release version number.

uint8_t

sqa version number

uint8_t

dev version number

uint16_t

Division Factor.

uint32_t

SoC PLL clock frequency.

uint32_t

SoC PLL reference clock frequency.

uint8_t
uint8_t

Functions#

sl_status_t
sl_si91x_dac_init(sl_dac_clock_config_t *dac_clock)

Initializes the DAC(Digital to Analog Converter).

sl_status_t
sl_si91x_dac_set_configuration(sl_dac_config_t dac_config, float vref_value)

Configure DAC control parameters.

sl_status_t
sl_si91x_dac_write_data(int16_t *data, uint16_t length)

Writes digital input samples to DAC and also writes the digital sample to both dynamic and static mode of DAC.

sl_status_t
sl_si91x_dac_read_data(uint16_t *dac_output_data)

Read DAC analog output data.

sl_status_t
sl_si91x_dac_get_achieved_sample_clock(uint32_t sample_rate, uint32_t *sample_clock)

Get the DAC sample clock.

sl_status_t
sl_si91x_dac_rewrite_data(int16_t *data, uint16_t length)

Rewrite the DAC sample data.

sl_status_t
sl_si91x_dac_register_event_callback(sl_dac_callback_t callback_event)

Register the user callback function.

sl_status_t

Unregister the user callback function.

sl_status_t

Start the DAC operation.

sl_status_t

Stop the DAC operation.

sl_status_t

De-initialize the DAC.

Get the DAC version.

Enumeration Documentation#

sl_dac_operation_mode_t#

sl_dac_operation_mode_t

Enumeration for DAC operation mode.

Enumerator
SL_DAC_FIFO_MODE

operation mode as fifo mode

SL_DAC_STATIC_MODE

operation mode as static mode

SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC

This mode is currently not supported.

SL_DAC_OPERATION_MODE_LAST

Last member of enum for validation.


Definition at line 64 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_dac_callback_event_t#

sl_dac_callback_event_t

Enumeration for DAC callback events.

Enumerator
SL_DAC_FIFO_MODE_EVENT

Callback event for FIFO mode.

SL_DAC_STATIC_MODE_EVENT

Callback event for Static mode.


Definition at line 72 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_channel_id_for_adc_t#

sl_channel_id_for_adc_t

Enumeration for ADC channel this enum only used on Reference voltage for ADC mode of DAC.

note: These enums are not used as SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC mode is not supported currently.

Enumerator
SL_DAC_ADC_CHANNEL_0

ADC channel 0.

SL_DAC_ADC_CHANNEL_1

ADC channel 1.

SL_DAC_ADC_CHANNEL_2

ADC channel 2.

SL_DAC_ADC_CHANNEL_3

ADC channel 3.

SL_DAC_ADC_CHANNEL_4

ADC channel 4.

SL_DAC_ADC_CHANNEL_5

ADC channel 5.

SL_DAC_ADC_CHANNEL_6

ADC channel 6.

SL_DAC_ADC_CHANNEL_7

ADC channel 7.

SL_DAC_ADC_CHANNEL_8

ADC channel 8.

SL_DAC_ADC_CHANNEL_9

ADC channel 9.

SL_DAC_ADC_CHANNEL_10

ADC channel 10.

SL_DAC_ADC_CHANNEL_11

ADC channel 11.

SL_DAC_ADC_CHANNEL_12

ADC channel 12.

SL_DAC_ADC_CHANNEL_13

ADC channel 13.

SL_DAC_ADC_CHANNEL_14

ADC channel 14.

SL_DAC_ADC_CHANNEL_15

ADC channel 15.


Definition at line 79 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

Typedef Documentation#

sl_dac_callback_t#

typedef void(* sl_dac_callback_t) (uint8_t event) )(uint8_t event)

Typedef for user supplied callback function which is called when a DAC samples completes.

Parameters
[in]event

DAC event for different interrupt.


Definition at line 58 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

Variable Documentation#

release#

uint8_t sl_dac_version_t::release

Release version number.


Definition at line 100 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

major#

uint8_t sl_dac_version_t::major

sqa version number


Definition at line 101 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

minor#

uint8_t sl_dac_version_t::minor

dev version number


Definition at line 102 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

division_factor#

uint16_t sl_dac_clock_config_t::division_factor

Division Factor.


Definition at line 107 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

soc_pll_clock#

uint32_t sl_dac_clock_config_t::soc_pll_clock

SoC PLL clock frequency.


Definition at line 108 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

soc_pll_reference_clock#

uint32_t sl_dac_clock_config_t::soc_pll_reference_clock

SoC PLL reference clock frequency.


Definition at line 109 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

operating_mode#

uint8_t sl_dac_config_t::operating_mode

Definition at line 114 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

dac_fifo_threshold#

uint8_t sl_dac_config_t::dac_fifo_threshold

Definition at line 115 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

adc_channel#

uint8_t sl_dac_config_t::adc_channel

Definition at line 116 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

dac_sample_rate#

uint32_t sl_dac_config_t::dac_sample_rate

Definition at line 117 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

dac_pin#

uint8_t sl_dac_config_t::dac_pin

Definition at line 118 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

dac_port#

uint8_t sl_dac_config_t::dac_port

Definition at line 119 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

Function Documentation#

sl_si91x_dac_init#

sl_status_t sl_si91x_dac_init (sl_dac_clock_config_t * dac_clock)

Initializes the DAC(Digital to Analog Converter).

Parameters
[in]dac_clock

clock structure variables ( sl_dac_clock_config_t)

This API will enable on the DAC peripheral as well as set the clock for the DAC controller.

  • The DAC clock configurations are mentioned as follows:

    • soc_pll_clock (Frequency range: 1 MHz to 180 MHz),

    • soc_pll_reference_clock (Frequency range: 15 MHz to 65 MHz) and 

    • division_factor (0–63).

Returns

  • Status 0 if successful, else below are the error codes:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid

    • SL_STATUS_FAIL (0x0001) - The function failed

    • SL_STATUS_NOT_INITIALIZED (0x0011) - Clock is not initialized

Note

  • Default value is recommended for DAC clock configurations.


Definition at line 143 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_set_configuration#

sl_status_t sl_si91x_dac_set_configuration (sl_dac_config_t dac_config, float vref_value)

Configure DAC control parameters.

Parameters
[in]dac_config

DAC configuration structure variable ( sl_dac_config_t)

[in]vref_value

Reference voltage in the range of 1.8 to 3.6v.

The configurations are listed below:

  • Operation mode (Static/FIFO/Reference voltage for ADC)

  • Sample rate (63 sps to 5 Msps)

  • DAC FIFO Threshold value(0 to 7)

  • ADC Channel(0 to 15)

    Returns

    • Status 0 if successful, else error code:

      • SL_STATUS_OK (0x0000) - Success

      • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid

      • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch Range

    Note

    • In DAC If "Reference voltage for ADC" is the operation mode, choose ADC Channel.


Definition at line 162 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_write_data#

sl_status_t sl_si91x_dac_write_data (int16_t * data, uint16_t length)

Writes digital input samples to DAC and also writes the digital sample to both dynamic and static mode of DAC.

Parameters
[in]data

Input samples buffer pointer.

[in]length

Number of samples to play in DAC

If Static mode is enabled data written to the DR will not be written to the FIFO It will be played on DAC directly. Only single sample can be held at a time. If FIFO mode enabled. Data written to the DR is written to the FIFO in this mode. Note

  • For static mode sample length is '1'.

Returns

  • Status 0 if successful, else error code:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch Range


Definition at line 181 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_read_data#

sl_status_t sl_si91x_dac_read_data (uint16_t * dac_output_data)

Read DAC analog output data.

Parameters
[out]dac_output_data

DAC data will be read from DR and store in dac_output_data variable.

Reads the analog output data of the DAC from data register for dynamic and static mode, returning the last data played on DAC.

Returns

  • Status 0 for successful execution (SL_STATUS_OK)


Definition at line 195 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_get_achieved_sample_clock#

sl_status_t sl_si91x_dac_get_achieved_sample_clock (uint32_t sample_rate, uint32_t * sample_clock)

Get the DAC sample clock.

Parameters
[in]sample_rate

Sample rate to sample input data per sec in the range of (63- 5000000).

[out]sample_clock

Sample frequency value will return in this variable.

This API will read the configured clock and return the achieved sample clock.

Returns

  • Status 0 if successful, else error code:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch Range


Definition at line 209 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_rewrite_data#

sl_status_t sl_si91x_dac_rewrite_data (int16_t * data, uint16_t length)

Rewrite the DAC sample data.

Parameters
[in]data

Input samples buffer pointer.

[in]length

Number of samples to play in DAC in the range of (1- 1024).

Rewrites the input sample data in DAC FIFO operating mode, it will rewrite the sample data in DAC continuously.

Returns

  • Status 0 if successful, else error code:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch

Note

  • The rewrite is only applicable for FIFO mode.


Definition at line 227 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_register_event_callback#

sl_status_t sl_si91x_dac_register_event_callback (sl_dac_callback_t callback_event)

Register the user callback function.

Parameters
[in]callback_event

Pointer to the function which needs to be called at the time of interrupt ( sl_dac_callback_t)

At the time of events, the function passed in the parameter is called with the respective event as the parameter.

Returns

  • Status 0 if successful, else error code:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer

    • SL_STATUS_BUSY (0x0004) - Driver is busy

Note


Definition at line 246 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_unregister_event_callback#

sl_status_t sl_si91x_dac_unregister_event_callback (void )

Unregister the user callback function.

Parameters
[in]

Note

  • It is mandatory to call this function before registering the callback again.

Returns

  • Status 0 for successful execution (SL_STATUS_OK)


Definition at line 256 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_start#

sl_status_t sl_si91x_dac_start (void )

Start the DAC operation.

Parameters
N/A

It will enable signal to DAC, enable path to DAC controller, enable the DAC FIFO config and enable dynamic.

Returns

  • Status 0 for successful execution (SL_STATUS_OK)


Definition at line 268 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_stop#

sl_status_t sl_si91x_dac_stop (void )

Stop the DAC operation.

Parameters
N/A

It will stop signal to DAC, disconnect path to DAC controller and disable the DAC FIFO config.

Returns

  • Status 0 for successful execution (SL_STATUS_OK)


Definition at line 281 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_deinit#

sl_status_t sl_si91x_dac_deinit (void )

De-initialize the DAC.

Parameters
N/A

It will shutdown/power_off the power of DAC.

Returns

  • Status 0 for successful execution (SL_STATUS_OK)


Definition at line 289 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h

sl_si91x_dac_get_version#

sl_dac_version_t sl_si91x_dac_get_version (void )

Get the DAC version.

Parameters
[in]

Returns the release, SQA, and dev versions of the DAC.

Returns


Definition at line 298 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h