Path: AVR-EN => Applications => AVR-D/A-Converter => R/2R calculation basics   Diese Seite in Deutsch: Flag DE Logo
DAC8 Tutorial for learning AVR assembly language
for AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega
from ATMEL using practical examples


Simple 8-bit-Digital-to-Analog-Converter with a R/2R Network
Calculation basics of a R/2R network

Calculation basics R/2R net work

Here, it is demonstrated stepwise how a R/2R network functions and how it can be calculated.

One-Bit-DAC

1-Bit-DAC This is a simple One-Bit-DAC.

Depending from the state on the input on bit 0 the DAC generates two different analog voltages: The operating voltage VOp is the operating voltage of the AVR driving the output port, e.g. 5.0 V. The half operating voltage results from the resistor divider, which consists of the two 2R resistors. This voltage is divided:
Vout = VOp * 2R / (2R + 2R) = UOp * 0.5

The upper half of the operating voltage is consumed by the upper resistor.

For the starter three additional notes:

Two-Bit-DAC

2-bit-DAC Now we add two more resistors, to have a 2-Bit-DAC.

Depending from the state of the two bits not only two different but four voltages result. The binary output states 00, 01, 10 and 11 generate this. Here, the "2R" on the output on the lower part, and the "2R" to ground) are connected with the upper bit via a R, which is half the resistance of the 2R. That causes the name R/2R network.

The same principle can be continued to construct a 3-, a 4-, an 8- or a 10-bit DAC: just add additional output port pins, a "2R" and a "R" for each of these.

Currents in a 2-bit-DAC How it works that the two input pins 0 and 1 contribute so differently to the resulting voltage at VR1 can only be understood by looking at all the currents in the network. The calculation of all those currents is a bit more complicated and requires some algebra, but comes to a simple result. Here is the complete calculation.

Calculation of the 2-bit-DAC The result of all those calculations in equation (18) is rather simple, all resistors and currents have disappered and the result is nice: both bits contribute to the output voltage by their binary part. Bit 1 one half, bit 0 one fourth.

Equation (19) writes this as a general formula for n bits. Without having to write down douzends of currents through 9 times 2R and 7 times R. That would not fit to a HTML screen, and especially not onto the screen of a mobile phone.

The maximum voltage that a R/2R network provides is not the operating voltage but slightly smaller (due to the lowest 2R to ground). It rather is:
VMax = VOp * (2n - 1) / 2n

In case of an 8-bit network and 5.0 V the maximum is 4.98 V.

Eight-bit-DAC

8-bit-DAC To the left is an 8-bit-DAC, with all his in- and output connections.

Formula for V(R0) There is a simpler method to calculate the eight-bit-resistor network. We again start with the lowest bit, bit 0, and calculate the voltage on the lowest cross point of the network, VR0. This depends from the next higher voltage on the next higher cross point, VR1, as well as from the output voltage of the bit 0 pin. The current flowing in to the crosspoint from above, IR10 equals the two currents that flow out of the network, IR00 and IR01, formula (1).

The currents are simple: IR10 is simply the voltage difference between VR1 and VR0, divided by R. The current IR00 is the voltage difference between VR0 and the pin's output voltage V0 (which can be zero or the operating voltage). The current IR01 is VR0, divided by 2R. This is the content of formula (2).

We now multiply all components by 2R and, by that, get rid of all the resistors, formula (3).

Now we sort all VR1 components to the left, anything else to the right, yielding formula (4). After summing up, we end with 4 * VR0 on the left, formula (5), and divide by 4 to get formula (6) for VR0.

The result is rather simple to understand: VR0 is half the next higher voltage, VR1 plus one fourth of the voltage on port pin 0.



Formula for V(R1) Now we have to take care of the next higher voltage, VR1. This depends in the same way from the current from above, IR20, the current to the pin 1, IR10, and the current to the next lower crosspoint, IR11, formula (7).

We again multiply all this by 2R and again get rid of R, formula (8). In the next step we replace VR0 by the term in formula (6) to get formula (9). And again we sort by our unknown VR1 in formula (10). Also again, we divide by four and get the simple result in formula (13). Again, the voltage VR1 depends from one half of the next upper voltage, VR2, from one fourth of the voltage on pin 1 and by one eight of the voltage on pin 0.

Formula for V(R2) And again do all the same for VR2. And, surprise, surprise: come out with the same sort of formula: one pin half added, the influence of the lower pins all divided by two, so that now pin 0 contributes only one sixteenths.



And: doing the same for the next four higher pins yields the formula for the complete 8-bit-R2R network. Now pin 0 contributes only 1 / 256 to VR7, the higher pins always by the factor 2 more.

Now, what happens if all higher bits are zero and only pin 0 is high? The pin 0 then feeds current into all upper pins, all currents have a negative sign, and the farer above the pin the lower is the current feeded. But pin 0 has to serve them all a bit.

Currents into and out of a R2R network

A nice and interesting task: calculate all currents for all eight pins and for all 256 byte combinations, and sum up all positive currents and all negative currents separately to yield the current on the VCC and on the GND pin of the AVR, that can be caused by the attached R2R network.

Which bit combinations out of the 256 possible cause the largest source and sink currents?

Consult the attached Libre-Office-Calc file here for the interesting answers to this academic question.

To the top of that page

©2017/2021 by http://www.avr-asm-tutorial.net