2
\$\begingroup\$

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.

https://i.imgur.com/RkyVBWF.png

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: enter image description here

My result:

enter image description here

\$\endgroup\$
  • 3
    \$\begingroup\$ why do you expect 5V? \$\endgroup\$ – Marcus Müller Aug 6 at 21:16
  • 7
    \$\begingroup\$ You haven't erred. All bits set (255) is 255/256 * Vref. (And, good observation skills, not saying "close enough") \$\endgroup\$ – Brian Drummond Aug 6 at 21:21
  • 4
    \$\begingroup\$ ("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.) \$\endgroup\$ – Marcus Müller Aug 6 at 21:23
  • 4
    \$\begingroup\$ Like I said, you have good observation skills. Now use them to find better sources... \$\endgroup\$ – Brian Drummond Aug 6 at 21:25
  • 2
    \$\begingroup\$ 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). \$\endgroup\$ – Marcus Müller Aug 6 at 21:57
10
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – user260321 Aug 6 at 22:04
  • 2
    \$\begingroup\$ @user260321 0V = ground \$\endgroup\$ – Aaron Aug 6 at 22:06
  • \$\begingroup\$ 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 \$\endgroup\$ – user260321 Aug 6 at 22:10
  • 3
    \$\begingroup\$ the switches need to suck voltage out of the R2R when the bit is a zero, \$\endgroup\$ – Jasen Aug 6 at 22:19
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – marcelm Aug 7 at 9:09
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I have an updated version here. Does this seem more correct to you? i.imgur.com/JaKTc5E.png \$\endgroup\$ – user260321 Aug 7 at 2:17
  • \$\begingroup\$ What does my link tell you? \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Aug 7 at 2:19
  • \$\begingroup\$ 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. \$\endgroup\$ – user260321 Aug 7 at 2:22
  • \$\begingroup\$ A logic gate output that switches between the rails is a SPDT \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Aug 7 at 2:42
  • 1
    \$\begingroup\$ I know that, but I want you to know it by reading, not me saying so \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Aug 7 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.