You are on page 1of 7

instructables

R2R Digital-Analog-Converter (DAC)

by Vulcaman

R2R Digital-Analog-Converter (DAC): Page 1


Hi, we set D0 to 5V, D1 to 0V , D2 to 5V and D3 to 0V.
You can also read this as " 0101 " in binary, but on
in this instructable, I want to show you, how you can this I will come later again. The circuit is now
create your own Digital-Analog-Converter (DAC) by changed to this:
simply using a R2R Resistor ladder. But at first, I
want to show you for what Applications a DAC is
used for.

For example, if you want to create an analog voltage


of 3V with your Arduino you will definitely run into
problems, because the Arduino isn't able to create
this kind of voltage. The Arduino could only output
different kinds of voltages: 0V (LOW) and 5V (HIGH).
So the variety of possible voltages on the Arduino is
limited.
At this point you need to consider, how you could
The answer to this problem is a simple circuit, which analyze this circuit. From the first look you will see
will convert an digital Voltage to a Analog voltage. two voltage sources (5V). One of the simplest ways
The simplest way to do so, is a R2R-Resistor ledder. to analyze a circuit with two voltage sources is to use
This schematic is for an 4Bit DAC connected to an superposition. If using superposition, you first
Arduino at Pin D0, D1, D2 and D3. For this circuit you consider only about the first voltage source and the
need two types of resistors: R and the double value of second will be pulled to ground. In the next step the
R (2R). For example 1k and 2k . first will be pulled to ground and the second will kept
on. After you have calculated the voltage V_OUT in
both cases, you can simply sum up the voltages and
you will have the resulting voltage.

So let's start with the first case: D0 is connected to


5V and D2 is pulled to ground:

Now we want to analyze this simple linear circuit,


how the Output voltage will change while changing
the applied voltages on the digital pins. For example

R2R Digital-Analog-Converter (DAC): Page 2


Here you will see two resistors (2R) connected in As you can see the resulting voltage will be 5V/16V
parallel followed by one resistor (R) in series . So the or in decimal 0,3125V.
resulting value will be 2R/2 + R = R . The voltage
source can be divided by two, if you consider the two Now we have completed the analysis for the first
2R resistors which are connected in series. The power source. For the second we will start from this
resulting circuit will look like: point and will use the same simplifications like in the
steps above:

Now it is rather simple. As you can see there are two


Once you have finished the analysis you will come to
2R resistors connected in parallel, followed by one R
this simplified circuit:
resistor in series, so the resulting resistor will be 2R.
The Voltage source needs to be divided by two again.
The result will look like that:

Now the output voltage will be 5V/4V or 1,25V in


decimal.

Now you need to repeat the simplification from the Conclusion:


step above two times and you will come to this The last step is to sum up both voltages to get the
simplified circuit real voltage on the V_OUT pin. In this case this will
be

0,3125V + 1,25V = 1,5625 V

But the main message of this calculation is how the


applied voltage to the R2R network will affect the
output voltage V_OUT. As you can see, when D0 is
set to HIGH, the resulting voltage will be divided by
16, but when D3 is set to HIGH, the out_put voltage

R2R Digital-Analog-Converter (DAC): Page 3


is only divided by 4. And that is the trick of the R2R
network, if you control your pins with binary values,
the voltage will directly follow the binary number.

For example:

A 4bit number is directly connected to the Pins, so


the first bit is connected to Pin D3 , the second to Pin
D2 , the third to pin D1 and the last to Pin D0.

If the number has a value of "0101", the affected


voltage will be 1,5625V, which is exactly the
calculated voltage above. The voltage V_OUT will
change linear to the assigned binary number! Now
you can simply extend your R2R network to 8bit to
create a more accurate DAC.

R2R Digital-Analog-Converter (DAC): Page 4


Step 1: The Simulation in Tinkercad-Circuits

For a simple simulation of this R2R DAC I haved used Tinkercad circuits.

This time I have extended the R2R DAC to an resolution of 8bit. You can simply press the "Simulation" button in
the Tinkercad project to start the simulation and see an sawtooth function on the oscilloscope. The Tinkercad-
Circuit project can be accessed by this link: https://www.tinkercad.com/things/bXuK4iUc6im . I have also
implemented rectangle, triangle and sawtooth functions. The functions needs to be comment out, then you can
start your simulation again. This code uses portmanipulation which makes the thing a lot easier than using arduino
functions like digitalwrite().

R2R Digital-Analog-Converter (DAC): Page 5


uint8_t level = 0;

void setup()
{
DDRD = B11111111; // set all Digital Pins on PORTD to OUTPUT
}

void loop()
{
//Rectangle
//PORTD = 255; // 255 is 11111111 in binary
//delay(1);
//PORTD = 0; // 0 is 00000000 in binary
//delay(1);

//Sawtooth
level %= 255;
PORTD = level++;

//Triangle
//for(int i = -255 ; i < 255 ; i++){
//PORTD = abs(i);
//}
}

R2R Digital-Analog-Converter (DAC): Page 6


Step 2: From Simulation to Reality

After the simulation it is always a good choice to build Triangle:


a prototype and test it in reality. For this test have
created the small circuit on a bread board and
connected it to an old oscilloscope.

Here are some pictures of the circuit in action:

Rectangle:

Conclusion:

For me this projects was a success, I have learned a


lot about how DAC works. But please remember, if
you consider to use this as a function generator, you
Sawtooth:
will definitely need to use an operation amplifier
connected as an impedance changer. This will make
your circuit more stable to different loads and different
impedances.

R2R Digital-Analog-Converter (DAC): Page 7

You might also like