Professional Documents
Culture Documents
Practical Dacs: Food Living Outside Play Technology Workshop
Practical Dacs: Food Living Outside Play Technology Workshop
Practical DACs
by nevdull on April 8, 2013
Table of Contents
Practical DACs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DAC Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Primary Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 4: Build It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
BOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Solder Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Step 5: Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
http://www.instructables.com/id/Practical-DACs/
Author:nevdull The Bold Scientist
Gian is the Managing Director t at Open Design Strategies and holds a BA in Molecular/Cellular Biology and an MS in Computer Science. He has a collection
of 8-bit microcontrollers and a room full of computer junk that he believes talks to him. He is a sympathizer with the Robot Overlords and is adroitly
maneuvering himself to be in a comfortable position when the AVR global domination begins. He is also scared of zombies.
This instructable is part of my "Practical" series of DIY guides. You may also like Practical Power Supplies, Practical OpAmps, Practical Voltage Dividers, Practical
Electronic Formulas, or any of my other instructables. I will link them all together when I have completed the practical series of DIY guides.
Keeping with the format of the "Practical" series, each section is prefaced with an "At a Glance"-style bulleted objective list that helps set expectations and prepare the
reader for that part of the instructable. I've tried to write in a clear, concise, and easily accessible manner while handling sometimes complex or complicated subject
matter. The end of each series is capped off with a "final remarks/conclusion" section sometimes with ideas for further research but always with ways you may contact
me if you have questions or comments about my instructable. I am always open to hear your thoughts on improving this or any of my Instructables.
Now, let's get started learning how to interface the digital world to the analog world!
DAC Basics
Here you will learn or refresh your memory on DAC basics.
Digital values are discrete, stepped values that have clear boundaries delineating them from other digital values. For instance, the values 1 and 2 are discrete values
(although they could also be analog ones, but more on this later) which means that there are no values in between the value 1 and the value 2. They can be thought of as
bins similar to FFT. Look at the figure below to see how discrete values are used in a histogram. Note the analog line that bounds the histogram frequencies.
Some examples of digital values might be age (assuming year boundaries), eye color, school grade, or categorical height (ie short, medium, tall vs. 5'9" or 6'2").
Analog values are continuous, on a line and include all the intermediate values between any two sample points. Notice on the histogram below that the analog line is
smooth while the digital line is boxy. Some examples of continuous values includes voltage and height.
A DAC is a device that takes digital values, often in binary, and converts that number into an equivalent analog value. For example, the RGB value in VGA monitors
expects an analog value from around 0 to 1V for each color channel, but most GPUs and graphic cards operate on digital values (ie binary bits), so the video RAMDAC
converts from a binary pixel representation, say, 01100011 to a voltage that represents that value to the VGA monitor.
Another common use of a DAC in electronics and microcontrollers is when you want to take stored digital samples and convert that to an equivalent sine wave. This can
http://www.instructables.com/id/Practical-DACs/
often be useful for showing things like AC voltage or current over time in a meaningful way.
Most DAC ICs are multiplying DACs, meaning the DAC produces an output signal that is proportional to the product of a varying input reference level multiplied times the
digital input code. Some DACs have a fixed internal reference input that is used to set the analog output range while others support external analog input. DACs are
capable of producing unipolar output, that is, a single-polarity analog signal or bipolar (positive and negative values). Many unipolar DACs take binary code as its digital
input with bipolar DACs taking either a binary offset or a two's compliment value.
Primary Characteristics
When choosing or building a DAC you should look for a couple of primary characeristics of the DAC to get an idea of how the DAC will perform in your environment (or
what you have to do if you're building one by hand). The first step is to determine the resolution. This is easy. Resolution, σ, is the number of bits in the digital input. If
your DAC has four binary inputs, then the DAC resolution would be 4bits. Second, work out your maximum output voltage by calculating 2σ • LSB where LSB is the least
significant bits.
The next parameter to look at is probably the biggest and most important. It is called integral nonlinearity, or INL for short. The INL of a DAC describes its deviation
between the ideal output and the actual output. That is, the deviation of the DAC's transfer frunction from a straight line, typically measured at each analog step. The
straight line can be approximated to the actual transfer function. Two most common types of lines are called best fit line and the endpoint line. In any case, the INL is the
maximum distance between the ideal line and the actual transfer function. Low-to-mid range DACs may specify an INL upwards of 16 while the quite good ones (and
inherently more expensive) can offer an INL of around 1. INL is formally specified like this:
Further, to determine the slope of the line through the end points, you can use:
The offset error is the output voltage when the digital input is zero and remains constant for all input values. The offset error can often be mitigated by fine tuning the DAC
circuit. Gain error is the difference between the ideal maximum output voltage and the actual maximum value of the transfer function after subtracting the offset error.
Gain error changes the slope of the function.
For the most part, the characteristics of a DAC are defined by its reference voltage. The DAC's reference voltage, V ref , sets the DAC's maximum output voltage and also
defines the voltage step by which the output changes in response to a 1LSB transition at the input. Simply put, one step equals Vref /2N .
http://www.instructables.com/id/Practical-DACs/
Step 2: Binary Weighted DAC
To better understand how DACs do what they do, we'll investigate a simple way to produce analog values from digital input.
Objectives at a Glance...
Here, the values of resistors are R, R/2, R/4, and R/8 where R = 10K ohm and R 3 = 10K ohm. The equivalent circuit of the op amp generates V out = -Vin (R3 /Rin ) = -
5V(10K/Rin ) with a 5V input. To find all possible values of Rin we can use the standard "resistors in parallel" formula of:
Here the A through D act as a binary coefficient modifying the resistor in the appropriate binary place. To find the analog output voltage, you simply use the formula I
already included above:
Assuming Vin of 5V and R3 of 10K, we come up with the table included below.
This binary-weighted DAC is limited to 4-bit input generating 16 analog output steps. To double the resolution, you might think to add in four more resistors at 1/16R,
1/32R, 1/64R, and 1/128R and you would be correct...but only partially. This is where implementation falls short of theory. The problem with this approach is that when
you get to the 1/128R resistor, you would have to find a 78.125 ohm resistor and even if you found one, or built one up from separate resistors, you would still be plagued
with the resistor's tolerance level. A 10% tolerance means the actual value of the 78.125 ohm resistor may fluctuate within +/- 10%. You can do better with a 1%
tolerance resistor but how do you get out to 3 significant figures of resolution?
This weighted binary/scaled approach fails us when we need more than just a few bits of resolution. What are we to do? Junk this design and turn the page!
http://www.instructables.com/id/Practical-DACs/
Step 3: R/2R DAC
Objectives at a Glance...
As expected, here are the relevant or important formulas when working with this type of DAC.
I = Vref /R
Vout = -Isum * Rf
Where Vref is 5V, S0 through S3 are the switches in the illustration with S3 on top and S0 on bottom. Isum is the sum of the currents entering the inverting input of the op
amp and Rf is the feedback resistor of the summing amplifier.
First, you must realize that the current drawn through any one switch is always the same regardless of whether it is connected to GND or Vref . If the switch is connected
to GND, then Isum will flow to GND but if the switch is thrown up, then Isum will enter the inverting input of the op amp as the op amp creates a virtual ground at it's
inverting input (remember that setting an op amp's non-inverting input to GND will make the inverting input = 0V via negative feedback...if you need a refresher please
check out my Practical Operation Amplifiers DIY guide).
When you understand that the current flowing through any one switch is always constant, it makes solving for the variables of the equations much easier as the total
current I supplied by Vref will be constant, as well. Once you've grok'd that, you can figure out what fractions of the total current passes through each of the branches
within the R/2R network using some simple circuit analysis.
It is key to understand how the resistance (and hence, current) is calculated and can be done by performing a simple circuit reduction. Please refer to my Practical
Voltage Dividers for details on how this is done. Once you have done this, you will have a consistent means to generate fractions of 1/2I, 1/4I, 1/8I, and 1/16I which get
summed together by the op amp. For example, if switches S3 , S2 , and S1 (1101) are thrown, we get 1/2I, 1/4I, and 1/16I current combining in Isum . To derive I itself, we
can simply use Ohm's law of V = IR or, solving for I, I = V/R. So, assuming Vref of 5V , R of 10K ohm, and Rf of 20K we get I = 5V/10K = 500 uA. Using this, Isum =
1/2(500uA) + 1/4(500uA) + 1/16(500uA) = 406.25 uA. The final output voltage, V out is then Vout = -Isum *Rf = -500uA * 20K = -8.125V for a digital input value of 1101.
To create an R/2R DAC with higher resolution you only have to add more voltage dividers and take some care when selecting your resistors.
Now you're ready to put what you've learned to use and build an R/2R DAC. Turn the page and let's go!
http://www.instructables.com/id/Practical-DACs/
Step 4: Build It
Objectives at a Glance...
Fire up the soldering iron, locate your multimeter, and steel yourself for some rough SMD on SMD action. The R/2R DAC you will be building has a few new features that
I didn't cover in the previous sections. Some new functionality was added to enable it to be used on pin-constrained AVRs like the ATtiny series while the choice of an
inverting op amp was based on price, availability, and input impedance.
To make things a little easier, I've included a Bill of Material (BOM) below so you can get organized and setup your mis en place workbench.
BOM
Part Value Device Package Description
http://www.instructables.com/id/Practical-DACs/
R7 20K R-US_R0805 R0805 RESISTOR, American symbol
Notice that this R/2R DAC sports a resolution of 12 bits, which is 212 possible binary input code values. Recall from the theory discussion previously that the higher
resolution the DAC, the smaller the analog steps between each output value, which means the device reading the analog output should be able to sample and convert
with at least that much precision.
You will also notice that instead of those clunky manual switches I used in previous demonstrations, this DAC takes a serial input into two chained serial-in/parallel-out
shift registers. This keeps us from having to supply 12 dedicated I/O pins for the digital code inputs. The op amp at the end is of the JFET variety so it gives us a high
input impedance. If you need to know why this is important, please refer to my practical operational amplifiers DIY guide.
This board breaks out six signals consisting of SIGNAL_IN[DIGITAL], CLOCK/STROBE, !RESET, SIGNAL_OUT[ANALOG] and two power signals: VCC and GND. A
brief definition of what each signal is meant for follows.
SIGNAL_IN
This signal is the digital serial-data input into the shift registers of the DAC.
CLOCK
For every shift down of values, you strobe the CLOCK line and the shift registers will shift all values down one flip-flop location.
!RESET
This is an active LOW signal that resets the shift registers to zero values.
SIGNAL_OUT
This is the analog signal from the conversion process and transfer function based on the inputs.
I inserted all ICs into their own sockets, but don't feel you have to do this. I just did it so I could pull out the ICs and use them again later. If you prefer, just socket them
straight onto the PCB. Also, I ran all the signal and power traces out to a pretty non-standard PTH footprint. I'm not sure why I did this, but in the newest revision of the
schematic and board file, I ran the traces out to a header. So, if you see a discrepancy between the images here and the schematic, that's why.
Experiment and Play
http://www.instructables.com/id/Practical-DACs/
Now that you have finished building your R/2R DAC it's time to put it to some use and analyze its accuracy. If you're using a multimeter to read the analog output value
then it's probably easiest to do this by having your microcontroller change the digital input but very slowly so the analog signal gets some settling time to be read by your
multimeter.
http://www.instructables.com/id/Practical-DACs/
File Downloads
Related Instructables
http://www.instructables.com/id/Practical-DACs/
Advertisements
http://www.instructables.com/id/Practical-DACs/