# Trying to expand my knoledge: R2R DAC

Found this, thought I would share it, in case it may be of interest.

I was looking for a crude DAC for a constant variable voltage source. not much for current capacity though.
I presume a lot of resistors, and an Arduino Mega2560 would make a fairly good DAC, not counting the cost of components, of course.

~Travis

I'm not sure if you would be interested , but for \$5 you can get a 12-bit DAC

If you prefer to build the R2R dac I would recommend the LT1215 op amp. Of course almost any op amp will work.

8-bit DACs

.

How wide an array of voltages do you need? You can connect IO pins (via appropriately calculated resistors) to the ADJ pin of a linear regulator to to tweak the output voltage of the regulator. Since IO pins have three states (source/off/sink) you can get quite a few voltages from the regulator with just a few pins.

Fig 9.2.17 of TI's LM317 datasheet explains this concept. Transistors aren't required depending on your resistor selection.

How many bits do you need to use. Note that 1% resistors will only get you six bits.

Grumpy_Mike:
How many bits do you need to use. Note that 1% resistors will only get you six bits.

For a 6 bit system, the output voltage uncertainty using hypothetically perfect resistors would be around 0.78%, right? Half the resolution, 0.5 * 1/(2^6). So 1% tolerance resistors might not make it?

travis_farmer:
... higher math was never a strong point during school. I took Applied Algebra, but never really got it till I got heavy into electronics after school.
...

I had fits with math all through school, none-the-less, I forced myself to take it. Once I quit trying to "get" it and just "did" it instead, math and me got along much better!

travis_farmer:
Well heck, that is way too much math for 5:22 AM.

But seriously, 0.78125% relates to what?

Trav..... it's the same thing as a ruler. The uncertainty or error is half the smallest spacing.... a ruler typically has 1 mm spacings. So the measurement uncertainty is plus or minus half a mm.

For a N bit digital (binary) number..... eg 6 bit, there are 2^6 = 64 unique values ... or levels. If we choose to divide this value into say an arbitrary chunk of cake.... and call the full cake '1'. Then we would get the smallest chunk being 1/[2^6].

The full cake can be thought of as 1 Volt if we like. If only considering positive voltages.... then we would start from 0V...lowest level. Then next level up is 1/[2^6]. Then next level up is 2/[2^6]....then 3/[2^6]... all the way up to 63/[2^6] = 63/64.

Again....the smallest gap or voltage increment is 1/64. So...just like a ruler.... the uncertainty is + or - half this value.... ie + or - 1/128.... which is 0.0078125....or 0.78125%.

The resistor ladders of DAC ... such as r-2r ladder or another kind called binary weighted resistor ladder.... the output voltage accuracy will depend on the resistor value accuracies. Working out the actual voltage uncertainty or error for say a r-2r ladder would require applying error analysis on the ladder circuit. In general... the most critical resistors need to be made accurately.... with uncertainty or error less than the quantisation uncertainty... such as 0.78125%.

I had fits with math all through school, none-the-less, I forced myself to take it. Once I quit trying to "get" it and just "did" it instead, math and me got along much better!

I had test anxiety so I had a whiskey flask and went in the men's room just before a test and drank three swigs of cognac just before a big test to calm my nerves. My brother preferred Crown Royal.

But seriously, 0.78125% relates to what?

The minimum tolerance of the resistor you will need to guarantee monoticinty. This means to ensure that a bigger digital input produces a bigger analogue output.

Quite frankly, the Adafruit module is sounding better and better.

Just to be accurate, it's also available from Sparkfun.

The voltage is always repeatable, but step 32 might not give a higher analogue output than step 31 did. If it does that it does it all the time.

raschemmel:
I had test anxiety so I had a whiskey flask and went in the men’s room just before a test and drank three swigs of cognac just before a big test to calm my nerves. My brother preferred Crown Royal.

HA! Yeah, same thing, but it was 1972 and organic chemistry, so I took LSD.

These days I much prefer cognac.

travis_farmer:
Ahh, I think I got it. the result of the formula is the tolerance, and being 1% tolerance, 'common' resistors do not have enough accuracy at the given bit level for a repeatable resulting voltage. in other words, the step level 31 in a 64-bit R-2R may drift into steps 30 or 32, or more.
so in 5V 6-bit, step R-2R, step 31 (2.46V) , it could drift +- 0.64V, or about 3.1V to 1.8V. :o

does that sound right?
Quite frankly, the Adafruit module is sounding better and better.

~Travis

Spot on Travis. In order to mimic the perfect (ideal) system, or do what the ideal (perfect) system does in terms of getting output value to correctly change (1 bit at a time, or output the voltage to the correct voltage region (in between two adjacent quantisation levels) ..... the resistor tolerance needs to be good enough for the purpose. Usually, the resistors associated with generating a voltage for the least significant bit needs to be most accurate (in fabrication).

What you said in reply #16 was correct. This might not be the same thing as reply #17 thought you had said.

Usually, the resistors associated with generating a voltage for the least significant bit needs to be most accurate (in fabrication).

True for a binary weighted D/A but not for an R-2R. There it is the most significant bit that contribuitions most current and has to be close to the real value.

The thing about the ladder is the actual value of R is unimportant it is how close all the values of R are to each other.

These days I much prefer cognac.

It is easier to acquire.

HA! Yeah, same thing, but it was 1972 and organic chemistry, so I took LSD.

No moldy rye bread around ?

travis_farmer:
oh, I see. that makes more sense. So in other words, a R-2R ladder is a little to crude with 1% resistors to be practical for much of anything, if precision is desired.

But 0.1% or better resistors aren't exactly expensive these days...

Grumpy_Mike:
The thing about the ladder is the actual value of R is unimportant it is how close all the values of R are to each other.

Yeah....but if R values are too extreme, then currents could be too small, or voltages could get noisier etc. Also, if you have voltage dividers, then uncertainty in R value translates to uncertainty in output value, right? And knowing how close the R values are to each other will mean knowing their values accurately, or at least in some cases knowing ratios of resistances accurately.

Also, if you have voltage dividers, then uncertainty in R value translates to uncertainty in output value, right?

Right.

Grumpy_Mike:
Right.

Thanks Grumpy Mike. I see what you mean there. Really good comment you made about R-2R and binary weighted ladder difference too.