VDAC - Voltage DAC

Description

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:

Initialize the VDAC with default settings and modify selected fields:

// Set prescaler to get 1 MHz VDAC clock frequency.
vdacInit. prescaler = VDAC_PrescaleCalc (1000000, true , 0); // function call for series 0/1
VDAC_Init (VDAC0, &vdacInit);
vdacChInit. enable = true ;
VDAC_InitChannel (VDAC0, &vdacChInit, 0);

Perform a conversion:

VDAC_ChannelOutputSet (VDAC0, 0, 250);
Note
The output stage of a VDAC channel consists of an on-chip operational amplifier (OPAMP) in the OPAMP module. This OPAMP is highly configurable; and to exploit the VDAC functionality fully, configure the OPAMP using the OPAMP API. Using the OPAMP API also loads OPAMP calibration values. The default (reset) settings of OPAMP is sufficient for many applications.

Data Structures

struct VDAC_Init_TypeDef
VDAC initialization structure, common for both channels.
struct VDAC_InitChannel_TypeDef
VDAC channel initialization structure.

Functions

void VDAC_ChannelOutputSet (VDAC_TypeDef *vdac, unsigned int channel, uint32_t value)
Set the output signal of a VDAC channel to a given value.
void VDAC_Enable (VDAC_TypeDef *vdac, unsigned int ch, bool enable)
Enable/disable the VDAC channel.
void VDAC_Init (VDAC_TypeDef *vdac, const VDAC_Init_TypeDef *init)
Initialize VDAC.
void VDAC_InitChannel (VDAC_TypeDef *vdac, const VDAC_InitChannel_TypeDef *init, unsigned int ch)
Initialize a VDAC channel.
void VDAC_Channel0OutputSet (VDAC_TypeDef *vdac, uint32_t value)
Set the output signal of VDAC channel 0 to a given value.
void VDAC_Channel1OutputSet (VDAC_TypeDef *vdac, uint32_t value)
Set the output signal of VDAC channel 1 to a given value.
void VDAC_IntClear (VDAC_TypeDef *vdac, uint32_t flags)
Clear one or more pending VDAC interrupts.
void VDAC_IntDisable (VDAC_TypeDef *vdac, uint32_t flags)
Disable one or more VDAC interrupts.
void VDAC_IntEnable (VDAC_TypeDef *vdac, uint32_t flags)
Enable one or more VDAC interrupts.
uint32_t VDAC_IntGet (VDAC_TypeDef *vdac)
Get pending VDAC interrupt flags.
uint32_t VDAC_IntGetEnabled (VDAC_TypeDef *vdac)
Get enabled and pending VDAC interrupt flags.
void VDAC_IntSet (VDAC_TypeDef *vdac, uint32_t flags)
Set one or more pending VDAC interrupts from SW.
uint32_t VDAC_PrescaleCalc (uint32_t vdacFreq, bool syncMode, uint32_t hfperFreq)
Calculate the prescaler value used to determine VDAC clock.
void VDAC_Reset (VDAC_TypeDef *vdac)
Reset VDAC to same state that it was in after a hardwares reset.

Macros

#define VDAC_INIT_DEFAULT
Default configuration for VDAC initialization structure.
#define VDAC_INITCHANNEL_DEFAULT
Default configuration for VDAC channel initialization structure.

Enumerations

enum VDAC_Refresh_TypeDef {
vdacRefresh8 = _VDAC_CTRL_REFRESHPERIOD_8CYCLES,
vdacRefresh16 = _VDAC_CTRL_REFRESHPERIOD_16CYCLES,
vdacRefresh32 = _VDAC_CTRL_REFRESHPERIOD_32CYCLES,
vdacRefresh64 = _VDAC_CTRL_REFRESHPERIOD_64CYCLES
}
Channel refresh period.
enum VDAC_Ref_TypeDef {
vdacRef1V25Ln = _VDAC_CTRL_REFSEL_1V25LN,
vdacRef2V5Ln = _VDAC_CTRL_REFSEL_2V5LN,
vdacRef1V25 = _VDAC_CTRL_REFSEL_1V25,
vdacRef2V5 = _VDAC_CTRL_REFSEL_2V5,
vdacRefAvdd = _VDAC_CTRL_REFSEL_VDD,
vdacRefExtPin = _VDAC_CTRL_REFSEL_EXT
}
Reference voltage for VDAC.
enum VDAC_PrsSel_TypeDef {
vdacPrsSelCh0 = _VDAC_CH0CTRL_PRSSEL_PRSCH0,
vdacPrsSelCh1 = _VDAC_CH0CTRL_PRSSEL_PRSCH1,
vdacPrsSelCh2 = _VDAC_CH0CTRL_PRSSEL_PRSCH2,
vdacPrsSelCh3 = _VDAC_CH0CTRL_PRSSEL_PRSCH3,
vdacPrsSelCh4 = _VDAC_CH0CTRL_PRSSEL_PRSCH4,
vdacPrsSelCh5 = _VDAC_CH0CTRL_PRSSEL_PRSCH5,
vdacPrsSelCh6 = _VDAC_CH0CTRL_PRSSEL_PRSCH6,
vdacPrsSelCh7 = _VDAC_CH0CTRL_PRSSEL_PRSCH7,
vdacPrsSelCh8 = _VDAC_CH0CTRL_PRSSEL_PRSCH8,
vdacPrsSelCh9 = _VDAC_CH0CTRL_PRSSEL_PRSCH9,
vdacPrsSelCh10 = _VDAC_CH0CTRL_PRSSEL_PRSCH10,
vdacPrsSelCh11 = _VDAC_CH0CTRL_PRSSEL_PRSCH11
}
Peripheral Reflex System signal used to trigger VDAC channel conversion.
enum VDAC_TrigMode_TypeDef {
vdacTrigModeSw = _VDAC_CH0CTRL_TRIGMODE_SW,
vdacTrigModePrs = _VDAC_CH0CTRL_TRIGMODE_PRS,
vdacTrigModeRefresh = _VDAC_CH0CTRL_TRIGMODE_REFRESH,
vdacTrigModeSwPrs = _VDAC_CH0CTRL_TRIGMODE_SWPRS,
vdacTrigModeSwRefresh = _VDAC_CH0CTRL_TRIGMODE_SWREFRESH,
vdacTrigModeLesense = _VDAC_CH0CTRL_TRIGMODE_LESENSE
}
Channel conversion trigger mode.

