## Friday, April 11, 2008

### Computer Dashboard, part 4 - D/A Conversion 2

Back to Part 3

Gee, this is getting a little epic. Keath, I'm glad you're enjoying it. Or at least reading it. So. We have a meter to swing, and a number of pins, each of which can output a set voltage. What we need to do is some binary math. For my purposes, I decided that my meters were small enough that setting them to one of 32 values was going to be enough precision. That meant I needed 5 pins to dedicate to a meter, because 2 to the 5th is 32. Got it?

No? Well, binary numbers represent numbers with just 2 values, 0 and 1. Just like in decimal numbers we have the "ones place" and the "tens place" and the "hundreds place", ie, 124 has 1 in the hundreds, 2 in the tens and 4 in the ones, binary numbers have the 1's place, the 2's place, the 4's place, the 8's place, and the 16's place, etc. So, if you are using 5 pins, you can count from 0 to 31, because 16 + 8 + 4 + 2 + 1 = 31. That gives me 32 values, so for instance, the number 10011 is 16 + 2 + 1 = 19. (n-n-n-nineteen).

Got it? Well, go google it or something. The point, is we need some way of making pin 5 "count" more than pin 1. When pin 1 changes, we only want the meter to move by 1 unit. When pin 5 changes, we want the meter to move by 16 units. The way to do this is with a resistor ladder. As shown in the picture, each of the 5 pins will connect to the network from the bottom, and there is one output, to the meter. Pin 1 will be connected furthest from the output (marked LSB on the diagram), so as the voltage from that pin makes its way across all of those resistors, it will be dropped until it contributes very little to the total at the end. Pin 5 will be connected nearest to the output (marked MSB on the diagram), so the voltage from Pin 5 only has 1 resistor in its path to the output, and will thus influence the voltage, or current, at the end, much more. (Resistors drop voltage, by the way).

That's it - that's how simple a digital-analog converter can be - a bunch of resistors. Going the other way - not so easy.

Keath said...

Are all your resistors the same, uh, resistance, or do they vary? I'd assume that they need to vary so as to ensure that each input is reduced the correct amount, but they're all labeled R and 2R, so does the number of resistors the signal passes through automagically arrive at the correctly proportioned voltage? Does R/2R indicate that the initial voltage is reduced by twice as much as the resistance between steps and that how much it is reduced depends only on the amount of signal the meter is expecting? Do I make any sense?

Iestyn Lewis said...

You sort of make sense. David Byrne urges you to stop. The description is somewhat simplified, due to space considerations, and to the fact that my understanding has grown fuzzy since doing this project. The resistors are all indeed either R or 2R, I think in my case they are 100K and 200K resistors.

Each of the junctions functions as a voltage divider. Current always wants to find the easiest path from source to ground. In the diagram, there are 2 ways for the current from each input to get to ground - either by going through the Load at upper left or directly to Ground at upper right.

So in the case of the MSB, on the left, there's a whole world of pain in the form of resistors in between that junction and the ground on the right. Much easier just to go through the load (the meter), and thereby change the reading on the meter by a lot.

In the case of the LSB on the right, the current sees a whole lot of pain to the left, and would much rather just go to ground. But a little tiny bit makes it through to the meter, and changes it by a little.

In between, you get varying percentages of current divided between ground and the meter.

All can be determined by Ohm's law, V = I*R. But the tricky part is always deciding which one of those remains constant, so you can figure out the other 2.