# 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... $2^{N - 1}R$. 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 $2^1x2^1x2^1=8$ different colours on screen. How can we do to construct a N-bit DAC to obtain $2^Nx2^Nx2^N$ colours?

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

Fig. 1. Binary-Weighted DAC structure
Fig 2. Output voltage error after replace calculated resistors with E12 series resistors

The relation between resistors is:

$R_0 = 2R_1 = 4R_2 = \ldots = 2^{N-1}R_{N-1}$

The value of $R_0$ is:

$R_0 = Z_L (2^N-1) \left[\frac{V_c}{V_{max}} - 1 \right]\,$
with:

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

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

$R_0 = 4.17K$
$R_1 = R_0/2 = 2.09K$
$R_2 = R_0/4 = 1.04K$
$R_3 = R_0/8 = 0.52K$

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

Resistors in series with cable

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.