EFM32 Gecko Software Documentation  efm32g-doc-5.1.2

Detailed Description

Digital to Analog Converter (DAC) Peripheral API.

This module contains functions to control the DAC peripheral of Silicon Labs 32-bit MCUs and SoCs. The DAC converts digital values to analog signals at up to 500 ksps with 12-bit accuracy. The DAC is designed for low energy consumption, but can also provide very good performance.

Data Structures

struct  DAC_Init_TypeDef
 
struct  DAC_InitChannel_TypeDef
 

Macros

#define DAC_INIT_DEFAULT
 
#define DAC_INITCHANNEL_DEFAULT
 

Enumerations

enum  DAC_ConvMode_TypeDef {
  dacConvModeContinuous = _DAC_CTRL_CONVMODE_CONTINUOUS,
  dacConvModeSampleHold = _DAC_CTRL_CONVMODE_SAMPLEHOLD,
  dacConvModeSampleOff = _DAC_CTRL_CONVMODE_SAMPLEOFF
}
 
enum  DAC_Output_TypeDef {
  dacOutputDisable = _DAC_CTRL_OUTMODE_DISABLE,
  dacOutputPin = _DAC_CTRL_OUTMODE_PIN,
  dacOutputADC = _DAC_CTRL_OUTMODE_ADC,
  dacOutputPinADC = _DAC_CTRL_OUTMODE_PINADC
}
 
enum  DAC_PRSSEL_TypeDef {
  dacPRSSELCh0 = _DAC_CH0CTRL_PRSSEL_PRSCH0,
  dacPRSSELCh1 = _DAC_CH0CTRL_PRSSEL_PRSCH1,
  dacPRSSELCh2 = _DAC_CH0CTRL_PRSSEL_PRSCH2,
  dacPRSSELCh3 = _DAC_CH0CTRL_PRSSEL_PRSCH3,
  dacPRSSELCh4 = _DAC_CH0CTRL_PRSSEL_PRSCH4,
  dacPRSSELCh5 = _DAC_CH0CTRL_PRSSEL_PRSCH5,
  dacPRSSELCh6 = _DAC_CH0CTRL_PRSSEL_PRSCH6,
  dacPRSSELCh7 = _DAC_CH0CTRL_PRSSEL_PRSCH7
}
 
enum  DAC_Ref_TypeDef {
  dacRef1V25 = _DAC_CTRL_REFSEL_1V25,
  dacRef2V5 = _DAC_CTRL_REFSEL_2V5,
  dacRefVDD = _DAC_CTRL_REFSEL_VDD
}
 
enum  DAC_Refresh_TypeDef {
  dacRefresh8 = _DAC_CTRL_REFRSEL_8CYCLES,
  dacRefresh16 = _DAC_CTRL_REFRSEL_16CYCLES,
  dacRefresh32 = _DAC_CTRL_REFRSEL_32CYCLES,
  dacRefresh64 = _DAC_CTRL_REFRSEL_64CYCLES
}
 

Functions

__STATIC_INLINE void DAC_Channel0OutputSet (DAC_TypeDef *dac, uint32_t value)
 Set the output signal of DAC channel 0 to a given value. More...
 
__STATIC_INLINE void DAC_Channel1OutputSet (DAC_TypeDef *dac, uint32_t value)
 Set the output signal of DAC channel 1 to a given value. More...
 
void DAC_ChannelOutputSet (DAC_TypeDef *dac, unsigned int channel, uint32_t value)
 Set the output signal of a DAC channel to a given value. More...
 
void DAC_Enable (DAC_TypeDef *dac, unsigned int ch, bool enable)
 Enable/disable DAC channel. More...
 
void DAC_Init (DAC_TypeDef *dac, const DAC_Init_TypeDef *init)
 Initialize DAC. More...
 
void DAC_InitChannel (DAC_TypeDef *dac, const DAC_InitChannel_TypeDef *init, unsigned int ch)
 Initialize DAC channel. More...
 
__STATIC_INLINE void DAC_IntClear (DAC_TypeDef *dac, uint32_t flags)
 Clear one or more pending DAC interrupts. More...
 