Function Documentation

VDAC_ChannelOutputSet()

void VDAC_ChannelOutputSet ( VDAC_TypeDef * vdac,
unsigned int channel,
uint32_t value
)

Set the output signal of a VDAC channel to a given value.

This function sets the output signal of a VDAC channel by writing value to the corresponding CHnDATA register.

Parameters
[in] vdac A pointer to the VDAC peripheral register block.
[in] channel A channel number to set the output of.
[in] value A value to write to the channel output register CHnDATA.

VDAC_Enable()

void VDAC_Enable ( VDAC_TypeDef * vdac,
unsigned int ch,
bool enable
)

Enable/disable the VDAC channel.

Parameters
[in] vdac A pointer to the VDAC peripheral register block.
[in] ch A channel to enable/disable.
[in] enable True to enable VDAC channel, false to disable.

VDAC_Init()

void VDAC_Init ( VDAC_TypeDef * vdac,
const VDAC_Init_TypeDef * init
)

Initialize VDAC.

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 VDAC_InitChannel() .

Note
This function will disable both channels prior to configuration.
Parameters
[in] vdac A pointer to the VDAC peripheral register block.
[in] init A pointer to the VDAC initialization structure.

VDAC_InitChannel()

void VDAC_InitChannel ( VDAC_TypeDef * vdac,
const VDAC_InitChannel_TypeDef * init,
unsigned int ch
)

Initialize a VDAC channel.

Parameters
[in] vdac A pointer to the VDAC peripheral register block.
[in] init A pointer to the VDAC channel initialization structure.
[in] ch A channel number to initialize.

VDAC_Channel0OutputSet()

void VDAC_Channel0OutputSet ( VDAC_TypeDef * vdac,
uint32_t value
)
inline

Set the output signal of VDAC channel 0 to a given value.

This function sets the output signal of VDAC channel 0 by writing value to the CH0DATA register.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
[in] value Value to write to channel 0 output register CH0DATA.

VDAC_Channel1OutputSet()

void VDAC_Channel1OutputSet ( VDAC_TypeDef * vdac,
uint32_t value
)
inline

Set the output signal of VDAC channel 1 to a given value.

This function sets the output signal of VDAC channel 1 by writing value to the CH1DATA register.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
[in] value Value to write to channel 1 output register CH1DATA.

VDAC_IntClear()

void VDAC_IntClear ( VDAC_TypeDef * vdac,
uint32_t flags
)
inline

Clear one or more pending VDAC interrupts.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
[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).

VDAC_IntDisable()

void VDAC_IntDisable ( VDAC_TypeDef * vdac,
uint32_t flags
)
inline

Disable one or more VDAC interrupts.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
[in] flags VDAC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn).

VDAC_IntEnable()

void VDAC_IntEnable ( VDAC_TypeDef * vdac,
uint32_t flags
)
inline

Enable one or more VDAC interrupts.

Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using VDAC_IntClear() prior to enabling the interrupt.
Parameters
[in] vdac Pointer to VDAC peripheral register block.
[in] flags VDAC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn).

VDAC_IntGet()

uint32_t VDAC_IntGet ( VDAC_TypeDef * vdac )
inline

Get pending VDAC interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in] vdac Pointer to 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).

VDAC_IntGetEnabled()

uint32_t VDAC_IntGetEnabled ( VDAC_TypeDef * vdac )
inline

Get enabled and pending VDAC interrupt flags.

Useful for handling more interrupt sources in the same interrupt handler.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
Note
Interrupt flags are not cleared by the use of this function.
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).

VDAC_IntSet()

