DAC STM Application Note
DAC STM Application Note
Application note
Extending the DAC performance of STM32 microcontrollers
Introduction
Most of the STM32 microcontrollers embed 12-bit DACs (digital to analog converters),
specified to operate up to 1 Msps (megasamples per second).
Several applications benefit from DACs operating at higher speeds, this note explains how
to extend the speed performance of microcontrollers listed in Table 1 using external
operational amplifiers (OpAmps).
The STM32 DAC system is described in Section 1 of this document, while an application
example focusing on 5 Msps sine wave generation is presented in Section 2.
STM32F0 Series
STM32F1 Series
STM32F2 Series
STM32F3 Series
STM32F4 Series
STM32F7 Series
STM32G0 Series
Microcontrollers
STM32G4 Series
STM32H7 Series
STM32L0 Series
STM32L1 Series
STM32L4 Series
STM32L4+ Series
STM32L5 Series
Contents
2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1 External OpAmp choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Software implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.1 Digital sine waveform pattern preparation . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.2 Setting the sine waveform frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.3 Offset calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.4 Output gain calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1 Board modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Measurement results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
List of tables
List of figures
Ra S1
DACINT
VREF+
S2 DACOUT
R
VREF-
R
VREF- MS35843V2
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
When the output buffer is disabled, the output signal speed simply follows the RC constant,
which is determined by the DAC output impedance RDAC (= 2 * Ra) and the capacitive load
on the DACOUT pad.
As an example, the STM32F407 defines the impedance output with buffer off at a maximum
value of 15 kΩ. If a 10 pF capacitive load (including the parasitic capacitance of the
STM32F407 device on DACOUT pad) is considered, to get ±1 LSB of the final value (from
lowest code to highest code) we have
1 T⁄ ( CR )
1 – ------
N
= 1–e
2
Solving for T gives T = CR * N* ln 2 = 0.693 CR * N = 1.8 µs, hence, in this configuration the
conversion time cannot be smaller than 1.8 µs (equivalent to a frequency of 555 kHz).
This analysis does not include any effect of the switching speed of the DAC itself and its
transient. When using high speed, these factors cannot be ignored, they degrade the
performance.
DAC
RDAC DACOUT
VREF+
R2
VREF- Cp
R3
In this configuration there is a minor limitation due to the RC constant, the main limitation
being the external OpAmp speed (gain bandwidth and slew rate) and the DAC digital data
update rate. There are, however, some disadvantages. The feedback resistor R1 needs to
be equal to the RDAC on chip of the STM32, otherwise it will create a DAC gain error.
Integrated resistors usually feature a rather wide spread on their absolute value, and
significant variation over temperature, hence it is necessary to calibrate the gain error
(discussed in detail in Section 2.2.4: Output gain calibration).
It is also possible to use the external OpAmp with voltage follower mode. This enhances the
output bandwidth and slew rate, however the RDAC output impedance and the parasitic
capacitor on the DACOUT form an RC filter that limits the speed performance.
For the voltage follower mode, it is not necessary to perform the gain calibration.
Table 2 shows the maximum sampling rate for different STM32 products.
Note: Values reported in Table 2 have been measured on the bench, when bus is not used by any
other system: in real applications it is necessary to have some margin.
1.5 Summary
By using an external high speed OpAmp, it is possible to extend the speed performance of
the STM32 DACs by more than 1 Msps, see Section 2 for an example showing how to use
this technique on STM32 products.
2 Example
The example of the high speed use of the DAC is based on STM32F407, it shows how to
generate a 200 kHz sine wave by the DAC operating at 5 Msps.
Digital inputs are converted to output voltages by linear conversion between 0 and VREF+.
The analog output voltage on each DAC channel pin is determined as:
DOR
DAC Output = V REF ⋅ -----------------------------------------------------------
DAC_MaxDigitalValue
Y ( x ) = 3.3Volt ⋅ Y ( x ) ⁄ 0xFFF
SineAnalog SineDigital
The table can be saved in the memory and transferred by DMA. The transfer is triggered by
the same timer that triggers the DAC.
2047 2065
2065 2048
1023 3135
3071 983
3.1 x 0xFFF + 1
Y ( x ) = ---------------------------------- ⋅ ⎛ sin ⎛ 2Π ⋅ -------⎞ + 1⎞ ⋅ ---------------------------- + 18
SineDigital 3.3 ⋅ 1.0508 ⎝ ⎝ n S⎠ ⎠ 2
0 2066
1 2521
2 2948
3 3319
4 3612
5 3807
6 3893
7 3864
8 3723
9 3477
10 3142
11 2740
12 2295
13 1837
14 1392
15 990
16 655
17 409
18 268
19 239
20 325
21 520
22 813
23 1184
24 1611
Note: The output signal is inverted compare to the digital code, due to the inverting amplifier stage
of the external OpAmp.
R1
VDD
C3
From MCU DAC pin (PA4)
VDD
LMH6645
R2
R3
C2
MS35841V1
R1 12 kΩ
Resistor R2 10 kΩ
R3 10 kΩ
C1 5 pF
Capacitor C2 100 nF
C3 100 nF
3 Measurements
The measurements have been done on a STM32F4Discovery board with the configuration
shown in Figure 3.
Output swing is not equal to 3.1 Vpp, as sampling time is not aligned with the peak of the
sine wave signal.
The second and third harmonics are around the noise level.
4 Conclusions
5 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other
product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.