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.
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:
Initialize the DAC: sl_si91x_dac_init
Set the DAC configuration: sl_si91x_dac_set_configuration
Register the event callback (if required): sl_si91x_dac_register_event_callback
Write data to DAC: sl_si91x_dac_write_data
Start DAC operation: sl_si91x_dac_start
(Optional) Rewrite data for FIFO mode: sl_si91x_dac_rewrite_data
Deinitialize the DAC: sl_si91x_dac_deinit
Modules#
Enumerations#
Enumeration for DAC operation modes.
Enumeration for DAC callback events.
Enumeration for ADC channels.
Typedefs#
Typedef for a user-defined callback function, triggered upon the completion of a DAC sample.
Functions#
To initialize the DAC (Digital to Analog Converter).
To configure DAC control parameters.
To write digital input samples to the DAC.
To read the DAC sampled output data.
To get the DAC sample clock.
To rewrite the DAC sample data.
To register the user callback function.
To unregister the user callback function.
To start the DAC operation.
To stop the DAC operation.
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. |
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. |
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. |
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.
[in] | event | DAC event identifier for various interrupts. |
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).
[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.
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.
[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)
Pre-condition:
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.
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.
[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.
Pre-condition:
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.
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.
[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.
Pre-conditions:
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.
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.
[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.
Pre-conditions:
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.
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.
[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.
Pre-conditions:
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.
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.
[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.
Pre-conditions:
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.
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.
N/A |
This API unregisters the previously registered user callback function.
Note
It is mandatory to call this function before registering the callback again.
Pre-condition:
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.
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.
N/A |
This API starts writing the samples in static/FIFO modes.
Pre-conditions:
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.
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.
N/A |
This API stops writing the samples in static/FIFO modes.
Pre-conditions:
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.
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.
N/A |
This API deinitializes the DAC module, releases the hardware resources, and resets the DAC parameters.
Pre-conditions:
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.
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.
N/A |
This API returns the release, major, and minor versions of the DAC.
Returns
sl_dac_version_t Structure containing the DAC version information, see sl_dac_version_t.
392
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h