14. Digital-to-analog converter (DAC)

14.1 Introduction

The STM32WL33xx embeds a DAC module. The DAC is not available on STM32WL30xx and STM32WL31xx devices.

The DAC module is a 6-bit, voltage output digital-to-analog converter. The DAC may be used in conjunction with the DMA controller. The DAC has three output channels:

14.2 DAC main features

14.3 DAC block diagram

Figure 28 shows the block diagram of the DAC.

Figure 28. DAC block diagram

Block diagram of the DAC showing the DAC Controller and the DAC block.

The diagram illustrates the internal architecture of the DAC. The DAC Controller (enclosed in a red box) contains the CR (Control Register), TRIGGER SELECTOR, DHR (Data Holding Register), CONTROL LOGIC (containing LFSR and triangle generators), and DOR (Data Output Register). The TRIGGER SELECTOR receives inputs from the Advanced Peripheral Bus (PA8) via SWTRIG and TIM16 TRGO, and is controlled by TSEL (2:0) from the CR. The DHR provides a 6-bit value to the CONTROL LOGIC via WAVEN x(1:0). The CONTROL LOGIC also receives MAMP (3:0) from the CR and TEN from the DOR. It outputs dma_ack_dac and dma_req_dac signals. The DOR receives a 6-bit value from the CONTROL LOGIC and provides VCMON to the DAC block. The DAC block includes pins for VDDA, GNDA, DACIN[5:0], DAC_PWDN, EN, BON, VCMEN, CMPEN, DACOUT, DAC_ENDACOUTBUFF, DACOUT_HVBATT, DAC_ENDACOUT_VCMBUFF, and DAC_ENDACOUT. It also features a VCMBUF connected to PA13 and PB4, and a DACOUT_GPIO output. The DACOUT_COMPMINUS output is also shown.

Block diagram of the DAC showing the DAC Controller and the DAC block.

14.4 DAC functional description

14.4.1 DAC channel enable

DAC channel can be powered on by setting its corresponding EN bit in the DAC_CR register. The DAC channel is then enabled after a startup time \(t_{\text{WAKEUP}}\).

Note: The EN bit enables the analog DAC Channel macrocell only. The DAC Channel digital interface is enabled even if the EN bit is reset.

14.4.2 DAC outputs enable

The DAC integrates one output buffer that can be used to reduce the output impedance, and to drive external loads directly without having to add an external operational amplifier. DAC channel output buffer can be enabled and disabled using the corresponding BON bit in the DAC_CR register.

DAC has other two output channels connected internally respectively to VCMBUFF (which can be switched on by VCMON bit) and to COMPINMINUS that can be enabled using corresponding bits VCMEN and CMPEN.

14.4.3 DAC conversion

The DAC_DOR cannot be written directly and any data transfer to the DAC channel must be performed by loading the DAC_DHR register.

Data stored in the DAC_DHR register are automatically transferred to the DAC_DOR register after one APB0 clock cycle, if no hardware trigger is selected (TEN bit in DAC_CR register is reset). However, when a hardware trigger is selected (TEN bit in DAC_CR register is set) and a trigger occurs, the transfer is performed three APB0 clock cycles later.

When DAC_DOR is loaded with the DAC_DHR contents, the analog output voltage becomes available after a time \(t_{\text{SETTLING}}\) that depends on the power supply voltage and the analog output load.

14.4.4 DAC output voltage

Digital inputs are converted to output voltages on a linear conversion between 0 and \(V_{\text{REF+}}\).

The analog output voltages on each DAC channel pin are determined by the following equation:

\[\text{DACOUT} = V_{\text{DD}} \times (\text{DOR}/64)\]

14.4.5 DAC trigger selection

If the TEN control bit is set, conversion can then be triggered by an external event (TIM16 counter, PA8 from SYSCFG). The TSEL[2:0] control bits determine which out of 3 possible events trigger conversion (see register DAC control register (DAC_CR)).

Each time a DAC interface detects a rising edge TIM16 TRGO output, or on the PA8 pin event from SYSCFG, the last data stored into the DAC_DHR register are transferred into the DAC_DOR register. The DAC_DOR register is updated three APB0 cycles after the trigger occurs, while if software trigger occurs it's updated one APB0 cycle later.

If the software trigger is selected, the conversion starts once the SWTRIG bit is set. SWTRIG is reset by hardware once the DAC_DOR register has been loaded with the DAC_DHR register contents.

Note: TSEL[2:0] bit cannot be changed when the EN bit is set.

When software trigger is selected, the transfer from the DAC_DHR register to the DAC_DOR register takes only one APB0 clock cycle.

14.4.6 DMA request

