VDAC - Digital to Analog Voltage Converter.#
Digital to Analog Voltage Converter (VDAC) Peripheral API.
This module contains functions to control the VDAC peripheral of Silicon Labs' 32-bit MCUs and SoCs. VDAC converts digital values to analog signals at up to 500 ksps with 12-bit accuracy. VDAC is designed for low energy consumption, but can also provide very good performance.
The following steps are necessary for basic operation:
Clock enable:
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_VDAC0);
Initialize the VDAC with default settings and modify selected fields:
sl_hal_vdac_init_t vdac_init = SL_HAL_VDAC_INIT_DEFAULT;
sl_hal_vdac_init_channel_t vdac_channel_init = SL_HAL_VDAC_CHANNEL_INIT_DEFAULT;
Set prescaler to get 1 MHz VDAC clock frequency. Calculate clock frequency used for VDAC.
sl_clock_branch_t clock_branch;
uint32_t src_clk_freq;
clock_branch = sl_device_peripheral_get_clock_branch(SL_PERIPHERAL_VDAC0);
sl_clock_manager_get_clock_branch_frequency(clock_branch, &src_clk_freq);
vdac_init.prescaler = sl_hal_vdac_calculate_prescaler(VDAC0, 1000000, src_clk_freq);
sl_hal_vdac_init(VDAC0, &vdac_init);
sl_hal_vdac_init_channel(VDAC0, &vdac_channel_init, 0);
sl_hal_vdac_enable_channel(VDAC0, 0);
Perform a conversion:
sl_hal_vdac_set_output_channel(VDAC0, 0, 250);
Modules#
Enumerations#
Channel refresh period.
Timer overflow period.
Reference voltage for VDAC.
Refresh source for VDAC.
Channel conversion trigger mode.
Channel power mode.
VDAC channel Abus port selection.
Functions#
Initialize VDAC.
Initialize a VDAC channel.
Enable the VDAC channel.
Disable the VDAC channel.
Set the output signal of a VDAC channel to a given value.
Calculate the prescaler value used to determine VDAC clock.
Reset VDAC to its default state.
Wait for the vdac to complete all synchronization of register changes and commands.
Wait for the vdac to be completely disabled.
Enables the VDAC module.
Disables the VDAC module and ensures all operations are synchronized.
Enable one or more VDAC interrupts.
Disable one or more VDAC interrupts.
Set one or more pending VDAC interrupts from SW.
Clear one or more pending VDAC interrupts.
Get pending VDAC interrupt flags.
Get enabled and pending VDAC interrupt flags.
Start Sine mode.
Stop Sine mode.
Get the VDAC Status register.
Macros#
VDAC instance validation.
Default configuration for VDAC initialization structure.
Sine mode configuration for VDAC initialization structure.
Default configuration for VDAC channel initialization structure.
Enumeration Documentation#
sl_hal_vdac_channel_t#
sl_hal_vdac_channel_t
VDAC channel.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_CHANNEL_0 | Channel 0 of VDAC. |
| SL_HAL_VDAC_CHANNEL_1 | Channel 1 of VDAC. |
sl_hal_vdac_refresh_t#
sl_hal_vdac_refresh_t
Channel refresh period.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_REFRESH_CYCLES_2 | Refresh every 2 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_4 | Refresh every 4 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_8 | Refresh every 8 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_16 | Refresh every 16 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_32 | Refresh every 32 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_64 | Refresh every 64 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_128 | Refresh every 128 clock cycles. |
| SL_HAL_VDAC_REFRESH_CYCLES_256 | Refresh every 256 clock cycles. |
sl_hal_vdac_timer_overflow_period_t#
sl_hal_vdac_timer_overflow_period_t
Timer overflow period.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_OVERFLOW_CYCLE_2 | Overflows every 2 clock cycles. |
| SL_HAL_VDAC_OVERFLOW_CYCLE_4 | Overflows every 4 clock cycles. |
| SL_HAL_VDAC_OVERFLOW_CYCLE_8 | Overflows every 8 clock cycles. |
| SL_HAL_VDAC_OVERFLOW_CYCLE_16 | Overflows every 16 clock cycles. |
| SL_HAL_VDAC_OVERFLOW_CYCLE_32 | Overflows every 32 clock cycles. |
| SL_HAL_VDAC_OVERFLOW_CYCLE_64 | Overflows every 64 clock cycles. |
sl_hal_vdac_vref_t#
sl_hal_vdac_vref_t
Reference voltage for VDAC.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_VREF_1V25 | Internal 1.25 V band gap reference. |
| SL_HAL_VDAC_VREF_2V5 | Internal 2.5 V band gap reference. |
| SL_HAL_VDAC_VREF_AVDD | AVDD reference. |
| SL_HAL_VDAC_VREF_EXTERNAL_PIN | External pin reference. |
sl_hal_vdac_refresh_source_t#
sl_hal_vdac_refresh_source_t
Refresh source for VDAC.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_REFRESH_NONE | No refresh source. |
| SL_HAL_VDAC_REFRESH_SOURCE_TIMER | Refresh triggered by refresh timer overflow. |
| SL_HAL_VDAC_REFRESH_SYNC_PRS | Refresh triggered by sync PRS. |
| SL_HAL_VDAC_REFRESH_ASYNC_PRS | Refresh triggered by async PRS. |
sl_hal_vdac_trigger_mode_t#
sl_hal_vdac_trigger_mode_t
Channel conversion trigger mode.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_TRIGGER_MODE_NONE | No conversion trigger source selected. |
| SL_HAL_VDAC_TRIGGER_MODE_SW | Channel is triggered by CHnDATA or COMBDATA write. |
| SL_HAL_VDAC_TRIGGER_MODE_SYNC_PRS | Channel is triggered by Sync PRS input. |
| SL_HAL_VDAC_TRIGGER_MODE_LESENSE | Channel is triggered by LESENSE. |
| SL_HAL_VDAC_TRIGGER_MODE_INTERNAL_TIMER | Channel is triggered by Internal Timer. |
| SL_HAL_VDAC_TRIGGER_MODE_ASYNC_PRS | Channel is triggered by Async PRS input. |
sl_hal_vdac_power_mode_t#
sl_hal_vdac_power_mode_t
Channel power mode.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_POWER_MODE_HIGH_POWER | High power buffer mode. |
| SL_HAL_VDAC_POWER_MODE_LOW_POWER | Low power buffer mode. |
sl_hal_vdac_port_selection_t#
sl_hal_vdac_port_selection_t
VDAC channel Abus port selection.
| Enumerator | |
|---|---|
| SL_HAL_VDAC_PORT_NONE | No GPIO selected. |
| SL_HAL_VDAC_PORT_A | Port A selected. |
| SL_HAL_VDAC_PORT_B | Port B selected. |
| SL_HAL_VDAC_PORT_C | Port C selected. |
| SL_HAL_VDAC_PORT_D | Port D selected. |
Function Documentation#
sl_hal_vdac_init#
void sl_hal_vdac_init (VDAC_TypeDef * vdac, const sl_hal_vdac_init_t * init)
Initialize VDAC.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| const sl_hal_vdac_init_t * | [in] | init | A pointer to the VDAC initialization structure. |
Initializes the common parts for both channels. This function will also load calibration values from the Device Information (DI) page into the VDAC calibration register. To complete a VDAC setup, channel control configuration must also be done. See sl_hal_vdac_init_channel().
Note
This function will disable both channels prior to configuration.
sl_hal_vdac_init_channel#
void sl_hal_vdac_init_channel (VDAC_TypeDef * vdac, const sl_hal_vdac_init_channel_t * init, uint32_t channel)
Initialize a VDAC channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| const sl_hal_vdac_init_channel_t * | [in] | init | A pointer to the VDAC channel initialization structure. |
| uint32_t | [in] | channel | A channel number to initialize. |
Configures a specific VDAC channel with the provided settings.
sl_hal_vdac_enable_channel#
void sl_hal_vdac_enable_channel (VDAC_TypeDef * vdac, uint32_t channel)
Enable the VDAC channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | channel | A channel to enable. |
sl_hal_vdac_disable_channel#
void sl_hal_vdac_disable_channel (VDAC_TypeDef * vdac, uint32_t channel)
Disable the VDAC channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | channel | A channel to disable. |
sl_hal_vdac_set_output_channel#
void sl_hal_vdac_set_output_channel (VDAC_TypeDef * vdac, uint32_t channel, uint32_t value)
Set the output signal of a VDAC channel to a given value.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | channel | A channel number to set the output of. |
| uint32_t | [in] | value | A value to write to the channel output register CHnDATA. |
This function sets the output signal of a VDAC channel by writing value to the corresponding CHnDATA register.
sl_hal_vdac_calculate_prescaler#
uint32_t sl_hal_vdac_calculate_prescaler (VDAC_TypeDef * vdac, uint32_t vdac_frequency, uint32_t reference_frequency)
Calculate the prescaler value used to determine VDAC clock.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | vdac_frequency | VDAC frequency target. The frequency will automatically be adjusted to be below the maximum allowed VDAC clock. |
| uint32_t | [in] | reference_frequency | Frequency in Hz of the reference VDAC. |
The VDAC clock is given by the input clock divided by the prescaler+1. VDAC_CLK = IN_CLK / (prescale + 1) The maximum VDAC clock is 1 MHz.
Note
If the requested VDAC frequency is low and the maximum prescaler value can't adjust the actual VDAC frequency lower than requested, the maximum prescaler value is returned resulting in a higher VDAC frequency than requested.
Returns
A prescaler value to use for VDAC to achieve a clock value less than or equal to
vdac_frequency.
sl_hal_vdac_reset#
void sl_hal_vdac_reset (VDAC_TypeDef * vdac)
Reset VDAC to its default state.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
sl_hal_vdac_wait_sync#
void sl_hal_vdac_wait_sync (VDAC_TypeDef * vdac)
Wait for the vdac to complete all synchronization of register changes and commands.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
sl_hal_vdac_wait_ready#
void sl_hal_vdac_wait_ready (VDAC_TypeDef * vdac)
Wait for the vdac to be completely disabled.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
sl_hal_vdac_enable#
void sl_hal_vdac_enable (VDAC_TypeDef * vdac)
Enables the VDAC module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
sl_hal_vdac_disable#
void sl_hal_vdac_disable (VDAC_TypeDef * vdac)
Disables the VDAC module and ensures all operations are synchronized.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
sl_hal_vdac_enable_interrupts#
void sl_hal_vdac_enable_interrupts (VDAC_TypeDef * vdac, uint32_t flags)
Enable one or more VDAC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | flags | VDAC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn). |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using sl_hal_vdac_clear_interrupts() prior to enabling the interrupt.
sl_hal_vdac_disable_interrupts#
void sl_hal_vdac_disable_interrupts (VDAC_TypeDef * vdac, uint32_t flags)
Disable one or more VDAC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | flags | VDAC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn). |
sl_hal_vdac_set_interrupts#
void sl_hal_vdac_set_interrupts (VDAC_TypeDef * vdac, uint32_t flags)
Set one or more pending VDAC interrupts from SW.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | flags | VDAC interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn). |
sl_hal_vdac_clear_interrupts#
void sl_hal_vdac_clear_interrupts (VDAC_TypeDef * vdac, uint32_t flags)
Clear one or more pending VDAC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
| uint32_t | [in] | flags | Pending VDAC interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn). |
sl_hal_vdac_get_pending_interrupts#
uint32_t sl_hal_vdac_get_pending_interrupts (VDAC_TypeDef * vdac)
Get pending VDAC interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
Returns
VDAC interrupt sources pending. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn).
sl_hal_vdac_get_enabled_pending_interrupts#
uint32_t sl_hal_vdac_get_enabled_pending_interrupts (VDAC_TypeDef * vdac)
Get enabled and pending VDAC interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Returns
Pending and enabled VDAC interrupt sources. The return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in VDACx_IEN_nnn register (VDACx_IEN_nnn) and
the OR combination of valid interrupt flags of the VDAC module (VDACx_IF_nnn).
Note
Interrupt flags are not cleared by the use of this function.
sl_hal_vdac_sine_mode_start#
void sl_hal_vdac_sine_mode_start (VDAC_TypeDef * vdac)
Start Sine mode.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
This function sends the sine mode start signal to the DAC.
sl_hal_vdac_sine_mode_stop#
void sl_hal_vdac_sine_mode_stop (VDAC_TypeDef * vdac)
Stop Sine mode.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
This function sends the sine mode stop signal to the DAC.
sl_hal_vdac_get_status#
uint32_t sl_hal_vdac_get_status (VDAC_TypeDef * vdac)
Get the VDAC Status register.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| VDAC_TypeDef * | [in] | vdac | A pointer to the VDAC peripheral register block. |
Returns
Current STATUS register value.