2011 June 15

Digital-to-analog converter

Filed under: Digital music,Digital-to-analog conversion — gasstationwithoutpumps @ 01:30

One of the first concerns for producing musical sounds from a computer is converting the stream of numbers computed by the algorithm into a stream of voltages uniformly spaced in time. The uniform timing is the responsibility of the computer (in my case, an Arduino board), and I’ll cover that in a later post, but the conversion to voltages is best done with a digital-to-analog converter (DAC). (One can also try using the pulse-width modulation of the Arduino’s digital pins—I’ll cover that in a later post also.)

When I first built hardware for digital sound, DACs were expensive parts. My first board used a DAC0801LCN, an 8-bit DAC that is (amazingly) still available. It came in a 16-pin DIP and needed a fairly large power-supply voltage (±4.5v to ±18v).  It also uses up a lot of output pins on the Arduino (each of the 8-bits is a separate pin).

Old DAC circuitry on a vector board.

The DIP packaging was pretty nice, though, as I could use wirewrap sockets and wire the board without much trouble. (I can’t find my old hobbywrap wirewrap tool, and wire wrapping seems to have gone out of style with hobbyists—too bad as it was a very cheap, low-tech way to connect circuits, with less trouble than soldering and more robustness than breadboards.)

Here is the back of my old DAC board, showing some wire-wrapped and some soldered connections.

For my Arduino, I wanted a DAC that I could plug into the Arduino board directly, without ribbon cables or other complications, and that would not use up many of the I/O pins on the Arduino.
Modern DACs are mostly serial-interface devices, to cut down on pin count, so the resolution of the DAC is no longer tied to the number of pins used to interface to it. Since DACs have gotten dirt cheap in the past 30 years, I figured I’d go with a 12-bit DAC instead of an 8-bit one. This may have been a foolish choice, as a 16-bit DAC would not have cost much more and might have simplified the interface software (12 bits are not aligned to 8-bit words).

I ended up choosing a Texas Instruments part (TLV5618A) which has 2 12-bit DACs in an 8-pin DIP. Three pins are used for the serial digital interface, two for the analog outputs, two for power, and one for an analog reference input.  TI recommends a 2.048 voltage reference when using a 5v power supply, probably to make the voltage steps be a uniform 1mV.

The pinout for the TLV5618 DAC. Pins 4 and 7 are the outputs, Pins 5 and 8 are the power supply, Pin 6 is a reference voltage input, and pins 1,2, and 3 are the digital inputs.

If I’d been thinking clearly, I would have simply hooked the reference pin up to the 3.3v power supply on the Arduino (the data sheet says that the reference could be as high as Vdd-1.5v, which would be 3.5v), but instead I used a pair of resistors (a 22kΩ and a 15kΩ) to make a voltage divider that produces about 2.03 volts. I also put a capacitor between the reference pin and ground, so that it wouldn’t be too sensitive to noise on the power supply. Someone who cared more than me would probably use a zener diode to set the reference voltage more precisely with less noise, but I had resistors and capacitors on hand and would have had to wait several days to buy a zener diode. (It would also irk me to pay more for shipping than for the 40¢ part.)

Here is the schematic from my lab notebook. I realize that the capacitor does not have a size in the schematic—in fact I don't know much about the capacitor I used. I got a whole bunch of them in a grab bag at some point, and the labeling on them doesn't tell me much. They are labeled 564J100, which probably means 560nF ±5% and a 100volt rating (see the Wikipedia article on capacitor marking). I suppose I should try measuring the capacitance to confirm that assumption. I should also learn to use a free schematic capture program, so that people won't have to see the mess from my lab notebook.

The outputs are connected (via 2.2kΩ series resistors) to a headphone jack.  The DACs are capable of powering a small headphone (like an earbud), or you can use powered computer speakers or a headphone amplifier.  The series resistors are to keep from accidentally shorting out the DACs.

I built my digital-to-analog converter on the prototyping shield sold by ladyada.

I soldered up the board (including a socket for the DAC). One of the things I don’t like about the Ladyada prototyping shield is that the only access to the Arduino pins is through a set of female headers. I’m thinking of removing the both those headers and the male ones that connect to the Arduino on the bottom, and using long-tail female headers to both connect to the Arduino board and provide the ability to stack on top of the protoboard.  That would free up the holes where the female connectors are now to solder wires to. Ladyada sells the connectors as shield stacking connectors for Arduino, so I’m a little annoyed that they didn’t design them into the prototyping shield in the first place.  It would be a trivial change to their design, not even requiring a new PC board—just different header pieces and new instructions.

Prototyping board with a digital to analog converter

Finished prototyping board with a digital to analog converter

In a later post I’ll talk about how to communicate with the DAC over the serial link.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: