SECTION 13.2: DAC INTERFACING
This section will show how to interface a DAC (digitaltoanalog converter) to the 8051. Then we demonstrate how to generate a sine wave on the scope using the DAC.
Digitaltoanalog (DAC) converter
The digitaltoanalog converter (DAC) is a device widely used to convert digital pulses to analog signals. In this section we discuss the basics of interfacing a DAC to the 8051.
Recall from your digital electronics book the two methods of creating a DAC: binary weighted and R/2R ladder. The vast majority of integrated circuit DACs, including the MC1408 (DAC0808) used in this section, use the R/2R method since it can achieve a much higher degree of precision. The first criterion for judging a DAC is its resolution, which is a function of the number of binary inputs. The common ones are 8, 10, and 12 bits. The number of data bit inputs decides the resolution of the DAC since the number of analog output levels is equal to 2″, where n is the number of data bit inputs. Therefore, an 8input DAC
such as the DAC0808 provides 256 discrete voltage (or current) levels of output.
Similarly, the 12bit DAC provides 4096 discrete voltage levels. There are also
16bit DACs, but they are more expensive.
MC1408 DAC (or DAC0808)
In the MC1408 (DAC0808), the digital inputs are converted to current (I_{out}), and by connecting a resistor to the I_{out} pin, we convert the result to voltage.
The total current provided by the I_{out} pin is a function of the binary numbers at the DO – D7 inputs of the DAC0808 and the reference current (I_{re}f), and is as follows:
where DO is the LSB, D7 is the MSB for the inputs, and I_{re}f is the input current that must be applied to pin 14. The I_{re}f current is generally set to 2.0 mA. Figure 1318 shows the generation of current reference (setting I_{re}f = 2 mA) by using the
standard 5V power supply and IK and 1.5Kohm standard resistors. Some DACs also use the zener diode (LM336), which overcomes any fluctuation associated
Figure 1318. 8051 Connection to DAC808
Example 133
with the power supply voltage. Now assuming that I_{re}f = 2 mA, if all the inputs to the DAC are high, the maximum output current is 1.99 mA (verify this for yourself).
Converting l_{out} to voltage in DAC0808
Ideally we connect the output pin I_{out} to a resistor, convert this current to
voltage, and monitor the output on the scope. In real life, however, this can cause inaccuracy since the input resistance of the load where it is connected will also affect the output voltage. For this reason, the I_{ref} current output is isolated by connecting it to an opamp such as the 741 with R_{f} = 5K ohms for the feedback resistor. Assuming that R = 5K ohms, by changing the binary input, the output voltage changes as shown in Example 134.
Example 134
In order to generate a stairstep ramp, set up the circuit in Figure 1318 and connect the output to an oscilloscope. Then write a program to send data to the DAC to generate a stairstep ramp.
Solution:
Generating a sine wave
To generate a sine wave, we first need a table whose values represent the magnitude of the sine of angles between 0 and 360 degrees. The values for the sine function vary from 1.0 to +1.0 for 0 to 360degree angles. Therefore, the table values are integer numbers representing the voltage magnitude for the sine of theta. This method ensures that only integer numbers are output to the DAC by the 8051 microcontroller. Table 137 shows the angles, the sine values, the voltage magnitudes, and the integer values representing the voltage magnitude for each angle (with 30degree increments). To generate Table 137, we assumed the fullscale voltage of 10 V for DAC output (as designed in Figure 1318). Fullscale output of the DAC is achieved when all the data inputs of the DAC are high. Therefore, to achieve the fullscale 10 V output, we use the following equation.
V_{out} of DAC for various angles is calculated and shown in Table 137. See Example 135 for verification of the calculations.
Table 137: Angle vs. Voltage Magnitude for Sine Wave
Angle 9 (degrees) Sin 0 
V_{out} (Voltage Magnitude) Values Sent to DAC (decimal) 5 V + (5 V X sin 6) (Voltage Mag. X 25.6)

0 0 
5

128

30 0.5 
7.5

192

60 0.866 
9.33

238

90 1.0 
10

255

120 0.866 
9.33

238

150 0.5 
7.5

192

180 0 
5

128

210 0.5 
2.5

64

240 0.866 
0.669

17

270 1.0 
0

0

300 0.866 
0.669

17

330 0.5 
2.5

64

360 0 
5

128





Example 135
To find the value sent to the DAC for various angles, we simply multiply the V_{out} voltage by 25.60 because there are 256 steps and fullscale V_{out} is 10 volts. Therefore, 256 steps /10 V = 25.6 steps per volt. To further clarify this, look at the following code. This program sends the values to the DAC continuously (in an infinite loop) to produce a crude sine wave. See Figure 1319.
Figure 1319. Angle vs. Voltage Magnitude for Sine Wave