Why is my basic DAC incorrect?

I tried to make a basic R2R digital to analog converter in a simulator.

Even with all bits set, I get an output of 4.98V rather than the 5V I would expect. I expected 5V since so many online resources say things like the output "ranging from 0 to 5V", so I may be (mistakenly) assuming that all bits set = 5V. However it makes sense to me that you'd want the output from a DAC to range from 0 to 5V exactly so you won't have to care about how many bits the thing supports, only knowing that 0 = min and 5V = max supported.

Where have I erred?

Edit: Furthermore, I assume I've erred because when I try to copy the same number as shown in the video (172, or 10101100), I don't get 3.4V but rather 4.884V:

Video's image:

My result:

• why do you expect 5V? – Marcus Müller Aug 6 at 21:16
• You haven't erred. All bits set (255) is 255/256 * Vref. (And, good observation skills, not saying "close enough") – Brian Drummond Aug 6 at 21:21
• ("the output usually rangesâ€¦" is not an argument. Look at what you've built. It's not hard to analyze that this can never reach 5V on the output. It's always a voltage divider.) – Marcus Müller Aug 6 at 21:23
• Like I said, you have good observation skills. Now use them to find better sources... – Brian Drummond Aug 6 at 21:25
• You've got that right, you get ever closer to your 5V, but never reach it. It's not that hard, actually. It's literally just V_supply/(2^number of bits)*(maximum value representable by number of bits). The latter is always one less than 2^(number of bits). – Marcus Müller Aug 6 at 21:57

There are two issues here. It is true that for the kind of DAC you constructed:

$$V_{MAX} = \frac{2^N-1}{2^N}\times V_{REF}$$ where $$\N=8\$$ and $$\V_{REF} = 5.000V\$$ in your case. So you will never get exactly 5V out...the difference is always the voltage equal to a change in the LSB, which is also called the resolution of the converter.

The other issue is that you have connected the R2R string incorrectly. You need to use SPDT switches instead of SPST switches, so that the end of each of the 2R resistors is connected either to $$\V_{REF}\$$ or to ground.

• Why do each of the 2R resistors need to be connected to ground? I was trying to emulate the microcontroller from the video. From the "perspective" of the 2R resistor, it receives either 5V (on) or 0V (off), I presume it doesn't care where it comes from. So I used a switch to either permit the full 5V through or to cut it off by flicking the switch on/off. Did I misinterpret something? – user260321 Aug 6 at 22:04
• @user260321 0V = ground – Aaron Aug 6 at 22:06
• Was able to match the video's voltage using the switch you suggested (although I guess they rounded the value up), does this seem more correct? i.imgur.com/JaKTc5E.png – user260321 Aug 6 at 22:10
• the switches need to suck voltage out of the R2R when the bit is a zero, – Jasen Aug 6 at 22:19
• @user260321 "... is a switch being turned off / no voltage not the same/equivalent as 0V / ground?" - Absolutely not! With the resistor disconnected, there will be no current through it. Connect it to ground, and calculate the current through the resistor, it will be non-zero. – marcelm Aug 7 at 9:09

Your design does not accurately reflect the R-2R DAC.

The correct design uses Binary logic Levels (SPDT) for each bit, not open-close SPST switches to 2R to Vref.

https://www.tek.com/blog/tutorial-digital-analog-conversion-r-2r-dac

A basic web search would tell you this.

• I have an updated version here. Does this seem more correct to you? i.imgur.com/JaKTc5E.png – user260321 Aug 7 at 2:17
• What does my link tell you? – Tony Stewart Sunnyskyguy EE75 Aug 7 at 2:19
• Not sure, seems to use slightly different notation/objects compared to the simulator I'm using, so it looks close to both my original diagram as well as the updated one (and the video), which doesn't address my confusion over how to handle the translation from the microcontroller. But I think it's probably correct now. – user260321 Aug 7 at 2:22
• A logic gate output that switches between the rails is a SPDT – Tony Stewart Sunnyskyguy EE75 Aug 7 at 2:42
• I know that, but I want you to know it by reading, not me saying so – Tony Stewart Sunnyskyguy EE75 Aug 7 at 3:06