Digital to Analog

Following the last lab, you've probably wondered how we can take signals from a digital device and translate them into something that an analog circuit can use. When would you want this? Well, it turns out that playing 1s and 0s from a speaker doesn't sound so good. Motors, electromagnets, and lights are also typically things you want to have more fine control of than just turning on or off.

PWM

We'll start with the simplest option: Not actually converting to analog. How can this work? For things that care about the average of an input over time! If you toggle an LED between on and off quickly enough (a few hundred times a second), it just looks like it is on but dimmer. Some motors also can sometimes be controlled this way, as they'll keep spinning due to inertia when the power is off. And if we vary the relative amount of time an output is on or off, we get even finer control. This technique is know as Pulse Width Modulation or PWM.

We'll start here with a pair of humble LED circuits, shown below:

  • Use your power supply to set an analog voltage between 3 and 5V for your first circuit.
  • Set up a 0-5V square wave with our function generator.
  • Scroll down in the function generator options until you get to the duty option

Adjust the duty percentage until the two LEDs are roughly the same brightness. Check if the product of 5V * the duty cycle (as a percent) reasonably match your power supply's output.

While this works for a surprising number of situations, there are some limitations. One is that you'll always be rapidly switching voltages, which can cause unwanted oscillations elsewhere in a larger design. Some devices also don't appreciate being switched on and off quickly, and will let you know by dying. As a practical limit many microcontrollers can only output a few mA of current; transistors are your friend in such instances.

R-2R ladder

Okay, maybe you need to have something that does better than being the same voltage on average. One way of doing this is essentially the inverse of the successive approximation method we used last week. Consider the circuit below:

Each of our digital inputs can take on values of either 0V or 5V. So, how do we analyze this? The answer is that we treat it like a series of voltage dividers. If all of the inputs are off, there's not going to be current anywhere, so $V_{out} = 0V$. Let's separate the last part of the circuit and analyze it via Thevenin's theorem.

The equivalent series resistance is 2R and 2R in parallel, which is just R. The series equivalent voltage is $V_{D0}/2$, where $V_{D0}$ is either 0V or 5V.

Let's use this info to redraw an equivalent circuit:

From here, we can immediately combine the two resistors in series to an equivalent of 2R. Then, we have another voltage divider circuit. This one is a 50/50 split between $V_{D0}/2$ and $V_{D1}$. Our four possible outputs for the four different combinations of D0 and D1 are 0V, 1.25V, 2.5V, and 3.75V. If you want more precision, add more stages. Each new input improves the resolution by a factor of 2.

You probably didn't notice it at the time, but the UChicago Black Box™ that we used in the first lab? That used an 8-bit version of this circuit.

The conversion circuit used in our mystery function generator. Note that we explicitly are using only one value of resistor, but place two in parallel to achieve half the resistance value. Why? It looks neat, and it makes it so that you don't have to worry about what resistors go where if they're all the same.

Dedicated DAC chips

We'll be using a TLC7528C chip for our digital to analog conversion today. It uses this same R-2R topology to do its conversion. This chip was chosen in part because it has eight parallel inputs, making it so we once again don't need to worry about encoding a sequence of values in time. Let's take a look at the chip's pins now:

The relevant groups of pins are as follows:

Outputs

Pins 2 and 20 serve as a pair of outputs that can be toggled, letting you use one set of controls to update a pair of outputs. This is why there are OUTA and OUTB connections. This particular chip is designed for the outputs to be analog currents, but we'll use a different mode

Grounds

Pins 1 and 5 are listed as AGND and DGND respectively. While there is some subtlety to the need for different grounds for analog and digital parts of a circuit, that is a problem for another course entirely thankfully.

Feedback

Pins 3 and 19 are for feedback resistors (Resistor FeedBack A/RFBA and RFBB) used for tweaking the behavior of the R-2R ladder.

References

Pins 4 and 18 are reference voltages, which in our case will be the outputs we're using for the device.

Controls

Pins 6, 15, and 16 are used to select different behaviors of the chip. 6 toggles which output is being updated. 15 is the Chip Select (CS) pin, used to communicate that the chip should be ready to capture a new set of inputs. 16 is the WRite pin, used to start the conversion of the current digital inputs to analog.

Digital Inputs

Pins 7 through 14 are the digital inputs, from most to least significant bit respectively. The most significant bit is the one with the greatest impact (i.e. toggling it will increase the output by half of its total range) whereas the least significant bit will only increase the output by a factor of $\frac{1}{2^8}$ of the range.

Power

Last but not least, pin 17 is used for powering the chip