VDACEMLIB
Detailed 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. The VDAC converts digital values to analog signals at up to 500 ksps with 12-bit accuracy. The 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:
Perform a conversion:
- Note
- The output stage of a VDAC channel consist of an onchip operational amplifier in the OPAMP module. This opamp is highly configurable and to exploit the VDAC functionality fully, you might need to configure the opamp using the OPAMP API. By using the OPAMP API you will also load opamp calibration values. The default (reset) settings of the opamp will be sufficient for many applications.
Data Structures |
|
struct | VDAC_Init_TypeDef |
struct | VDAC_InitChannel_TypeDef |
Macros |
|
#define | VDAC_INIT_DEFAULT |
#define | VDAC_INITCHANNEL_DEFAULT |
Enumerations |
|
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 } |
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 } |
enum |
VDAC_Refresh_TypeDef
{
vdacRefresh8 = _VDAC_CTRL_REFRESHPERIOD_8CYCLES, vdacRefresh16 = _VDAC_CTRL_REFRESHPERIOD_16CYCLES, vdacRefresh32 = _VDAC_CTRL_REFRESHPERIOD_32CYCLES, vdacRefresh64 = _VDAC_CTRL_REFRESHPERIOD_64CYCLES } |
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 } |
Functions |
|
__STATIC_INLINE void | VDAC_Channel0OutputSet ( VDAC_TypeDef *vdac, uint32_t value) |
Set the output signal of VDAC channel 0 to a given value.
|
|
__STATIC_INLINE void | VDAC_Channel1OutputSet ( VDAC_TypeDef *vdac, uint32_t value) |
Set the output signal of VDAC channel 1 to a given value.
|
|
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 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.
|
|
__STATIC_INLINE void | VDAC_IntClear ( VDAC_TypeDef *vdac, uint32_t flags) |
Clear one or more pending VDAC interrupts.
|
|
__STATIC_INLINE void | VDAC_IntDisable ( VDAC_TypeDef *vdac, uint32_t flags) |
Disable one or more VDAC interrupts.
|
|
__STATIC_INLINE void | VDAC_IntEnable ( VDAC_TypeDef *vdac, uint32_t flags) |
Enable one or more VDAC interrupts.
|
|
__STATIC_INLINE uint32_t | VDAC_IntGet ( VDAC_TypeDef *vdac) |
Get pending VDAC interrupt flags.
|
|
__STATIC_INLINE uint32_t | VDAC_IntGetEnabled ( VDAC_TypeDef *vdac) |
Get enabled and pending VDAC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
|
|
__STATIC_INLINE 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 prescaler value used to determine VDAC clock.
|
|
void | VDAC_Reset ( VDAC_TypeDef *vdac) |
Reset VDAC to same state as after a HW reset.
|
|
Macro Definition Documentation
#define VDAC_INIT_DEFAULT |
Default config for VDAC init structure.
Definition at line
195
of file
em_vdac.h
.
#define VDAC_INITCHANNEL_DEFAULT |
Default config for VDAC channel init structure.
Definition at line
231
of file
em_vdac.h
.
Enumeration Type Documentation
enum VDAC_PrsSel_TypeDef |
Peripheral Reflex System signal used to trig VDAC channel conversion.
Definition at line
123
of file
em_vdac.h
.
enum VDAC_Ref_TypeDef |
Reference voltage for VDAC.
Definition at line
113
of file
em_vdac.h
.
enum VDAC_Refresh_TypeDef |
Channel conversion trigger mode.
Definition at line
147
of file
em_vdac.h
.
Function Documentation
__STATIC_INLINE void VDAC_Channel0OutputSet | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
value
|
||
) |
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.
Definition at line
267
of file
em_vdac.h
.
References _VDAC_CH0DATA_MASK , and VDAC_TypeDef::CH0DATA .
Referenced by VDAC_ChannelOutputSet() .
__STATIC_INLINE void VDAC_Channel1OutputSet | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
value
|
||
) |
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.
Definition at line
288
of file
em_vdac.h
.
References _VDAC_CH1DATA_MASK , and VDAC_TypeDef::CH1DATA .
Referenced by 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
Pointer to VDAC peripheral register block. [in] channel
Channel number to set output of. [in] value
Value to write to the channel output register CHnDATA.
Definition at line
290
of file
em_vdac.c
.
References VDAC_Channel0OutputSet() , and VDAC_Channel1OutputSet() .
void VDAC_Enable | ( | VDAC_TypeDef * |
vdac,
|
unsigned int |
ch,
|
||
bool |
enable
|
||
) |
Enable/disable VDAC channel.
- Parameters
-
[in] vdac
Pointer to VDAC peripheral register block. [in] ch
Channel to enable/disable. [in] enable
true to enable VDAC channel, false to disable.
Definition at line
81
of file
em_vdac.c
.
References VDAC_TypeDef::CMD , VDAC_TypeDef::STATUS , VDAC_CMD_CH0DIS , VDAC_CMD_CH0EN , VDAC_CMD_CH1DIS , VDAC_CMD_CH1EN , VDAC_STATUS_CH0ENS , and VDAC_STATUS_CH1ENS .
void VDAC_Init | ( | VDAC_TypeDef * |
vdac,
|
const VDAC_Init_TypeDef * |
init
|
||
) |
Initialize VDAC.
Initializes 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, please refer to VDAC_InitChannel() .
- Note
- This function will disable both channels prior to configuration.
- Parameters
-
[in] vdac
Pointer to VDAC peripheral register block. [in] init
Pointer to VDAC initialization structure.
Definition at line
123
of file
em_vdac.c
.
References _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_MASK , _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_SHIFT , _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_MASK , _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_SHIFT , _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_MASK , _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_SHIFT , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_MASK , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_SHIFT , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_MASK , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_SHIFT , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_MASK , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_SHIFT , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_MASK , _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_SHIFT , _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_MASK , _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_SHIFT , _VDAC_CAL_GAINERRTRIM_SHIFT , _VDAC_CAL_GAINERRTRIMCH1_SHIFT , _VDAC_CAL_OFFSETTRIM_SHIFT , _VDAC_CTRL_CH0PRESCRST_SHIFT , _VDAC_CTRL_DACCLKMODE_SHIFT , _VDAC_CTRL_DIFF_SHIFT , _VDAC_CTRL_OUTENPRS_SHIFT , _VDAC_CTRL_PRESC_MASK , _VDAC_CTRL_PRESC_SHIFT , _VDAC_CTRL_REFRESHPERIOD_SHIFT , _VDAC_CTRL_REFSEL_SHIFT , _VDAC_CTRL_SINEMODE_SHIFT , _VDAC_CTRL_WARMUPMODE_SHIFT , VDAC_Init_TypeDef::asyncClockMode , VDAC_TypeDef::CAL , VDAC_Init_TypeDef::ch0ResetPre , VDAC_TypeDef::CMD , VDAC_TypeDef::CTRL , DEVINFO , VDAC_Init_TypeDef::diff , VDAC_Init_TypeDef::mainCalibration , VDAC_Init_TypeDef::outEnablePRS , VDAC_Init_TypeDef::prescaler , VDAC_Init_TypeDef::reference , VDAC_Init_TypeDef::refresh , VDAC_Init_TypeDef::sineEnable , VDAC_TypeDef::STATUS , VDAC_CMD_CH0DIS , VDAC_CMD_CH1DIS , VDAC_STATUS_CH0ENS , VDAC_STATUS_CH1ENS , vdacRef1V25 , vdacRef1V25Ln , vdacRef2V5 , vdacRef2V5Ln , vdacRefAvdd , vdacRefExtPin , and VDAC_Init_TypeDef::warmupKeepOn .
void VDAC_InitChannel | ( | VDAC_TypeDef * |
vdac,
|
const VDAC_InitChannel_TypeDef * |
init,
|
||
unsigned int |
ch
|
||
) |
Initialize a VDAC channel.
- Parameters
-
[in] vdac
Pointer to VDAC peripheral register block. [in] init
Pointer to VDAC channel initialization structure. [in] ch
Channel number to initialize.
Definition at line
226
of file
em_vdac.c
.
References _VDAC_CH0CTRL_CONVMODE_SHIFT , _VDAC_CH0CTRL_PRSASYNC_SHIFT , _VDAC_CH0CTRL_PRSSEL_SHIFT , _VDAC_CH0CTRL_TRIGMODE_SHIFT , VDAC_TypeDef::CH0CTRL , VDAC_TypeDef::CH1CTRL , VDAC_TypeDef::CMD , VDAC_InitChannel_TypeDef::enable , VDAC_InitChannel_TypeDef::prsAsync , VDAC_InitChannel_TypeDef::prsSel , VDAC_InitChannel_TypeDef::sampleOffMode , VDAC_TypeDef::STATUS , VDAC_InitChannel_TypeDef::trigMode , VDAC_CMD_CH0DIS , VDAC_CMD_CH0EN , VDAC_CMD_CH1DIS , VDAC_CMD_CH1EN , VDAC_STATUS_CH0ENS , and VDAC_STATUS_CH1ENS .
__STATIC_INLINE void VDAC_IntClear | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
flags
|
||
) |
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).
Definition at line
306
of file
em_vdac.h
.
References VDAC_TypeDef::IFC .
__STATIC_INLINE void VDAC_IntDisable | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
flags
|
||
) |
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).
Definition at line
322
of file
em_vdac.h
.
References VDAC_TypeDef::IEN .
__STATIC_INLINE void VDAC_IntEnable | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
flags
|
||
) |
Enable one or more VDAC interrupts.
- Note
- Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using VDAC_IntClear() prior to enabling if such a pending interrupt should be ignored.
- 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).
Definition at line
343
of file
em_vdac.h
.
References VDAC_TypeDef::IEN .
__STATIC_INLINE uint32_t VDAC_IntGet | ( | VDAC_TypeDef * |
vdac
|
) |
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. A bitwise logic OR combination of valid interrupt flags for the VDAC module (VDAC_IF_nnn).
Definition at line
362
of file
em_vdac.h
.
References VDAC_TypeDef::IF .
__STATIC_INLINE uint32_t VDAC_IntGetEnabled | ( | VDAC_TypeDef * |
vdac
|
) |
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).
Definition at line
386
of file
em_vdac.h
.
References VDAC_TypeDef::IEN , and VDAC_TypeDef::IF .
__STATIC_INLINE void VDAC_IntSet | ( | VDAC_TypeDef * |
vdac,
|
uint32_t |
flags
|
||
) |
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).
Definition at line
405
of file
em_vdac.h
.
References VDAC_TypeDef::IFS .
uint32_t VDAC_PrescaleCalc | ( | uint32_t |
vdacFreq,
|
bool |
syncMode,
|
||
uint32_t |
hfperFreq
|
||
) |
Calculate prescaler value used to determine VDAC clock.
The VDAC clock is given by input clock divided by prescaler+1.
VDAC_CLK = IN_CLK / (prescale + 1)
Maximum VDAC clock is 1 MHz. Input clock is HFPERCLK 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 max prescaler value can not adjust the actual VDAC frequency lower than requested, the max 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 max allowed VDAC clock. [in] syncMode
Set to true if you intend to use VDAC in synchronous mode. [in] hfperFreq
Frequency in Hz of HFPERCLK oscillator. Set to 0 to use currently defined HFPERCLK clock setting. This parameter is only used when syncMode is set to true.
- Returns
-
Prescaler value to use for VDAC in order to achieve a clock value less than or equal to
vdacFreq
.
Definition at line
339
of file
em_vdac.c
.
References _VDAC_CTRL_PRESC_MASK , _VDAC_CTRL_PRESC_SHIFT , CMU_ClockFreqGet() , and cmuClock_HFPER .
void VDAC_Reset | ( | VDAC_TypeDef * |
vdac
|
) |
Reset VDAC to same state as after a HW reset.
- Parameters
-
[in] vdac
Pointer to VDAC peripheral register block.
Definition at line
383
of file
em_vdac.c
.
References _VDAC_CAL_RESETVALUE , _VDAC_CH0CTRL_RESETVALUE , _VDAC_CH0DATA_RESETVALUE , _VDAC_CH1CTRL_RESETVALUE , _VDAC_CH1DATA_RESETVALUE , _VDAC_CTRL_RESETVALUE , _VDAC_IEN_RESETVALUE , _VDAC_IFC_MASK , VDAC_TypeDef::CAL , VDAC_TypeDef::CH0CTRL , VDAC_TypeDef::CH0DATA , VDAC_TypeDef::CH1CTRL , VDAC_TypeDef::CH1DATA , VDAC_TypeDef::CMD , VDAC_TypeDef::CTRL , VDAC_TypeDef::IEN , VDAC_TypeDef::IFC , VDAC_TypeDef::STATUS , VDAC_CMD_CH0DIS , VDAC_CMD_CH1DIS , VDAC_STATUS_CH0ENS , and VDAC_STATUS_CH1ENS .