Engineering 72: Lab 6

D/A and A/D Converters

Aron Dobos, Tyler Strombom

24 October 2004

Building a D/A Converter Using the DAC0808 IC

The D/A converter circuit takes as input the lower 6 bits of data from port C of the PIC microcontroller board.  These 6 bits are mapped to the upper 6 bits of the DAC0808, with the two remaining LSB bits grounded.  As a result, the circuit will have reduced precision, and the raw input values will range from 0 to 63.  The maximum voltage achieved on the output will be as a result also be reduced by a factor of 252/255.

The DAC0808 IC produces an output current from which a proportional output voltage can be generated by correctly selecting resistor values.  The maximum output current Io on pin 4 is determined by the positive reference input current into pin 14.  Internally, a current mirror circuit allows the same current going into pin 14 to be “pulled” into pin 4 when all the bits are switched on.  Due to the 6 bit input precision, Io will maximally reach 252/255 * I14, but this is acceptable.  Based on these considerations, pin 14 was pulled up to a 5V reference through a 5.1k resistor, resulting in a reference current into pin 14 of 0.980 mA.  Io thus varies from 0 to 0.968 mA.

The opamp circuit transforms the output current to an output voltage.  The output pin of the DAC is virtually grounded by the opamp’s terminal characteristics.  Since no current can be pulled from the inverting terminal, all the current pulled into pin 4 must be through the feedback resistor.  Therefore, by choosing a feedback resistor of 5.1k, the full-scale output voltage seen on the opamp’s output terminal will be 4.94 V.  With all the bits switched off, no current flows, and clearly the output voltage will be 0.  The final circuit is reproduced below: Figure 1: Schematic of D/A converter

The circuit was verified by changing the port C value through the PIC web interface, and recording the output voltage.  The input ranged from 0 to 63 with an increment of 2.  The results are catalogued below:

 Input Vout Input Vout Input Vout Input Vout 0 0 18 1.4 36 2.8 54 4.19 2 0.15 20 1.55 38 2.95 56 4.35 4 0.31 22 1.71 40 3.1 58 4.5 6 0.46 24 1.86 42 3.26 60 4.66 8 0.62 26 2.01 44 3.41 62 4.81 10 0.77 28 2.17 46 3.57 63 4.89 12 0.93 30 2.33 48 3.73 14 1.08 32 2.49 50 3.88 16 1.24 34 2.64 52 4.04

Table 1: Digital Input and Output voltage for D/A Converter

The maximum output voltage achieved is 4.89 V, which is very close to the ideal maximum output voltage of 4.94 V.  The difference can be accounted for in the 5% resistor tolerances.  Plotting the data shows a clear linear ramp of the output voltage. Graph 1: Output Voltage versus Digital Input

The settling time of the DAC0808 was calculated by modifying the program on the PIC to alternate between two values.  The program modifications are listed below.

While (1)

{

delay_ms(1);

portc=20;

delay_ms(1);

portc=40;

}

The oscilloscope output clearly shows the transition period between the two voltages.  The voltage seems to have a 2nd order underdamped resonance instead of a linear ramp or 1st order response.  The settling time was measured with the cursors to be approximately 2.02 us for a transition from 1.55 volts to 3.10 volts.  This compares unfavorably with the settling time documented in the datasheet, which claims a settling time of 150 ns in the worst case when all the bits are switched on to within ±½ LSB.  However, the datasheet also mentions that board layout, short leads, 100 uF supply bypassing, and minimum scope lead lengths are mandatory for satisfactory settling time measurements.  None of these were taken into consideration in the lab, which could explain at least in part the much larger observed settling time. Graph 2: Oscilloscope Output for D/A converter

Building an A/D Converter Using a D/A Converter

The A/D converter works by ramping the D/A converter described above from 0 V to 4.89 V.  The output of the D/A is fed to a comparator that compares it against the test voltage.  The comparator output is read by the PIC microcontroller, and the ramp is stopped as soon as the D/A voltage is greater than the test voltage.  The output voltage of the D/A is thus approximately equal to the test voltage. The precision of this A/D conversion method depends on the granularity of the D/A ramp.