__STATIC_INLINE void DAC_IntDisable (DAC_TypeDef *dac, uint32_t flags)
 Disable one or more DAC interrupts. More...
 
__STATIC_INLINE void DAC_IntEnable (DAC_TypeDef *dac, uint32_t flags)
 Enable one or more DAC interrupts. More...
 
__STATIC_INLINE uint32_t DAC_IntGet (DAC_TypeDef *dac)
 Get pending DAC interrupt flags. More...
 
__STATIC_INLINE uint32_t DAC_IntGetEnabled (DAC_TypeDef *dac)
 Get enabled and pending DAC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler. More...
 
__STATIC_INLINE void DAC_IntSet (DAC_TypeDef *dac, uint32_t flags)
 Set one or more pending DAC interrupts from SW. More...
 
uint8_t DAC_PrescaleCalc (uint32_t dacFreq, uint32_t hfperFreq)
 Calculate prescaler value used to determine DAC clock. More...
 
void DAC_Reset (DAC_TypeDef *dac)
 Reset DAC to same state as after a HW reset. More...
 

Macro Definition Documentation

#define DAC_INIT_DEFAULT
Value:
{ \
dacRefresh8, /* Refresh every 8 prescaled cycles. */ \
dacRef1V25, /* 1.25V internal reference. */ \
dacOutputPin, /* Output to pin only. */ \
dacConvModeContinuous, /* Continuous mode. */ \
0, /* No prescaling. */ \
false, /* Do not enable low pass filter. */ \
false, /* Do not reset prescaler on ch0 start. */ \
false, /* DAC output enable always on. */ \
false, /* Disable sine mode. */ \
false /* Single ended mode. */ \
}

Default config for DAC init structure.

Definition at line 182 of file em_dac.h.

#define DAC_INITCHANNEL_DEFAULT
Value:
{ \
false, /* Leave channel disabled when init done. */ \
false, /* Disable PRS triggering. */ \
false, /* Channel not refreshed automatically. */ \
dacPRSSELCh0 /* Select PRS ch0 (if PRS triggering enabled). */ \
}

Default config for DAC channel init structure.

Definition at line 223 of file em_dac.h.

Enumeration Type Documentation

Conversion mode.

Enumerator
dacConvModeContinuous 

Continuous mode.

dacConvModeSampleHold 

Sample/hold mode.

dacConvModeSampleOff 

Sample/shut off mode.

Definition at line 70 of file em_dac.h.

Output mode.

Enumerator
dacOutputDisable 

Output to pin and ADC disabled.

dacOutputPin 

Output to pin only.

dacOutputADC 

Output to ADC only

dacOutputPinADC 

Output to pin and ADC.

Definition at line 78 of file em_dac.h.

Peripheral Reflex System signal used to trigger single sample.

Enumerator
dacPRSSELCh0 

PRS channel 0.

dacPRSSELCh1 

PRS channel 1.

dacPRSSELCh2 

PRS channel 2.

dacPRSSELCh3 

PRS channel 3.

dacPRSSELCh4 

PRS channel 4.

dacPRSSELCh5 

PRS channel 5.

dacPRSSELCh6 

PRS channel 6.

dacPRSSELCh7 

PRS channel 7.

Definition at line 88 of file em_dac.h.

Reference voltage for DAC.

Enumerator
dacRef1V25 

Internal 1.25V bandgap reference.

dacRef2V5 

Internal 2.5V bandgap reference.

dacRefVDD 

VDD reference.

Definition at line 122 of file em_dac.h.

Refresh interval.

Enumerator
dacRefresh8 

Refresh every 8 prescaled cycles.

dacRefresh16 

Refresh every 16 prescaled cycles.

dacRefresh32 

Refresh every 32 prescaled cycles.

dacRefresh64 

Refresh every 64 prescaled cycles.

Definition at line 131 of file em_dac.h.

Function Documentation

__STATIC_INLINE void DAC_Channel0OutputSet ( DAC_TypeDef dac,
uint32_t  value 
)

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

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

Parameters
[in]dacPointer to DAC peripheral register block.
[in]valueValue to write to the channel 0 output register CH0DATA.

