| R/2R Networks | |||
|
ADCs and DACs R/2R Networks How R/2R Networks work: Construction and Testing Adjusting the Output Miscellaneous Notes ADCs and DACs: When working with digital electronics, microcontrollers specifically, there is often a need to sample analog signals for digital processing or create analog signals from digital processing. This is the job of Analog to Digital Converters, called ADCs for short, and Digital to Analog Converters, abbreviated DACs. (R/2R networks deal only with the latter) The resolution with which an ADC or DAC is able to do the job is often measured in bits. A 4 bit DAC giving a 0-5V output could only deliver 16 (binary 0000 to 1111, decimal 0 to 15) different voltage levels between 0V and 5V, not enough in most cases. More common figures are 8 bit (256 steps) or 10 bit (1024 steps). Do not confuse resolution with accuracy, which is how close to the expected result the ADC or DAC can deliver. So.... ![]() This is an industry standard 8 bit DAC. ![]() This is how you are meant to use it. Confused? Fear not, there is another way.... R/2R Networks: When a high level of accuracy is required over a wide temperature range, single chip DACs may be the best option. But for the average hobbyist with the average funding, R/2R networks are a cheaper, easier and more versatile approach. My own experiment with R/2R DACs shown below reveals that they can also have a remarkable level of linear accuracy. An 8 bit R/2R network is pictured below. The actual values used for the resistors does not matter, the relationship between them does. Put simply, pick a value for all the resistors labeled "R", and all the others labeled "2R" must be twice that value.
I have used the values R = 10KΩ and 2R = 20KΩ, though the 20K resistors were harder to find in 1% tolerance. (Using larger tolerances is a bad idea) Smaller values, under 1KΩ, will probably draw enough current across the network to affect the output voltage. Higher values, over 1MΩ, may cause problems with noise if the analog output is fed into an op-amp. (as is often the case) How R/2R Networks work: The magic behind the R/2R network is actually quite simple. Each digital input sees the network as a voltage divider, delivering it's binary weighting to the output. If the most significant bit (MSB) is raised, half of the voltage applied to this input appears on the output. The next bit down will push a quarter of the logic voltage to the output, and so on.... A simple formula can be used to represent this: ![]() Where Dx is the data bit (0 or 1) and VLOGIC is the logic high voltage applied to the inputs. This equation can be expanded, (or compacted) as can the network itself to give different resolutions. 8 bit resolution is usually enough when using 5V logic levels, giving slightly less than 0.02V per step. Moving on.... Construction and Testing: After constructing an R/2R network it's usually a good idea to test it over the entire output range, as might be done at the factory for DAC IC's. In the case of my own experiment, the DAC was constructed over PORTB of a Microchip PIC16F628 MCU as illustrated below. This construction is reasonably compact for a prototype PCB, and certainly takes less space than a DAC IC and it's support components. The test was done by programming the PIC16F628 to put a certain byte value on PORTB, and therefore the R/2R network. The analog result of this byte value was then measured using a cheap digital multimeter, and the results graphed. Rather than programming the PIC16F628 256 times, measurements were only made for every five possible values, resulting in just over 50 readings. Here's what it looked like:
The green line represents perfect conversion, (not possible by any means) and the red line represents the measurements taken and is only visible when in error. The orange line (scale on the right hand y-axis) is the linear error, which is the difference between the ideal and the actual outputs expressed as a percentage of 5V. As you can see linear response and accuracy are pretty good, especially when compared to the DAC0800 pictured at the start of this article. The DAC0800 offers 0.1% non-linearity and this R/2R DAC can achieve about 0.18% minimum non-linearity. (please note that the testing methods and calculations carried out by myself are unlikely to be the same, or even similar to those done for the DAC0800) Adjusting the Output: Depending on your application, you may need to buffer and/or adjust the output range with an opamp. For buffering only, use an single opamp with the inverting (-) input tied directly to the output. (this configuration is often called a voltage follower) Otherwise, the output range can be adjusted to anything within the power supply. (Yes, this includes negative voltages) In theory, to achieve -5V to +5V output a standard opamp (like the 741 or TL071/TL081) would need dual power supplies of at least ±5.5V, be setup for a gain of exactly 2 (this doubles the step size to just under 0.04V) and have the inverting (-) input set to exactly 2.5V while connecting the non-inverting (+) input to the DAC output. I have not done any of this with my R/2R network, and I won't go into detail on opamp usage in this article. Miscellaneous Notes: Before throwing an IC DAC out the window (or perhaps just back in the junk box) in favour of a R/2R network, a few things should be noted.
If the above points don't affect your application, then R/2R networks may be the best way to go. If you have any comments or questions please don't hesitate to contact me. |
|||
| Return To Top | Last Updated: 27/03/2007 | Home Page | |