Digital to Analog Converter#

Introduction#

The Digital-to-Analog Converter (DAC) is a crucial component used to convert digital signals (binary data) into analog signals (continuous voltage or current). DACs are widely used in various applications, including audio systems, telecommunications, and control systems, where precise analog output is required.

DAC Block DiagramDAC Block Diagram

Common use cases include:

  • Audio Systems: Converting digital audio signals for playback.

  • Telecommunications: Modulating digital data onto an analog carrier.

  • Control Systems: Generating analog control signals for process control.

  • Signal Processing: Handling analog signals in various applications.

Configuration#

DAC configuration involves setting parameters such as the operation mode, sampling rate, and FIFO threshold. The configuration structure sl_dac_config_t is used to set these parameters, including operation mode (sl_dac_operation_mode_t), sampling rate, and more. The configuration is then applied using the sl_si91x_dac_set_configuration() API.

For detailed information on available configuration parameters, see the specific peripheral example README document.

Usage#

After defining the DAC configuration structures and passing an instance of sl_dac_config_t, the common DAC functions can be used to initiate and configure the DAC. The typical flow for implementation is as follows:

  1. Initialize the DAC: sl_si91x_dac_init

  2. Set the DAC configuration: sl_si91x_dac_set_configuration

  3. Register the event callback (if required): sl_si91x_dac_register_event_callback

  4. Write data to DAC: sl_si91x_dac_write_data

  5. Start DAC operation: sl_si91x_dac_start

  6. (Optional) Rewrite data for FIFO mode: sl_si91x_dac_rewrite_data

  7. Deinitialize the DAC: 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 modes.

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

Typedefs#

typedef void(*
sl_dac_callback_t)(uint8_t event)

Typedef for a user-defined callback function, triggered upon the completion of a DAC sample.

Functions#

sl_status_t
sl_si91x_dac_init(sl_dac_clock_config_t *dac_clock)

To initialize the DAC (Digital to Analog Converter).

sl_status_t
sl_si91x_dac_set_configuration(sl_dac_config_t dac_config, float vref_value)

To configure DAC control parameters.

sl_status_t
sl_si91x_dac_write_data(int16_t *data, uint16_t length)

To write digital input samples to the DAC.

sl_status_t
sl_si91x_dac_read_data(uint16_t *dac_output_data)

To read the DAC sampled output data.

sl_status_t
sl_si91x_dac_get_achieved_sample_clock(uint32_t sample_rate, uint32_t *sample_clock)

To get the DAC sample clock.

sl_status_t
sl_si91x_dac_rewrite_data(int16_t *data, uint16_t length)

To rewrite the DAC sample data.

sl_status_t
sl_si91x_dac_register_event_callback(sl_dac_callback_t callback_event)

To register the user callback function.

sl_status_t

To unregister the user callback function.

sl_status_t

To start the DAC operation.

sl_status_t

To stop the DAC operation.

sl_status_t

To deinitialize the DAC module.

To get the DAC version.

Enumeration Documentation#

sl_dac_operation_mode_t#

sl_dac_operation_mode_t

Enumeration for DAC operation modes.

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. It is intended to route DAC output directly to ADC input for processing.

SL_DAC_OPERATION_MODE_LAST

Last member of enum for validation.


Definition at line 69 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 79 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 channels.

This enum is only used in the 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 88 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 a user-defined callback function, triggered upon the completion of a DAC sample.

Parameters
[in]event

DAC event identifier for various interrupts.


Definition at line 60 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)

To initialize the DAC (Digital to Analog Converter).

Parameters
[in]dac_clock

Pointer to the DAC clock configuration structure ( sl_dac_clock_config_t).

This API enables the DAC peripheral and sets the clock for the DAC controller.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully initialized the DAC.

    • SL_STATUS_FAIL (0x0001) - The function failed.

    • SL_STATUS_NOT_INITIALIZED (0x0011) - Clock is not initialized.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

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

For more information on status codes, see SL STATUS DOCUMENTATION.

Note

  • Default value is recommended for DAC clock configurations.


Definition at line 158 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)

To configure DAC control parameters.

Parameters
[in]dac_config

DAC configuration structure variable, see sl_dac_config_t.

[in]vref_value

Reference voltage in the range of 1.8 to 3.6 V.

This API configures the DAC control parameters, including:

  • 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

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully configured the DAC.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch range.

For more information on status codes, see SL STATUS DOCUMENTATION.

Note

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


Definition at line 185 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)

To write digital input samples to the DAC.

Parameters
[in]data

Pointer to the input samples buffer.

[in]length

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

This API writes the digital sample to both dynamic and static modes of the DAC.

  • When Static mode is enabled, any data written to the Data Register (DR) will bypass the FIFO and be sent directly to the DAC for playback. Only a single sample can be held at a time.

  • If FIFO mode is enabled, data is written to the FIFO.

Note

  • For static mode, the sample length is 1.

  • For FIFO mode, the sample length is 1 - 1024.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully wrote the data to the DAC.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch range.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 213 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)

To read the DAC sampled output data.

Parameters
[out]dac_output_data

Pointer to store the DAC data read from the data register.

This API reads the sampled output data of the DAC from the data register for dynamic and static modes, returning the last data played on the DAC.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully read the data from the DAC.

    • SL_STATUS_FAIL (0x0001) - Function failed.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 236 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)

To get the DAC sample clock.

Parameters
[in]sample_rate

Sample rate for input data per second in the range of (63-5000000).

[out]sample_clock

Pointer to store the achieved sample frequency value.

This API reads the AUX clock and returns the achieved sample clock.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully got the achieved sample clock.

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch range.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 257 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)

To rewrite the DAC sample data.

Parameters
[in]data

Pointer to the input samples buffer.

[in]length

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

This API rewrites the input sample data in DAC FIFO operating mode, continuously rewriting the sample data in the DAC.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully rewrote the sample data.

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

    • SL_STATUS_INVALID_RANGE (0x0028) - Mismatch range.

For more information on status codes, see SL STATUS DOCUMENTATION.

Note

  • The rewrite is only applicable for FIFO mode.


Definition at line 283 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)

To register the user callback function.

Parameters
[in]callback_event

Pointer to the function which needs to be called at the time of interrupt, see sl_dac_callback_t.

This API registers a user-provided callback function that is invoked when an event occurs.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully registered the callback.

    • SL_STATUS_BUSY (0x0004) - Driver is busy.

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

For more information on status codes, see SL STATUS DOCUMENTATION.

Note

  • Before calling this function again, it is mandatory to call the sl_si91x_dac_unregister_event_callback function to unregister the callback; otherwise, it returns the SL_STATUS_BUSY error code.


Definition at line 307 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 )

To unregister the user callback function.

Parameters
N/A

This API unregisters the previously registered user callback function.

Note

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

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully deregistered the callback.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 325 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 )

To start the DAC operation.

Parameters
N/A

This API starts writing the samples in static/FIFO modes.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully started the DAC operation.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 344 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 )

To stop the DAC operation.

Parameters
N/A

This API stops writing the samples in static/FIFO modes.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully stopped the DAC operation.

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 364 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 )

To deinitialize the DAC module.

Parameters
N/A

This API deinitializes the DAC module, releases the hardware resources, and resets the DAC parameters.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Successfully deinitialized the DAC module.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

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

For more information on status codes, see SL STATUS DOCUMENTATION.


Definition at line 382 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 )

To get the DAC version.

Parameters
N/A

This API returns the release, major, and minor versions of the DAC.

Returns


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