DAC channel has a DMA capability. DMA channel is used to service DAC channel DMA requests.

A DAC DMA request is generated when an external trigger (but not a software trigger) occurs while the DMAEN bit is set. The value of the DAC_DHR register is then transferred into the DAC_DOR register.

DMA underrun

The DAC DMA request is not queued so that if a second external trigger arrives before the acknowledgment for the first external trigger is received (first request), then no new request is issued and the DMA channel underrun flag DMAUDR in the DAC_SR register is set, reporting the error condition. The DAC channel continues to convert old data.

The software should clear the DMAUDR flag by writing “1”, clear the DMAEN bit of the used DMA stream and re-initialize both DMA and DAC channel to restart the transfer correctly. The software should modify the DAC trigger conversion frequency or lighten the DMA workload to avoid a new DMA underrun. Finally, the DAC conversion could be resumed by enabling both DMA data transfer and conversion trigger.

For the DAC channel, an interrupt is also generated if its corresponding DMAUDRIE bit in the DAC_CR register is enabled.

14.4.7 Noise generation

In order to generate a variable-amplitude pseudonoise, an LFSR (linear feedback shift register) is available. DAC noise generation is selected by setting WAVE[1:0] to “01”. The preloaded value in LFSR is 0x2A. This register is updated, following a specific calculation algorithm, three APB0 clock cycles after each trigger event, unless software trigger is selected, in this case counter is incremented one APB0 clock cycle after each software trigger. A sequence of up to 2ⁿ⁻¹ numbers (where n = number of DAC bit) can be generated before the sequence repeats. The noise produced by this generator has a flat spectral distribution and can be considered white noise. However, instead of having a Gaussian output characteristics, it is uniformly distributed.

Figure 29. DAC LFSR register calculation algorithm

Block diagram of the DAC LFSR register calculation algorithm. It shows a 6-bit shift register with stages 0 to 5. The output of stage 5 is fed back through an XOR gate to the input of stage 0. The outputs of all stages are also fed into a NOR gate, which provides a feedback signal to the input of stage 0.
Block diagram of the DAC LFSR register calculation algorithm. It shows a 6-bit shift register with stages 0 to 5. The output of stage 5 is fed back through an XOR gate to the input of stage 0. The outputs of all stages are also fed into a NOR gate, which provides a feedback signal to the input of stage 0.

The LFSR value, that may be masked partially or totally by means of the MAMP[3:0] bits in the DAC_CR register, is added up to the DAC_DHR contents without overflow and this value is then stored into the DAC_DOR register.

If LFSR is 0x0000, a ‘1 is injected into it (antilock-up mechanism).

It is possible to reset LFSR wave generation by resetting the WAVE[1:0] bits.

Note: The DAC trigger must be enabled for noise generation by setting the TEN bit in the DAC_CR register.

14.4.8 Triangle-wave generation

It is possible to add a small-amplitude triangular waveform on a DC or slowly varying signal. DAC triangle-wave generation is selected by setting WAVE[1:0] to “1X”. The amplitude is configured through the MAMP[3:0] bits in the DAC_CR register. An internal triangle counter is incremented three APB0 clock cycles after each trigger event, unless software trigger is selected, in this case counter is incremented one APB0 clock cycle after each software trigger. The value of this counter is then added to the DAC_DHR register without overflow and the sum is stored into the DAC_DOR register. The triangle counter is incremented as long as it is less than the maximum amplitude defined by the MAMP[3:0] bits. Once the configured amplitude is reached, the counter is decremented down to 0, then incremented again and so on.

It is possible to reset triangle wave generation by resetting the WAVE[1:0] bits.

Figure 30. DAC triangle wave generation

Graph showing DAC triangle wave generation. The vertical axis represents the output value, with labels for 'DAC_DHRx base value' and 'MAMPx[3:0] max amplitude + DAC_DHRx base value'. The horizontal axis represents time. The waveform is a triangle wave starting at the base value, increasing linearly (labeled 'Incrementation'), reaching the maximum amplitude, and then decreasing linearly (labeled 'Decrementation') back to the base value. The cycle repeats.
Graph showing DAC triangle wave generation. The vertical axis represents the output value, with labels for 'DAC_DHRx base value' and 'MAMPx[3:0] max amplitude + DAC_DHRx base value'. The horizontal axis represents time. The waveform is a triangle wave starting at the base value, increasing linearly (labeled 'Incrementation'), reaching the maximum amplitude, and then decreasing linearly (labeled 'Decrementation') back to the base value. The cycle repeats.

Note: The DAC trigger must be enabled for triangle-wave generation by setting the TEN bit in the DAC_CR register.

