A Digital-to-Analog Converter (DAC) is an electronic circuit that translates discrete digital binary codes into continuous analog voltage or current signals. In the context of embedded systems, a microcontroller's CPU only understands logic levels—typically 0V for a '0' and 3.3V or 5V for a '1'. When your project requires a smooth, variable DC voltage to bias a transistor, generate an audio sine wave, or set a precise motor speed, a DAC bridges the gap between the digital brain and the physical analog world. It changes a circuit by replacing fixed on/off digital states with proportional, infinitely variable control over physical components.
Resolution, Step Size, and the Math Behind the Output
The most critical specification of any DAC is its resolution, measured in bits. This determines how many discrete voltage 'steps' the DAC can output between 0V and its reference voltage (Vref). A higher bit count means smaller steps, resulting in a smoother and more precise analog output. The size of the smallest possible voltage change is called the Least Significant Bit (LSB) or step size.
Here is how resolution translates to real-world voltage steps on common microcontroller logic levels:
| Resolution (Bits) | Total Steps (2^n) | Step Size (LSB) at 3.3V Ref | Step Size (LSB) at 5.0V Ref | Common Use Case |
|---|---|---|---|---|
| 8-bit | 256 | 12.94 mV | 19.61 mV | Basic LED dimming, simple motor control |
| 10-bit | 1,024 | 3.23 mV | 4.89 mV | General purpose sensor simulation |
| 12-bit | 4,096 | 0.81 mV | 1.22 mV | Audio generation, programmable power supplies |
| 16-bit | 65,536 | 0.05 mV | 0.08 mV | Synthesizer CV, precision lab equipment |
Worked Numeric Example: Dialing in Exactly 1.50V
Let's say you are building a programmable power supply using an ESP32 and an external 12-bit DAC (like the popular MCP4725). Your DAC is powered by a clean 3.3V reference, and you need to output exactly 1.50V to set a regulator's feedback loop.
The formula to find the digital value to send over I2C or SPI is:
Digital Value = (Target Voltage / Vref) × (2^n - 1)
Plugging in our real values:
Digital Value = (1.50V / 3.3V) × (4096 - 1)Digital Value = 0.4545 × 4095Digital Value = 1861.36
Since you can only send whole integers to the DAC register, you round to 1861. When the DAC processes this 12-bit integer, the actual output voltage will be 1861 × (3.3V / 4095) = 1.4997V. That 0.3mV error is well within the tolerance of most analog feedback circuits.
The Core Mechanism: How the Silicon Actually Switches
Under the hood, a DAC doesn't just 'guess' the voltage. It uses physical resistor networks or switched capacitor arrays to sum binary-weighted currents or voltages. The most common architecture you will encounter in hobbyist and mid-tier industrial chips is the R-2R resistor ladder.
In an R-2R ladder, a network of resistors with only two values (R and 2R) is connected to a series of electronic switches. Each switch corresponds to one bit of your digital input. When a bit is '1', the switch connects that node to the reference voltage; when '0', it connects to ground. Because of the specific ratio of the resistors, the binary-weighted currents sum together at the output amplifier. The most significant bit (MSB) contributes half of the total output voltage, the next bit contributes a quarter, the next an eighth, and so on. According to Analog Devices' MT-012 tutorial on DAC architectures, this binary scaling allows the circuit to translate a parallel digital word into a single, precise analog voltage in nanoseconds.
For higher resolution (16-bit and above), silicon designers often use Sigma-Delta or Segmented architectures to avoid the impossibly tight resistor matching tolerances required by massive R-2R ladders. If you are using the internal DAC on an original ESP32 (on pins GPIO25 and GPIO26), you are actually using a built-in 8-bit Sigma-Delta DAC, which is why the Espressif ESP32 Datasheet notes its non-linearity and limits its use to basic audio or slow control signals.
True DAC vs. PWM: The Most Common Confusion
The most frequent mistake embedded beginners make is confusing a true DAC output with Pulse Width Modulation (PWM). When an Arduino user types analogWrite(pin, 127), they are not outputting an analog voltage. They are outputting a 5V digital square wave that switches on and off so fast (usually around 490 Hz) that it spends 50% of its time HIGH and 50% LOW.
If you measure a 50% duty cycle PWM pin with a multimeter, the meter's internal averaging will display ~2.5V. But if you hook that same pin to an oscilloscope, you will see a harsh digital square wave bouncing between 0V and 5V. If you feed that PWM signal directly into an audio amplifier, you won't hear a smooth tone; you will hear a harsh, buzzing square wave and likely blow the tweeter.
You can turn a PWM signal into a true analog DC voltage by adding a physical RC (resistor-capacitor) low-pass filter to the output pin. A 10kΩ resistor and a 10µF capacitor will smooth the square wave into a DC level. However, this introduces severe latency (the voltage takes time to charge/discharge the capacitor) and limits your ability to output fast-changing waveforms like audio. A true DAC outputs the smooth voltage directly from the silicon, with no external filtering required for DC applications.
For a comprehensive breakdown of why true DACs are necessary for high-fidelity signal generation, Texas Instruments' DAC overview documentation highlights the critical differences in settling time and harmonic distortion between filtered PWM and dedicated DAC silicon.
Where You Meet DACs in Practice (and Which Chips to Buy)
Knowing how a DAC works is only half the battle; selecting the right architecture for your specific project is where the engineering happens. Here is where you will actually use DACs in the wild, along with the exact chips you should buy for the job.
- General DC Bias and Programmable Power Supplies: When you need to set a static voltage to control a bench power supply, an electronic load, or a motor driver's reference pin, an I2C DAC is perfect.
Buy the MCP4725: A 12-bit I2C DAC. Breakout boards cost around $4. It includes an internal EEPROM, meaning it remembers its last voltage setting even when power is cut. - High-Fidelity Audio Generation: If you are building an ESP32-based internet radio or a wavetable synthesizer, I2C DACs are too slow. You need an I2S (Inter-IC Sound) DAC, which streams stereo audio data synchronously.
Buy the PCM5102A: A 24-bit/192kHz I2S DAC module. Costs about $6. It requires no external analog filtering for line-out audio and interfaces directly with the ESP32's I2S peripheral. - Analog Synthesizers and Eurorack CV: Modular synthesizers use 'Control Voltage' (CV) to dictate pitch, typically tracking at 1 Volt per octave. If your DAC is only 12-bit, a 10V range yields ~2.4mV steps, which translates to noticeable pitch quantization (out-of-tune notes) in the higher octaves. You need 16-bit resolution.
Buy the DAC8568: A 16-bit, 8-channel SPI DAC. Costs around $25. It provides the sub-millivolt precision required for perfect 1V/octave tracking across multiple oscillator voices.
Ultimately, understanding how a DAC works allows you to stop relying on the 'analogWrite' crutch and start designing circuits that interact with the physical world with true, mathematically precise analog control.






