EmbeddedRelated.com

DAC

Category: Peripherals | Also known as: digital-to-analog converter

A digital-to-analog converter (DAC) is a peripheral that converts a digital numeric value into a proportional analog voltage (or, less commonly, current). It is the complement of an ADC and is used wherever a microcontroller or DSP needs to generate a continuously variable analog signal.

In practice

On-chip DACs are found on many mid- to high-end MCUs — for example, the STM32F4/F7/H7 series includes one or two 12-bit DACs, the Teensy 3.x/4.x (NXP Kinetis and i.MX RT) includes a 12-bit DAC, and the Microchip PIC32MX/MZ families include DAC peripherals on selected parts. Lower-end 8-bit MCUs often omit a hardware DAC entirely, making PWM-plus-RC-filter or an external SPI/I2C DAC IC the practical alternative.

Resolution and sample rate are the two key specifications. A 12-bit DAC gives 4096 steps over its output range, which is sufficient for many audio and general analog control applications, though audio quality depends on many factors beyond resolution and sample rate alone. Higher-fidelity audio (44.1 kHz, 16-bit or better) often uses an external DAC such as the PCM5102 or CS4344, driven over I2S, primarily for the quality and convenience those dedicated parts provide rather than because on-chip DACs are categorically incapable. For slow control signals — setting a reference voltage, driving an analog actuator, trimming a power supply — even an 8-bit DAC is often adequate. When evaluating resolution, note that the effective number of bits (ENOB) is usually somewhat lower than the nominal resolution due to noise and nonlinearity.

A common pitfall is leaving the DAC output unloaded or connecting a load impedance that the output buffer cannot drive. Many on-chip DACs have output buffers with limited drive strength (often a few milliamps at most); exceeding the rated load degrades linearity and output swing. Some on-chip DACs (including certain STM32 configurations) allow bypassing the output buffer for a wider voltage range at the cost of requiring a high-impedance load. Always check the DAC output impedance and buffer specifications in the datasheet.

Glitches are another concern in dynamic applications. When the DAC code transitions across certain bit boundaries (notably the MSB), charge redistribution in the internal resistor ladder or capacitor array can cause a brief voltage spike. In audio or precision signal generation, a deglitching output filter or careful code sequencing may be necessary. For generating complex waveforms, a common technique is direct digital synthesis (DDS): a lookup table of samples is fed to the DAC at a fixed rate from a timer interrupt or DMA transfer, as discussed in resources like "Modulation Alternatives for the Software Engineer."

Frequently asked

My MCU has no DAC. How do I generate an analog output?
The most common workaround is PWM with a low-pass RC filter. The filtered PWM output approximates an analog voltage proportional to the duty cycle. The achievable bandwidth and ripple depend on the PWM frequency and filter cutoff. For better linearity or higher update rates, an external DAC IC connected via SPI or I2C is a cleaner solution. Parts like the MCP4921 (SPI, 12-bit) are inexpensive and widely used.
What is the difference between a voltage-output and a current-output DAC?
A voltage-output DAC presents a voltage proportional to the digital code; most on-chip MCU DACs and many external DAC ICs are voltage-output. A current-output DAC sources or sinks a current proportional to the code; an external transimpedance amplifier (resistor or op-amp) converts it to a voltage. Current-output architectures are common in high-speed and audio converter designs (e.g., PCM56, AD9744) because they can achieve higher speeds, but they require additional circuitry for typical voltage-drive applications.
How do I generate a continuous waveform (sine wave, arbitrary waveform) with a DAC?
The standard approach is direct digital synthesis (DDS): store one period of the waveform as a sample table in flash or RAM, then use a hardware timer to trigger DMA transfers or an interrupt at a fixed sample rate that feeds successive table values to the DAC. On STM32 parts, the DAC can be configured with a DMA request tied to a TIM timer update, generating the waveform with no CPU involvement per sample. The highest representable frequency component is limited to roughly half the sample rate (Nyquist), and a reconstruction (low-pass) filter on the output removes high-frequency images; the usable output bandwidth is further shaped by the analog output path and the filter's characteristics.
What does DAC reference voltage mean, and why does it matter?
The DAC reference voltage (VREF) sets the full-scale output. The output voltage for a given code is approximately (code / 2^N) * VREF, where N is the resolution. If VREF is noisy or drifts with temperature, the DAC output inherits that noise and drift. For precision applications, a dedicated low-noise voltage reference (e.g., LM4040, REF3033) should be used rather than the MCU supply rail, which typically carries switching noise from the CPU and other peripherals.
What is the difference between a DAC and a sigma-delta modulator output?
A conventional DAC (R-2R ladder, string, or segmented architecture) produces a multi-level output that directly represents the digital code. A sigma-delta DAC (used in most high-resolution audio converters) oversamples and noise-shapes a 1-bit or few-bit stream to achieve high effective resolution; the analog output is recovered by a low-pass filter. Sigma-delta DACs can achieve 16 to 24 ENOB at audio bandwidths but require significant filtering and are not suited for arbitrary fast-settling waveforms. The blog post 'Isolated Sigma-Delta Modulators, Rah Rah Rah!' covers isolated sigma-delta modulator designs in more detail.

Differentiators vs similar concepts

DAC vs. PWM-as-analog-output: PWM is a digital signal whose average value approximates an analog level after filtering, but it carries significant ripple, has limited bandwidth set by the filter, and is nonlinear near the rails. A true DAC produces a direct, settled analog voltage each conversion cycle with lower ripple and better linearity, at the cost of requiring a dedicated peripheral or external IC. PWM is a practical substitute on hardware that lacks a DAC, but it is not equivalent in precision or dynamic performance.