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:
Audio Systems
Telecommunications
Control Systems
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.
As part of DAC configuration, available parameters include mode of operation by configuring sl_dac_operation_mode_t, DAC sampling rate in the range of (63-5000000 samples per second), FIFO threshold in the range of (0-7), and if mode of operation is Reference voltage for ADC, then the channel sl_channel_id_for_adc_t must be set. All of this can be configured through sl_dac_config_t, and then call the API sl_si91x_dac_set_configuration().
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.
sl_si91x_dac_rewrite_data (For FIFO mode of DAC operation)
Modules#
Enumerations#
Enumeration for DAC operation mode.
Enumeration for DAC callback events.
Enumeration for ADC channel this enum only used on Reference voltage for ADC mode of DAC.
Typedefs#
Typedef for user supplied callback function which is called when a DAC samples completes.
Variables#
Release version number.
sqa version number
dev version number
Division Factor.
SoC PLL clock frequency.
SoC PLL reference clock frequency.
Functions#
Initializes the DAC(Digital to Analog Converter).
Configure DAC control parameters.
Writes digital input samples to DAC and also writes the digital sample to both dynamic and static mode of DAC.
Read DAC analog output data.
Get the DAC sample clock.
Rewrite the DAC sample data.
Register the user callback function.
Unregister the user callback function.
Start the DAC operation.
Stop the DAC operation.
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. |
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. |
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. |
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.
[in] | event | DAC event for different interrupt. |
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.
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
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
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.
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.
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.
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
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
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
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
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
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
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).
[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.
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.
[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)
Pre-condition:
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.
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.
[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'.
Pre-condition:
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
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.
[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.
Pre-conditions:
Returns
Status 0 for successful execution (SL_STATUS_OK)
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.
[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.
Pre-conditions:
Returns
Status 0 if successful, else error code:
SL_STATUS_OK (0x0000) - Success
SL_STATUS_INVALID_RANGE (0x0028) - Mismatch Range
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.
[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.
Pre-conditions:
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.
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.
[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.
Pre-conditions:
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
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 SL_STATUS_BUSY error code.
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.
[in] |
Note
It is mandatory to call this function before registering the callback again.
Pre-condition:
Returns
Status 0 for successful execution (SL_STATUS_OK)
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.
N/A |
It will enable signal to DAC, enable path to DAC controller, enable the DAC FIFO config and enable dynamic.
Pre-conditions:
Returns
Status 0 for successful execution (SL_STATUS_OK)
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.
N/A |
It will stop signal to DAC, disconnect path to DAC controller and disable the DAC FIFO config.
Pre-conditions:
Returns
Status 0 for successful execution (SL_STATUS_OK)
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.
N/A |
It will shutdown/power_off the power of DAC.
Pre-condition:
Returns
Status 0 for successful execution (SL_STATUS_OK)
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.
[in] |
Returns the release, SQA, and dev versions of the DAC.
Returns
(sl_dac_version_t) type structure
298
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h