Definition at line 259 of file em_dac.h.

References _DAC_CH0DATA_MASK, and DAC_TypeDef::CH0DATA.

Referenced by DAC_ChannelOutputSet().

__STATIC_INLINE void DAC_Channel1OutputSet ( DAC_TypeDef dac,
uint32_t  value 
)

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

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

Parameters
[in]dacPointer to DAC peripheral register block.
[in]valueValue to write to the channel 1 output register CH1DATA.

Definition at line 281 of file em_dac.h.

References _DAC_CH1DATA_MASK, and DAC_TypeDef::CH1DATA.

Referenced by DAC_ChannelOutputSet().

void DAC_ChannelOutputSet ( DAC_TypeDef dac,
unsigned int  channel,
uint32_t  value 
)

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

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

Parameters
[in]dacPointer to DAC peripheral register block.
[in]channelChannel number to set output of.
[in]valueValue to write to the channel output register CHnDATA.

Definition at line 247 of file em_dac.c.

References DAC_Channel0OutputSet(), and DAC_Channel1OutputSet().

void DAC_Enable ( DAC_TypeDef dac,
unsigned int  ch,
bool  enable 
)

Enable/disable DAC channel.

Parameters
[in]dacPointer to DAC peripheral register block.
[in]chChannel to enable/disable.
[in]enabletrue to enable DAC channel, false to disable.

Definition at line 86 of file em_dac.c.

References _DAC_CH0CTRL_EN_SHIFT, BUS_RegBitWrite(), DAC_TypeDef::CH0CTRL, and DAC_TypeDef::CH1CTRL.

void DAC_Init ( DAC_TypeDef dac,
const DAC_Init_TypeDef init 
)

Initialize DAC.

Initializes common parts for both channels. In addition, channel control configuration must be done, please refer to DAC_InitChannel().

Note
This function will disable both channels prior to configuration.
Parameters
[in]dacPointer to DAC peripheral register block.
[in]initPointer to DAC initialization structure.

Definition at line 123 of file em_dac.c.

References _DAC_CH0CTRL_EN_SHIFT, _DAC_CTRL_CONVMODE_SHIFT, _DAC_CTRL_OUTMODE_SHIFT, _DAC_CTRL_PRESC_MASK, _DAC_CTRL_PRESC_SHIFT, _DAC_CTRL_REFRSEL_SHIFT, _DAC_CTRL_REFSEL_SHIFT, BUS_RegBitWrite(), DAC_TypeDef::CAL, DAC_TypeDef::CH0CTRL, DAC_Init_TypeDef::ch0ResetPre, DAC_TypeDef::CH1CTRL, DAC_Init_TypeDef::convMode, DAC_TypeDef::CTRL, DAC_CTRL_CH0PRESCRST, DAC_CTRL_DIFF, DAC_CTRL_OUTENPRS, DAC_CTRL_SINEMODE, dacRef2V5, dacRefVDD, DEVINFO, DAC_Init_TypeDef::diff, DAC_Init_TypeDef::outEnablePRS, DAC_Init_TypeDef::outMode, DAC_Init_TypeDef::prescale, DAC_Init_TypeDef::reference, DAC_Init_TypeDef::refresh, and DAC_Init_TypeDef::sineEnable.

void DAC_InitChannel ( DAC_TypeDef dac,
const DAC_InitChannel_TypeDef init,
unsigned int  ch 
)

Initialize DAC channel.

Parameters
[in]dacPointer to DAC peripheral register block.
[in]initPointer to DAC initialization structure.
[in]chChannel number to initialize.

Definition at line 193 of file em_dac.c.

References _DAC_CH0CTRL_PRSSEL_SHIFT, DAC_TypeDef::CH0CTRL, DAC_TypeDef::CH1CTRL, DAC_CH0CTRL_EN, DAC_CH0CTRL_PRSEN, DAC_CH0CTRL_REFREN, DAC_InitChannel_TypeDef::enable, DAC_InitChannel_TypeDef::prsEnable, DAC_InitChannel_TypeDef::prsSel, and DAC_InitChannel_TypeDef::refreshEnable.