The LM311 was used with the non-inverting input connected to the D/A and the inverting terminal connected directly to the test voltage.  The comparator was powered by a +15 V supply, to ensure reliable comparisons.  Using a 5 V supply gave unstable results when the D/A output voltage (and the test voltage) neared 5 V.  The comparator output was pulled up to a +5 V reference through a 2.1k resistor to provide the standard 0-5V logic levels to be read by the PIC.  The comparator output was connected to input pin RB1 (pin 4 on the PIC board).  The schematic of the circuit is given below. Figure 2: Schematic of A/D converter

The following is the C Source Code for the ramping A/D converter

while (1)

{

portc=0;

for (i=0;i<64;i++)

{

if (input(pin_b1)==1)

{

break;

}

portc = i;

for (k=0;k<250;k++);

}

webIntOut(i, ov1);

delay_ms(33);

}

The algorithm initially sets the voltage at port c to zero. Pin b1 is the output of the comparator. If b1 is high, port c is equal to or greater than the test voltage. Using a “for” loop, the algorithm increments the voltage port c from 0 to 64 using the variable “i”. Before each increment, the algorithm checks if pin b1 is high, i.e. = = 1. If high, then the “for” loop breaks, port c stops incrementing, and the output on the web displays the input voltage (ov1) and the digital output “i.” The algorithm then waits 33 ms and then sets port c to zero again and repeats the process. This checks to see if the test voltage has been changed by the pot. If pin b1 is not high, port c increments by 1 and a “for” loop using the variable “k” is used to delay the next “i” loop in order to allow the D/A converter to stabilize.

The circuit was verified by incrementing the test voltage using the pot, recording the input voltage using the oscilloscope, and recording the digital output on the PIC web interface. The input voltage ranged from -.85 to 4.90 V. These are the lowest and highest voltages that could be set with the pot, respectively. The results are catalogued below:

 Vin Digital Output Vin Digital Output -.85 2 2.50 34 .62 11 2.95 41 .88 14 3.15 43 1.09 17 3.50 47 1.38 20 3.71 50 1.58 23 4.21 56 1.72 25 4.48 61 1.95 28 4.70 64 2.02 29 4.90 64 2.13 30

Table 2: Input Voltage and Digital Output for A/D Converter

The minimum digital output was 2. There was a fairly linear relationship with the input and output as the test voltage input was increased. The maximum digital output achieved is 64. There was a slight plateau after the input reached 4.70 volts. As stated before, the discrepancies can be attributed to the granularity of the D/A ramp. Plotting the data: Graph 3: Digital Output versus Analog Input Voltage

The following oscilloscope output displays the test voltage (pink line), the value of port c (turquoise line), and the value of pin b1 (dark blue line). The graph clearly shows how the voltage at port c increases until it is equal to the test voltage. Pin b1 then switches to high and the voltage at port c stops incrementing. Graph 4: Oscilloscope Output for A/D converter

Using the PIC’s A/D Converter

The circuit was verified by incrementing the test voltage using the pot, recording the input voltage using the oscilloscope, and recording the digital output on the PIC web interface.  The input voltage ranged from -.180 to 4.78 volts. These are the lowest and highest voltages that could be set with the pot, respectively. The results are catalogued below:

 Vin Digital Output Vin Digital Output -.180 0 3.01 661 .501 139 3.52 767 1.03 248 4.03 870 1.53 352 4.50 966 2.02 455 4.78 1023 2.52 556

Table 2: Input Voltage and Digital Output for A/D Converter

The minimum digital output was 0. There was a linear relationship between the input and output as the test voltage input was increased. The maximum digital output achieved is 1023. The values ranged from zero to 1023 because this converter uses 10 bits instead of 6 bits. Plotting the data: Graph 5: Digital Output versus Analog Input Voltage