Вы находитесь на странице: 1из 4

Digital-to-Analog Conversion Using Resistor Ladders and Arduino Philip Zanotti March 30th, 2012

Executive Summary:
Often times it is desirable to generate an analog signal using a digital device such as a microcontroller. This application note explains how to build a simple 8-bit Digital-to-Analog converter using only 17 resistors and 1 port of an Arduino microcontroller. The resistor ladder acts as a series of current dividers that each receives high/low input from one pin of the microcontroller port, the most significant bit at the top of the ladder, and least significant bit at the bottom. Each bit, from most to least significant, has successively smaller influence on the output signal. The value, written to the port by the microcontroller firmware, is then reflected on the output of the resistor ladder.

Introduction:
Resistor Ladder digital to analog conversion (R-2R DAC) is a cheap and simple way to utilize a microcontroller as a digital-to-analog converter. The R-2R DAC is very easy to manufacture and incorporate into integrated circuits. R-2R DAC works on the principal of current dividers a generalized circuit diagram is pictured below:

Figure 1 - R-2R Schematic (http://en.wikipedia.org/wiki/Resistor_ladder)App

An-1 is the most significant bit of the digital value, and it is connected to the top of the ladder. The resolution of the conversion is determined by the following formula:

(a)

Vres = Vref x MIN/2n

For our application, we will be using an Arduino ATMega2650 board where Vout = 5 V and an 8-bit port. The resolution of our converter will be:

(b)

Vres = 5 x 1/28 = .02 (v)

Replace MIN with any digital value that will be outputted into the R-2R DAC ladder to compute the corresponding analog output voltage. The only major drawback to this design is the level of precision of the resistor values needed to create a highly accurate signal. Industrial applications generally require at minimum 1% tolerance resistors. Higher resolution converters will require increasingly more precise resistors. For this applications purposes, though, using resistors available in the lab is sufficient. The objective of this note is to construct and analyze an R-2R DAC with an Arduino microcontroller. It should be noted that an R-2R DAC can be created using any form of digital input.

Constructing and implementing an R-2R DAC:


Step 1) Part Selection Resistors must be selected to construct the schematic shown in Figure 1. For this application, R=1k was chosen.

Step 2) Circuit construction Assemble the circuit as shown in Figure 1. An-1 should be attached to the most significant bit of the chosen port, An-2 to the second most significant bit, and so on (Note: due to lab part availability, 2k resistance was created by placing two 1k resistors in series).

Figure 2 - Constructed R-2R circuit

Step 3a) Coding the Arduino (sine wave demonstration) There are many different ways to take advantage of the R-2R DAC as a software-controlled voltage source. The Arduino is capable of outputting 0-5(V) on its digital ports. The following example outputs a 10 Hz sine wave:
/* 10Hz Sine wave generator*/ float time; int value; void setup() { DDRK = 0xFF; } void loop() { time = millis()/50.0; //counts from beginning of program value = 128.0 + 128.0*sin(time*PI); //normalizes sine wave around 2.5 V PORTK = value; }

Figure 3 - Sinewave generator output

A low pass filter can be used at the output of the R-2R DAC to create a smoother signal and eliminate the brief drops shown in Figure 3.

Step 3b) Coding the Arduino (Software controlled voltage source) The R-2R DAC can be used as a software controlled voltage source. The following code uses a voltage dividers input on pin A0 of the Arduino and outputs the same voltage through the R-2R converter. The purpose of this application is to test this particular R-2R DACs accuracy.
/* ADC -DAC conversion*/ int value; int ADCpin = A0; void setup() { DDRK = 0xFF; pinMode(ADCpin, INPUT); } void loop() { value = analogRead(ADCpin); PORTK = value; }

From equation (a), we can calculate the accuracy of the converter.

Vout = Vref x MIN/2n


When Vref (measured by a digital multi-meter) is equal to 3.50 (V), Vout is equal to 4.13 (V). This equates to an error of 18%.

Suggestions and Recommendations


The 18% error calculated in the preceding example is quite large; however, the use of more precise resistors would greatly reduce the error. R2R DACs are capable of being accurate up to +/- 1 least significant bit, using IC resistors. Using a lookup table for sine values may improve speed as well, and increase the frequency range that can be generated by the DAC.

References
1) http://en.wikipedia.org/wiki/Resistor_ladder 2) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl

Вам также может понравиться