__STATIC_INLINE void DAC_IntClear ( DAC_TypeDef dac,
uint32_t  flags 
)

Clear one or more pending DAC interrupts.

Parameters
[in]dacPointer to DAC peripheral register block.
[in]flagsPending DAC interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).

Definition at line 300 of file em_dac.h.

References DAC_TypeDef::IFC.

__STATIC_INLINE void DAC_IntDisable ( DAC_TypeDef dac,
uint32_t  flags 
)

Disable one or more DAC interrupts.

Parameters
[in]dacPointer to DAC peripheral register block.
[in]flagsDAC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).

Definition at line 317 of file em_dac.h.

References DAC_TypeDef::IEN.

__STATIC_INLINE void DAC_IntEnable ( DAC_TypeDef dac,
uint32_t  flags 
)

Enable one or more DAC interrupts.

Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using DAC_IntClear() prior to enabling if such a pending interrupt should be ignored.
Parameters
[in]dacPointer to DAC peripheral register block.
[in]flagsDAC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).

Definition at line 339 of file em_dac.h.

References DAC_TypeDef::IEN.

__STATIC_INLINE uint32_t DAC_IntGet ( DAC_TypeDef dac)

Get pending DAC interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in]dacPointer to DAC peripheral register block.
Returns
DAC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).

Definition at line 359 of file em_dac.h.

References DAC_TypeDef::IF.

__STATIC_INLINE uint32_t DAC_IntGetEnabled ( DAC_TypeDef dac)

Get enabled and pending DAC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.

Parameters
[in]dacPointer to DAC peripheral register block.
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled DAC interrupt sources. The return value is the bitwise AND combination of
  • the OR combination of enabled interrupt sources in DACx_IEN_nnn register (DACx_IEN_nnn) and
  • the OR combination of valid interrupt flags of the DAC module (DACx_IF_nnn).

Definition at line 384 of file em_dac.h.

References DAC_TypeDef::IEN, and DAC_TypeDef::IF.

__STATIC_INLINE void DAC_IntSet ( DAC_TypeDef dac,
uint32_t  flags 
)

Set one or more pending DAC interrupts from SW.

Parameters
[in]dacPointer to DAC peripheral register block.
[in]flagsDAC interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).

Definition at line 408 of file em_dac.h.

References DAC_TypeDef::IFS.

uint8_t DAC_PrescaleCalc ( uint32_t  dacFreq,
uint32_t  hfperFreq 
)

Calculate prescaler value used to determine DAC clock.

The DAC clock is given by: HFPERCLK / (prescale ^ 2). If the requested DAC frequency is low and the max prescaler value can not adjust the actual DAC frequency lower than the requested DAC frequency, then the max prescaler value is returned, resulting in a higher DAC frequency than requested.

Parameters
[in]dacFreqDAC frequency wanted. The frequency will automatically be adjusted to be below max allowed DAC clock.
[in]hfperFreqFrequency in Hz of reference HFPER clock. Set to 0 to use currently defined HFPER clock setting.
Returns
Prescaler value to use for DAC in order to achieve a clock value <= dacFreq.

Definition at line 287 of file em_dac.c.

References _DAC_CTRL_PRESC_MASK, _DAC_CTRL_PRESC_SHIFT, CMU_ClockFreqGet(), and cmuClock_HFPER.

void DAC_Reset ( DAC_TypeDef dac)

Reset DAC to same state as after a HW reset.

Parameters
[in]dacPointer to ADC peripheral register block.

Definition at line 330 of file em_dac.c.

References _DAC_BIASPROG_RESETVALUE, _DAC_CH0CTRL_RESETVALUE, _DAC_CH1CTRL_RESETVALUE, _DAC_CTRL_RESETVALUE, _DAC_IEN_RESETVALUE, _DAC_IFC_MASK, DAC_TypeDef::BIASPROG, DAC_TypeDef::CAL, DAC_TypeDef::CH0CTRL, DAC_TypeDef::CH1CTRL, DAC_TypeDef::CTRL, DEVINFO, DAC_TypeDef::IEN, and DAC_TypeDef::IFC.