This application note gives examples for generating audio output signals using the Digital to
Analog Converter (DAC) peripheral embedded in the STM32F0xx microcontroller family.
A digital to analog converter, DAC, is a device that has the opposite function to an analog to
digital converter, it converts a digital word to a corresponding analog voltage.
The STM32 DAC module is a 12-bit word converter, with one output channel for supporting
mono audio.
The DAC can be used in many audio applications such as: security alarms, Bluetooth
headsets, talking toys, answering machines, man-machine interfaces, and low-cost music
players.
STM32 DAC can also be used for many other analog purposes, such as analog waveform
generation and control engineering.
The application note is organized in two main sections:
●Section 1 describes the main features of the STM32 DAC module.
●Section 2 presents two examples.
–In the first example, DAC is used to generate a sine wavefom.
–In the second example, the DAC is used to generate audio from .WAV files.
Figure 12.CPU and DMA activities during wave playing process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4/18Doc ID 022846 Rev 1
AN4058DAC main features
ai18300
1 DAC main features
1.1 Data format
The DAC accepts data in 3 integer formats: 8-bit, 12-bit right aligned and 12-bit left aligned.
A 12-bit value can range from 0x000 to 0xFFF, with 0x000 being the lowest and 0xFFF
being the highest value.
Figure 1.DAC data format
1.2 Dedicated timers
In addition to the software and External triggers, the DAC conversion can be triggered by
different timers.
TIM6 is a basic timer and is basically designed for DAC triggering.
Each time a 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.
Figure 2.STM32F0xx DAC trigger channel
external trigger
SWTRIGx
TIM6_TRGO
TIM3_TRGO
TIM15_TRGO
TIM2_TRGO
TSELx[2:0] bits
DAC Channel 1 Trigger
Trigger selector x
MS30315V1
Doc ID 022846 Rev 15/18
DAC main featuresAN4058
MS30316V1
DAC
RAM
(Pattern Table 1)
(Pattern Table 2)
Channel 1
Output
DAC Triggers
CPU
1.3 DMA capabilities
The STM32 microcontrollers have a DMA module with multiple channels. The DAC channel
is connected to an independent DMA channel. In the case of STM32F0xx Microcontrollers,
the DAC channel is connected to the DMA channel 3.
When DMA is not utilized, the CPU is used to provide DAC with the pattern waveform.
Generally the waveform is saved in a memory (RAM), and the CPU is in charge of
transferring the data from RAM to the DAC.
Figure 3.DAC interaction without DMA
When using the DMA, the overall performance of the system is increased by freeing up the
core. This is because data is moved from memory to DAC by DMA, without needing any
actions by the CPU. This keeps CPU resources free for other operations.
6/18Doc ID 022846 Rev 1
Loading...
+ 12 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.