The MAMP[3:0] bits must be configured before enabling the DAC, otherwise they cannot be changed.

14.5 DAC registers

14.5.1 DAC control register (DAC_CR)

Address offset: 0x00

Reset value: 0x0000 0000

Note: VCMBUFF can be used only in the LCSC (STM32WL33xx only) application (see Section 15: LC sensor controller (LCSC)) or by programming LCSC_ANATST_CFG register (bits[1:0]=0x3). VCMBUFF output is Vdd/2 whatever the value of DACOUT.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.VCMON
rw
1514131211109876543210
VCMENCMPENDMAUDRIEDMAENMAMP[3:0]WAVE[1:0]TSEL[2:0]TENBONEN
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:17 Reserved, must be kept cleared.

Bit 16 VCMON: VCMBUFF power-up. This bit is set and cleared by software.

0: VCM BUFFER OFF
1: VCM BUFFER ON

Bit 15 VCMEN: DAC channel output to VCM BUFFER enable. This bit is set and cleared by software.

0: DAC channel output to VCM BUFFER disabled
1: DAC channel output to VCM BUFFER enabled

Bit 14 CMPEN: DAC channel output to COMP INMINUS enable. This bit is set and cleared by software.

0: DAC channel output to COMP INMINUS disabled
1: DAC channel output to COMP INMINUS enabled

Bit 13 DMAUDRIE: DAC channel DMA Underrun Interrupt enable This bit is set and cleared by software.

0: DAC channel DMA Underrun Interrupt disabled
1: DAC channel DMA Underrun Interrupt enabled

Bit 12 DMAEN: DAC channel DMA enable This bit is set and cleared by software.

0: DAC channel DMA mode disabled
1: DAC channel DMA mode enabled

Bits 11:8 MAMP[3:0]: DAC channel mask/amplitude selector These bits are written by software to select mask in wave generation mode or amplitude in triangle generation mode.

0000: Unmask bit0 of LFSR/ triangle amplitude equal to 1
0001: Unmask bits[1:0] of LFSR/ triangle amplitude equal to 3
0010: Unmask bits[2:0] of LFSR/ triangle amplitude equal to 7
0011: Unmask bits[3:0] of LFSR/ triangle amplitude equal to 15
0100: Unmask bits[4:0] of LFSR/ triangle amplitude equal to 31
≥ 0101: Unmask bits[5:0] of LFSR/ triangle amplitude equal to 63

14.5.2 DAC software trigger register (DAC_SWTRIGR)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SWTRIG
w

Bits 31:1 Reserved, must be kept cleared.

Bit 0 SWTRIG: DAC channel software trigger This bit is set by software to enable/disable the software trigger.

0: Software trigger disabled

1: Software trigger enabled

Note: This bit is cleared by hardware (one APB0 clock cycle later) once the DAC_DHR register value has been loaded into the DAC_DOR register.

14.5.3 DAC channel data holding register (DAC_DHR)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DACDHR[5:0]
rwrwrwrwrwrw

Bits 31:6 Reserved, must be kept cleared.

Bits 5:0 DACDHR[5:0]: DAC channel 6-bit data These bits are written by software which specifies 6-bit data for DAC channel.

14.5.4 DAC channel data output register (DAC_DOR)

Address offset: 0x2C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DACDOR[5:0]
rrrrrr

Bits 31:6 Reserved, must be kept cleared.

Bits 5:0 DACDOR[5:0]: DAC channel data output These bits are read-only, they contain data output for DAC channel.

14.5.5 DAC status register (DAC_SR)

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.DMAUD
R
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
r_wc1

Bits 31:14 Reserved, must be kept cleared.

Bit 13 DMAUDR: DAC channel DMA underrun flag This bit is set by hardware and cleared by software (by writing it to 1).

0: No DMA underrun error condition occurred for DAC channel

1: DMA underrun error condition occurred for DAC channel (the currently selected trigger is driving DAC channel conversion at a frequency higher than the DMA service capability rate)

Bits 12:0 Reserved, must be kept at cleared.

14.6 DAC register map

The following table summarizes the comparator registers.

Table 37. DAC register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00DAC_CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.VCMONVCMENCMPEMDMAUDRIEDMAENMAMP[3:0]WAVE[1:0]TSEL[2:0]TENBONEN
Reset value00000000000000000
0x04DAC_SWTRIGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SWTRIG
Reset value0
0x10DAC_DHRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DACDHR[5:0]
Reset value0000000
0x2CDAC_DORRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DACDOR[5:0]
Reset value0000000
0x34DAC_SRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DMAUDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value0

Refer to Section 2.2.2: Memory map and register boundary addresses for the register boundary addresses.