A Digital-to-Analog Converter (DAC) translates discrete binary codes into continuous analog voltages. If you send a mid-scale digital code of 2048 to a 12-bit DAC powered by a 3.3V reference, the exact converted analog output is 1.650V. The governing formula is Vout = (D / (2n - 1)) × Vref, which substitutes as (2048 / 4095) × 3.3V = 1.650V. This conversion assumes an ideal, perfectly linear DAC with a stable, noise-free voltage reference. If your reference voltage sags or your DAC suffers from high Integral Non-Linearity (INL), this theoretical math will not match your multimeter reading on the bench.

The Core Conversion Formula and Step Sizes

The fundamental assumption that fixes a DAC's output is the Reference Voltage (Vref) combined with the Resolution (n). The DAC divides Vref into 2n discrete steps. The voltage difference between one digital code and the next is the Least Significant Bit (LSB) voltage. According to Analog Devices' MT-012 tutorial on DAC architectures, ignoring the LSB step size is the most common reason hobbyists experience "jumpy" or granular analog outputs when driving sensitive op-amp circuits.

DAC Resolution vs. LSB Step Size (Voltage per Code)
Resolution (Bits) Total Codes (2n) LSB at 3.3V Vref LSB at 5.0V Vref Common IC Example
8-bit 256 12.94 mV 19.60 mV ESP32 Internal DAC
10-bit 1,024 3.22 mV 4.88 mV Arduino Due (DAC0/DAC1)
12-bit 4,096 0.80 mV 1.22 mV Microchip MCP4725 (I2C)
16-bit 65,536 0.05 mV 0.076 mV TI DAC8568 (SPI)

When building a circuit, always match your DAC resolution to your required analog precision. If you need to set a bias voltage within 5mV, an 8-bit DAC on a 5V rail (19.6mV steps) is physically incapable of the task; you must step up to at least a 12-bit DAC.

Neighboring Code Values and the 120V/230V Mains Shift

To visualize how the analog output scales around our 2048 baseline, here is a table showing a ±20% code range. This is critical when programming PID control loops where your output variable fluctuates around a mid-scale setpoint.

Code-to-Voltage Mapping (12-bit DAC, 3.3V Vref)
Digital Code (Decimal) Variance from Mid-Scale Analog Vout
1638 -20% 1.319V
1843 -10% 1.484V
2048 Baseline (Mid) 1.650V
2252 +10% 1.814V
2457 +20% 1.979V

How the Answer Shifts for 120V, 230V, and 3-Phase Systems

A common point of confusion is how low-voltage DACs interface with high-voltage AC mains. DACs do not output 120V or 230V directly; they output low-voltage DC control signals (typically 0-5V or 0-10V) that command intermediary power electronics. The conversion math shifts based on the driver topology:

  • 120V Single-Phase (Lighting/Heating): The DAC outputs 0-5V to an isolated Silicon Controlled Rectifier (SCR) firing board. A DAC output of 2.5V (mid-scale) commands a 90° firing angle, delivering roughly 60V RMS to the 120V load.
  • 230V / 3-Phase (Motors): The DAC outputs 0-10V to a Variable Frequency Drive (VFD). A 5V DAC output maps to 30Hz. The VFD then synthesizes a 3-phase PWM waveform, outputting ~115V RMS per phase to a 230V 3-phase induction motor.
  • Meaningless Conversion Threshold: If your DAC is driving a 4-20mA current loop transmitter for industrial 230V valve control, the voltage-to-current mapping becomes meaningless if the loop impedance exceeds the transmitter's compliance voltage (usually 24V DC). Always verify the burden resistance of your receiving PLC.

Real-World Architectures: R-2R vs. Sigma-Delta vs. PWM

Not all DACs calculate Vout the same way under the hood. The Microchip MCP4725 uses a different internal topology than the internal DAC on an ESP32. Choosing the wrong architecture leads to excessive heat, slow settling times, or horrible noise floors.

DAC Architecture Comparison for Bench and Field Use
Architecture Speed (Settling Time) Linearity / Noise Best Use Case
Resistor String Fast (µs range) Excellent DNL, guaranteed monotonic Precision DC biasing, sensor calibration
R-2R Ladder Very Fast (ns range) Prone to glitches at major carry transitions High-speed waveform generation, audio
Sigma-Delta Slow (ms range) High resolution, requires output filtering Slow-moving control loops (temperature, PID)
PWM + RC Filter Depends on RC time constant Poor (high ripple, dependent on Vcc noise) Cheap hobbyist motor speed control

FAQ: When DAC Conversion Becomes Meaningless

Why does my multimeter read erratic voltages when the code is static?

The code-to-voltage conversion is mathematically meaningless if your Vref is noisy. If you power a 12-bit DAC directly from an Arduino's 5V USB pin, every time the microcontroller switches GPIO pins or transmits data, the 5V rail sags by 20-50mV. Because the DAC multiplies the digital code by Vref, that 50mV Vref sag is directly injected into your analog output. Fix: Always power the DAC's Vref pin from a dedicated Low Dropout Regulator (LDO) like the LM317 or AMS1117-3.3, and place a 100nF X7R ceramic decoupling capacitor as close to the Vref pin as physically possible.

Why is the ESP32's internal DAC so inaccurate at the top and bottom of the range?

The internal 8-bit DAC on the original ESP32 (pins GPIO25 and GPIO26) is notorious for severe non-linearity at the rails. Below code 15 and above code 240, the output transistors enter non-ohmic regions, meaning the formula Vout = (D / 255) × 3.3V completely breaks down. You might send code 255 and only measure 3.1V. Fix: Never use the internal ESP32 DAC for precision work. Spend $4 on an external I2C MCP4725 breakout board to guarantee true rail-to-rail linearity.

Understanding how a digital to analog converter works requires looking past the basic binary math. By locking down your reference voltage, selecting the correct resolution for your LSB requirements, and mapping the low-voltage output correctly to your high-voltage drivers, you can achieve precise, repeatable analog control in any DIY or industrial environment.