Our Latest News

DAC characteristics for audio and waveform generation using the DACs of the STM32 microcontroller family

Preface

This application note provides an example of generating an audio output signal using a digital-to-analog converter (DAC) peripheral, which is embedded in the STM32F10xx microcontroller family.

A digital-to-analog converter (DAC) is a device that converts data in digital form into the corresponding analog voltage signal, as opposed to an analog-to-digital converter.

This image has an empty alt attribute; its file name is image-137.png

The STM32 DAC modules are 12-bit word converters with two output channels supporting stereo audio. DACs can be used in a variety of audio applications, such as security alarms, Bluetooth headsets, audible toys, answering machines, human-machine interfaces, and low-cost music players STM32 DACs also enable many other analog uses, such as analog waveform generation and control engineering.

DAC Main Features

1, data format DAC can use the following three integer format data: 8-bit right-aligned, 12-bit right-aligned, and 12-bit left-aligned. 12-bit values range from 0x000 to 0xFFF, where 0x000 is the minimum value, and 0xFFF is the maximum value.

182b725e-6e25-11ed-8abf-dac502259ad0.png
  1. The dual analog-to-digital DAC has two output channels, one converter for each channel. In the dual DAC channel mode, the conversion can be performed separately or simultaneously. When the DAC channels are triggered by the same trigger source, the two channels will be combined together to perform the update operation simultaneously, and the conversion will also be carried out simultaneously.
  2. Dedicated Timers In addition to DAC conversion triggered by software and external triggers, DAC conversion can also be triggered by different timers. TIM6 and TIM7 are the two basic timers, mainly used for DAC triggering. Whenever the DAC interface detects a rising edge on the selected timer trigger output (TIMx_TRGO), the last data stored in the DAC_DHRx register is transferred to the DAC_DORx register.
184aa0c0-6e25-11ed-8abf-dac502259ad0.png

4, DMA function The STM32 microcontroller is equipped with a multi-channel DMA module. Each DAC channel is connected to a separate DMA channel. For the STM32F100x microcontroller, DAC channel 1 is connected to DMA channel 3 and DAC channel 2 is connected to DMA channel 4. When DMA is not used, the CPU is used to provide the DAC with the mode waveform. Normally, the waveform is stored in memory (RAM) and the CPU is responsible for transferring data from RAM to DAC.

1875262e-6e25-11ed-8abf-dac502259ad0.png

When DMA is used, the overall system performance is improved by the release of the core. In this case, data is transferred directly from memory to the DAC via DMA, without the CPU performing any operations. This saves CPU resources that can be used for other operations.

18b1f824-6e25-11ed-8abf-dac502259ad0.png
  1. DMA underflow error When DMA provides mode waveform to DAC, sometimes there is a situation that DMA transfer speed is faster than DAC conversion speed. In this case, the DAC will detect that part of the mode waveform is ignored and will not be converted. It will then set the “DMA underflow error” flag to 1. The underflow error can be handled by a shared IRQ channel using a trigger timer, or by a dedicated interrupt when the DAC is not triggered by TIM6.
  2. White Noise Generator 6.1 Definition The STM32 microcontroller DAC provides the user with a pseudo-random code generator. Depending on the number of beats used on the shift register, a sequence with a maximum of 2 to the n-1 power can be generated before the sequence is repeated.
18cd32d8-6e25-11ed-8abf-dac502259ad0.png

The noise generated by the noise generator has a uniform spectral distribution, which can be considered as white noise. However, white noise is uniformly distributed and does not have Gaussian output characteristics.

18fc68be-6e25-11ed-8abf-dac502259ad0.png

The offset of the noise waveform can be programmed. By changing this offset (signal mode) using the pre-configured offset table, the user can obtain a waveform that corresponds to the sum of the signal mode and the noise waveform.

19268978-6e25-11ed-8abf-dac502259ad0.png

6.2 Typical Applications

STM32 microcontrollers have 12-bit enhanced ADCs with sample rates up to 1 M/s. In most applications, this resolution is sufficient, but in some cases where higher accuracy is required, the concept of oversampling and sampling the input signal can be used to reduce the use of external ADC solutions and reduce the power consumption of the application.

Details of these methods are described in detail in the section titled “Oversampling with White Noise” in STM32 Application Note AN2668.

White noise generators can also be used to generate electronic music, often directly or as input to a filter to create other types of noise signals. White noise generators are widely used in audio synthesis, often to reproduce the effects of percussion instruments such as cymbals, which have a high amount of noise in their frequency domain.

White noise generators can be used in control engineering, as well as in frequency response testing of amplifiers and electronic filters. White noise is a general-purpose synthetic noise source used for acoustic masking through tinnitus maskers.

7、Delta wave generator

7.1 Definition

The STM32 DAC provides the user with a triangle waveform generator with flexible offsets, amplitudes and frequencies. Theoretically, a triangle waveform is a waveform consisting of an infinite set of odd harmonics. The amplitude of the triangle waveform can be corrected using the MAMPx bit in the DAC_CR register.

195e8c56-6e25-11ed-8abf-dac502259ad0.png

See the STM32 Reference Manual for more information on the triangle waveform. Triangle waveform frequency is related to the frequency of the trigger source

1985d87e-6e25-11ed-8abf-dac502259ad0.png

The offset of the triangle waveform can be programmed. By changing the triangle waveform ground offset (signal mode) using the pre-configured offset table, the user can obtain a waveform that corresponds to the sum of the signal mode and the triangle waveform.

19b01738-6e25-11ed-8abf-dac502259ad0.png

7.2 Typical Applications

Triangle wave generators are often used for sound synthesis because their higher harmonics fall off more quickly and therefore have a softer tone than square waves.

Triangle wave generator circuits can also be used for a variety of modem circuit applications.

8、Cache output

In order to drive external loads without the use of external op-amps, the DAC channel has an embedded output buffer that can be enabled and disabled depending on the user application.

If the DAC output is not buffered, the actual voltage output will be lower than the expected voltage output when a load is present in the user application circuit. When the buffer is enabled, the actual voltage output will be very close to the desired voltage output.

19ea9912-6e25-11ed-8abf-dac502259ad0.png

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663