void VDAC_IntSet ( VDAC_TypeDef * vdac,
uint32_t flags
)
inline

Set one or more pending VDAC interrupts from SW.

Parameters
[in] vdac Pointer to VDAC peripheral register block.
[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).

VDAC_PrescaleCalc()

uint32_t VDAC_PrescaleCalc ( uint32_t vdacFreq,
bool syncMode,
uint32_t hfperFreq
)

Calculate the prescaler value used to determine VDAC clock.

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. The input clock is HFPERCLK/HFPERCCLK when VDAC synchronous mode is selected, or an internal oscillator of 10 MHz +/- 20% when asynchronous mode is selected.

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.
Parameters
[in] vdacFreq VDAC frequency target. The frequency will automatically be adjusted to be below maximum allowed VDAC clock.
[in] syncMode Set to true if you intend to use VDAC in synchronous mode.
[in] hfperFreq Frequency in Hz of HFPERCLK/HFPERCCLK oscillator. Set to 0 to use the currently defined HFPERCLK/HFPERCCLK clock setting. This parameter is only used when syncMode is set to true.
Returns
A prescaler value to use for VDAC to achieve a clock value less than or equal to vdacFreq .

VDAC_Reset()

void VDAC_Reset ( VDAC_TypeDef * vdac )

Reset VDAC to same state that it was in after a hardwares reset.

Parameters
[in] vdac A pointer to the VDAC peripheral register block.

Macro Definition Documentation

VDAC_INIT_DEFAULT

#define VDAC_INIT_DEFAULT
Value:
{ \
true, /* Use main output path calibration values. */ \
false, /* Use synchronous clock mode. */ \
false, /* Turn off between sample off conversions.*/ \
vdacRefresh8, /* Refresh every 8th cycle. */ \
0, /* No prescaling. */ \
vdacRef1V25Ln, /* 1.25 V internal low noise reference. */ \
false, /* Do not reset prescaler on CH 0 start. */ \
false, /* VDAC output enable always on. */ \
false, /* Disable sine mode. */ \
false /* Single ended mode. */ \
}

Default configuration for VDAC initialization structure.

VDAC_INITCHANNEL_DEFAULT

#define VDAC_INITCHANNEL_DEFAULT
Value:
{ \
false, /* Leave channel disabled when initialization is done. */ \
vdacPrsSelCh0, /* PRS CH 0 triggers conversion. */ \
false, /* Treat PRS channel as a synchronous signal. */ \
vdacTrigModeSw, /* Conversion trigged by CH0DATA or COMBDATA write. */ \
false, /* Channel conversion set to continuous. */ \
}

Default configuration for VDAC channel initialization structure.

Enumeration Type Documentation

VDAC_Refresh_TypeDef

Channel refresh period.

Enumerator
vdacRefresh8

Refresh every 8 clock cycles.

vdacRefresh16

Refresh every 16 clock cycles.

vdacRefresh32

Refresh every 32 clock cycles.

vdacRefresh64

Refresh every 64 clock cycles.

VDAC_Ref_TypeDef

Reference voltage for VDAC.

Enumerator
vdacRef1V25Ln

Internal low noise 1.25 V band gap reference.

vdacRef2V5Ln

Internal low noise 2.5 V band gap reference.

vdacRef1V25

Internal 1.25 V band gap reference.

vdacRef2V5

Internal 2.5 V band gap reference.

vdacRefAvdd

AVDD reference.

vdacRefExtPin

External pin reference.

VDAC_PrsSel_TypeDef

Peripheral Reflex System signal used to trigger VDAC channel conversion.

Enumerator
vdacPrsSelCh0

PRS ch 0 triggers conversion.

vdacPrsSelCh1

PRS ch 1 triggers conversion.

vdacPrsSelCh2

PRS ch 2 triggers conversion.

vdacPrsSelCh3

PRS ch 3 triggers conversion.

vdacPrsSelCh4

PRS ch 4 triggers conversion.

vdacPrsSelCh5

PRS ch 5 triggers conversion.

vdacPrsSelCh6

PRS ch 6 triggers conversion.

vdacPrsSelCh7

PRS ch 7 triggers conversion.

vdacPrsSelCh8

PRS ch 8 triggers conversion.

vdacPrsSelCh9

PRS ch 9 triggers conversion.

vdacPrsSelCh10

PRS ch 10 triggers conversion.

vdacPrsSelCh11

PRS ch 11 triggers conversion.

VDAC_TrigMode_TypeDef

Channel conversion trigger mode.

Enumerator
vdacTrigModeSw

Channel is triggered by CHnDATA or COMBDATA write.

vdacTrigModePrs

Channel is triggered by PRS input.

vdacTrigModeRefresh

Channel is triggered by Refresh timer.

vdacTrigModeSwPrs

Channel is triggered by CHnDATA/COMBDATA write or PRS input.

vdacTrigModeSwRefresh

Channel is triggered by CHnDATA/COMBDATA write or Refresh timer.

vdacTrigModeLesense

Channel is triggered by LESENSE.