# Binary-Weighted Digital To Analog Converter

Lea este artículo en español |

**Sumary**

In many of our projects we will need a

**Digital To Analog Converter**(

**DAC**) to generate an output analog voltage from signal samples. It is necessary, for example, when we want to generate video signals. As in these cases the input impedance of the monitor/TV is well-known we can construct a very simple (and cheap) DAC using a structure of resistors called "Binary-Weighted Resistors".

This DAC is simply a set of resistors in parallel of values 1R, 2R, 4R... <math>2^{N - 1}R</math>. Note that this structure is not a "R-2R ladder", it is a different structure that serves for the same purpose, each one has its own advantages and disadvantages<ref>This 1R-2R-4R structure is nonviable when the number of bits is elevated because it requires very precise resistors of values too higher. In those cases, a "R-2R ladder" structure usually solves this problem</ref> (see DAC types).

## Example

Many of the low cost FPGA development boards (*starter kits*) have a VGA port, but it has only 1-bit resolution DAC (Digital/Analog Converter) so we can obtain only <math>2^1x2^1x2^1=8</math> different colours on screen. How can we do to construct a N-bit DAC to obtain <math>2^Nx2^Nx2^N</math> colours?

If we know the load impedance connected to our DAC (for a VGA monitor is <math>Z_L=75\Omega</math>), we can use the simple resistor structure showed in Fig 1 for R, G and signals (one for each signal). In this figure, <math>a_{N-1},\ a_{N-2},\ \ldots,\ a_1,\ a_0\,</math> are the bits of the number that will be converted to an analog voltage <math>V_o</math>. Bit <math>a_{N-1}</math> is the most significant bit (MSB) and <math>a_0</math> is the least significant bit (LSB). If <math>a_i</math> is "1" then that pin is connected to <math>V_c</math> volts (tipicaly +5V or +3.3V) and if it is "0" is connected to ground (+0V).

The relation between resistors is:

<math>R_0 = 2R_1 = 4R_2 = \ldots = 2^{N-1}R_{N-1} </math>

The value of <math>R_0</math> is:

<math>R_0 = Z_L (2^N-1) \left[\frac{V_c}{V_{max}} - 1 \right]\,</math>

with:

- <math>N</math> the DAC number of bits
- <math>Z_L</math> is VGA monitor input impedance
- <math>V_c</math> voltage for logic "1", voltage for logic "0" is supposed to be +0V, if not, the equation above is incorrect.
- <math>V_{max}</math> is max analog output voltage. It corresponds to the code 111...111. The output range is (0V, <math>V_{max}</math>)

For example, consider a DAC with N=4 bits, <math>Z_L=75\Omega</math>, <math>V_{max} = 0.7V</math> and logic "1" represented by <math>V_c=3.3V</math>, the optimal resistors that we should use are:

<math>R_0 = 4.17K</math>

<math>R_1 = R_0/2 = 2.09K</math>

<math>R_2 = R_0/4 = 1.04K</math>

<math>R_3 = R_0/8 = 0.52K</math>

This values are not manufactured so we must approximate them by resistors off-the-self (precision resistors is recommended). This will introduce a considerable error in analog output signal. Fig 2. shows this error when the values indicated before are replaced with the values in the E12 series of resistors.

To obtain graphs like this, you can use the following Octave/Matlab scripts DAC_design.m and DAC_out.m. To obtain the error precisely, you should measure the resistors you are using with an ohm-meter.

### Building circuit

The usual way to make the DAC circuit would be in a PCB with its resistor, female VGA conector, etc. Like the peripheals sold by the manofacturer

There is, althought, most simple way to achieve this goal: put breadboard cables and resistors directly in expansion connectors of the FPGA board. Works fine but you shouldn't move it too much.

See VGADAC_TEST for VHDL files to check the circuit.

## If you don't know in advance the input/load impedance...

If you do not know beforehand the input impedance<ref>Because it is not known or because it varies too much with frecuency</ref> which you are going to connect to DAC output then you will need a op-amp as output stage to adapt impedances. Every commercial DAC chip like AD7303 has one.

Another problem to consider is that if the load impedance consumes too much current (high load), the DAC's output stage could saturate provoking the output signal peaks are trimmed (distortion). In this case you will have to use a power amplifier. In audio frecuencies and for small power (~1W) It's very typical to use LM386.

## References

- Digital-to-Analog Conversion
- Microelectronics, Jacob Millman & Arvin Grabel (a clasical text about electronics)

<references />