DAC - Digital to Analog Converter#

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 and can also provide very good performance.

Modules#

DAC_Init_TypeDef

DAC_InitChannel_TypeDef

Enumerations#

enum
dacConvModeContinuous = _DAC_CTRL_CONVMODE_CONTINUOUS
dacConvModeSampleHold = _DAC_CTRL_CONVMODE_SAMPLEHOLD
dacConvModeSampleOff = _DAC_CTRL_CONVMODE_SAMPLEOFF
}

Conversion mode.

enum
dacOutputDisable = _DAC_CTRL_OUTMODE_DISABLE
dacOutputPin = _DAC_CTRL_OUTMODE_PIN
dacOutputADC = _DAC_CTRL_OUTMODE_ADC
dacOutputPinADC = _DAC_CTRL_OUTMODE_PINADC
}

Output mode.

enum
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
}

Peripheral Reflex System signal used to trigger single sample.

enum
dacRef1V25 = _DAC_CTRL_REFSEL_1V25
dacRef2V5 = _DAC_CTRL_REFSEL_2V5
dacRefVDD = _DAC_CTRL_REFSEL_VDD
}

Reference voltage for DAC.

enum
dacRefresh8 = _DAC_CTRL_REFRSEL_8CYCLES
dacRefresh16 = _DAC_CTRL_REFRSEL_16CYCLES
dacRefresh32 = _DAC_CTRL_REFRSEL_32CYCLES
dacRefresh64 = _DAC_CTRL_REFRSEL_64CYCLES
}

Refresh interval.

Functions#

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

Enable/disable the DAC channel.

void
DAC_Init(DAC_TypeDef *dac, const DAC_Init_TypeDef *init)

Initialize DAC.

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

Initialize DAC channel.

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

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

uint8_t
DAC_PrescaleCalc(uint32_t dacFreq, uint32_t hfperFreq)

Calculate prescaler value used to determine the DAC clock.

void
DAC_Reset(DAC_TypeDef *dac)

Reset DAC to the same state that it was in after a hardware reset.

void
DAC_Channel0OutputSet(DAC_TypeDef *dac, uint32_t value)

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

void
DAC_Channel1OutputSet(DAC_TypeDef *dac, uint32_t value)

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

void
DAC_IntClear(DAC_TypeDef *dac, uint32_t flags)

Clear one or more pending DAC interrupts.

void
DAC_IntDisable(DAC_TypeDef *dac, uint32_t flags)

Disable one or more DAC interrupts.

void
DAC_IntEnable(DAC_TypeDef *dac, uint32_t flags)

Enable one or more DAC interrupts.

uint32_t
DAC_IntGet(DAC_TypeDef *dac)

Get pending DAC interrupt flags.

uint32_t
DAC_IntGetEnabled(DAC_TypeDef *dac)

Get enabled and pending DAC interrupt flags.

void
DAC_IntSet(DAC_TypeDef *dac, uint32_t flags)

Set one or more pending DAC interrupts from SW.

Macros#

#define
DAC_INIT_DEFAULT undefined

Default configuration for DAC initialization structure.

#define
DAC_INITCHANNEL_DEFAULT undefined

Default configuration for DAC channel initialization structure.

Enumeration Documentation#

DAC_ConvMode_TypeDef#

DAC_ConvMode_TypeDef

Conversion mode.

Enumerator
dacConvModeContinuous

Continuous mode.

dacConvModeSampleHold

Sample/hold mode.

dacConvModeSampleOff

Sample/shut off mode.


DAC_Output_TypeDef#

DAC_Output_TypeDef

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.


DAC_PRSSEL_TypeDef#

DAC_PRSSEL_TypeDef

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.


DAC_Ref_TypeDef#

DAC_Ref_TypeDef

Reference voltage for DAC.

Enumerator
dacRef1V25

Internal 1.25V bandgap reference.

dacRef2V5

Internal 2.5V bandgap reference.

dacRefVDD

VDD reference.


DAC_Refresh_TypeDef#

DAC_Refresh_TypeDef

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.


Function Documentation#

DAC_Enable#

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

Enable/disable the DAC channel.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

A pointer to the DAC peripheral register block.

unsigned int[in]ch

A channel to enable/disable.

bool[in]enable

true to enable DAC channel, false to disable.


DAC_Init#

void DAC_Init (DAC_TypeDef * dac, const DAC_Init_TypeDef * init)

Initialize DAC.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

A pointer to the DAC peripheral register block.

const DAC_Init_TypeDef *[in]init

A pointer to the DAC initialization structure.

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

Note

  • This function will disable both channels prior to configuration.


DAC_InitChannel#

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

Initialize DAC channel.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

A pointer to the DAC peripheral register block.

const DAC_InitChannel_TypeDef *[in]init

A pointer to the DAC initialization structure.

unsigned int[in]ch

A channel number to initialize.


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.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

A pointer to the DAC peripheral register block.

unsigned int[in]channel

A channel number to set the output.

uint32_t[in]value

A value to write to the channel output register CHnDATA.

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


DAC_PrescaleCalc#

uint8_t DAC_PrescaleCalc (uint32_t dacFreq, uint32_t hfperFreq)

Calculate prescaler value used to determine the DAC clock.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]dacFreq

DAC frequency wanted. The frequency will automatically be adjusted to be below the maximum allowed DAC clock.

uint32_t[in]hfperFreq

Frequency in Hz of the reference HFPER clock. Set to 0 to use the currently defined HFPER clock setting.

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

Returns

  • Prescaler value to use for DAC to achieve a clock value <= dacFreq.


DAC_Reset#

void DAC_Reset (DAC_TypeDef * dac)

Reset DAC to the same state that it was in after a hardware reset.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

A pointer to the ADC peripheral register block.


DAC_Channel0OutputSet#

void DAC_Channel0OutputSet (DAC_TypeDef * dac, uint32_t value)

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

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]value

Value to write to the channel 0 output register CH0DATA.

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


DAC_Channel1OutputSet#

void DAC_Channel1OutputSet (DAC_TypeDef * dac, uint32_t value)

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

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]value

Value to write to the channel 1 output register CH1DATA.

Sets the output signal of DAC channel 1 by writing value to the CH1DATA register.


DAC_IntClear#

void DAC_IntClear (DAC_TypeDef * dac, uint32_t flags)

Clear one or more pending DAC interrupts.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]flags

Pending DAC interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).


DAC_IntDisable#

void DAC_IntDisable (DAC_TypeDef * dac, uint32_t flags)

Disable one or more DAC interrupts.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]flags

DAC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).


DAC_IntEnable#

void DAC_IntEnable (DAC_TypeDef * dac, uint32_t flags)

Enable one or more DAC interrupts.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]flags

DAC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_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 DAC_IntClear() prior to enabling the interrupt.


DAC_IntGet#

uint32_t DAC_IntGet (DAC_TypeDef * dac)

Get pending DAC interrupt flags.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

Note

  • Event bits are not cleared by the use of this function.

Returns

  • DAC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).


DAC_IntGetEnabled#

uint32_t DAC_IntGetEnabled (DAC_TypeDef * dac)

Get enabled and pending DAC interrupt flags.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

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

Note

  • Interrupt flags are not cleared by the use of this function.

Returns

  • Pending and enabled DAC interrupt sources. 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).


DAC_IntSet#

void DAC_IntSet (DAC_TypeDef * dac, uint32_t flags)

Set one or more pending DAC interrupts from SW.

Parameters
TypeDirectionArgument NameDescription
DAC_TypeDef *[in]dac

Pointer to DAC peripheral register block.

uint32_t[in]flags

DAC interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the DAC module (DAC_IF_nnn).