L. Padilla

Two years ago I was interested in having a sound digitizer-player, but the sound cards like SoundBlaster were somewhat expensive to buy one and use it only every now and then. Some time later I discovered an extremely simple design to play sound with an amazing quality (having into account its simplicity). It was a digital to analog converter (DAC) made with only a few resistors. It was used by several MOD players and a few games. The design was widely known since long time ago. Its working basis is the following.

We have a certain number of bits whose logic levels are characterized with electric levels, say logic zero = 0 volts and logic one = V volts. This bit set can be interpreted as a number comprised between zero and 2n - 1, and so it can represent the levels of an analog signal. The analog signal can be extracted directly from the digital signals if the electric levels of all of the bits are summed up with certain weights. The most significant bit is not weighted (that is, it has weight = 1), the bit next to it has a weight of 1/2, the following bit has a weight of 1/4 and so on. The least significant bit will have a weight of 1/2n - 1. This way the resulting output signal is analog (because it is not restricted to two values, 0 or V volts) and its level is proportional to the logic value represented by the bit set.

In the practice the DAC is applied to the parallel port of the PC. In this case we have 8 bits (but it could be more if we use not only the data pins, but also the control pins) whose electric levels are 0 volts (for logic zero) and approximately +5 volts (for logic one). The summing and weighting of the bits are made through resistors. The simplest way is to connect the pin of the bit number j with a resistor whose value is 2j x R. This would require 8 resistors, each twice the previous one, something which is difficult to achieve in practice. That's why a more elaborated circuit was designed. In the figure you can see that the DAC is made with a chain of resistors which only needs two different kinds of resistors. This makes the circuit stabler and easier to build in practice. The output signal will be approximately comprised between zero and +5 volts with 28 = 256 different levels, that is, the resolution of the DAC is 8 bits.

I decided to try the DAC and I got quite satisfied, but this was only half of the job. I also wanted to do the opposite operation, that is, I wanted an analog to digital converter (ADC). Then I started thinking about how I could digitalize sound in the same simple manner. My knowledge of electronics was rather poor (in fact it haven't become better), I only knew the basic principles of passives components and semiconductors. Finally I thought that the simpler design is to use the already built DAC as a reference voltage generator and to compare the input signal to be digitalized with it. A way to do it is to add the reference voltage to the input signal and see if a certain threshold is exceeded. If so, the signal is higher than the threshold level minus the reference and we must decrement the DAC output and compare again. If the threshold is not exceeded then the situation is the opposite and we must increment the DAC. When we find the two consecutive DAC values that make the threshold be unexceeded and exceeded respectively, we will have digitalized the input signal with a resolution equal to that of the DAC.

The main problem was in the design of a simple threshold detector. It has to be sensible to one step of the DAC, which is 5/256 = 20 mV. The conversion of a small step of voltage into a logic signal (for example, 5 volts if the step exceeded threshold and 0 volts otherwise) is typically done through a chain of transistors, so that they convert a step of 20 mV into a step of 5 V (gain = 5/20x10-3 = 250). As long as I wanted to keep the design as simple as possible I tried to use only one transistor, then the transistor has to be carefully chosen and polarized. My knowledge of transistors was not enough to do it this way, so I tried another approach.

The specifications of the logic levels say basically that there are 3 situations when an input signal is applied. If the signal is below some level, say 1 volt, it will be interpreted as a logic 0. If the signal is above a certain level, say 4 volts, it will be interpreted as a logic 1. If the signal is between both level then nothing can be said, the manufacturer of the equipment cannot predict the behavior, it will be randomly interpreted as a logic 0 or a logic 1. My bet was that the level in which the interpretation of the input signal changes from logic 0 to logic 1 is fixed and stable enough, though it will change randomly from computer to computer.

That is how I get to the design in the figure. Any electrical engineer will considerate this circuit as an aberration or some kind of electrical heresy or blaspheme, but believe me, it works! The overall principle is the following. The input signal to be digitalized is added to the DAC signal and applied to the base of a transistor. The collector of the transistor is connected to an input of the parallel port and the emitter to a variable resistor. The ends of the variable resistor are connected to ground and to a negative voltage source. I took the serial port as a source for this negative voltage, but any other source can be used. The serial port uses two electric levels, -12 and +12 volts approximately. There should not be risk of damage because the power consumption is low, besides, by definition of the RS-232C standard, any pin can be short-circuited with any other pin (including ground) without damage, otherwise your port is not a real RS-232C. When the signal in the base of the transistor grows, the voltage of the collector decreases, that's how the input of the parallel port is set from 1 to 0. The variable resistor has to be adjusted so that in absence of signal the digitalization results in the level 128 of 256. The volume control of the sound source (microphone, cassette, radio, CD, etc.) has to be adjusted so that the extreme levels (0 and 255) are almost never reached (to avoid saturation).

After the first trials I was surprised with the stability of the device. My bet was right. Once the variable resistor has been correctly set, the fluctuation is +/- 1 LSB, that is, like professional devices!

According to Nyquist's theorem, the maximum frequency that can be successfully digitalized is half of the sampling frequency. With my 386/40 MHz running a C program I scanned at a rate of 14 kHz. This sets the limit in 7 kHz, which is enough for human voice but not for hi-fi music. With a faster computer and programming directly in assembler the limit should be raised. To eliminate frequencies incorrectly digitalized, so they appear as noise, I added the low pass filter that can be found in the design. If your computer is faster than mine maybe you'll have to change the filter's constant to be optimum with your setup.

The digitalization process requires a lot of memory, at a sampling rate of 14 kHz, the data flow is 14 kb per second. As long as I don't know how to manage extended memory, my particular solution was to create a RAM disk and use it to store temporarily the data.

The design is very experimental and is intended to serve as an introduction to basic electronics, interfacing PCs with your own devices and its programming (you have to take into account that now really good sound cards have become quite cheap). I'm currently working on other devices so I don't plan to improve this design, but it can be done in many ways. Try it. The filter can be better, the extra source (for which I took the serial port) might be removed, the manual switch that changes from ADC mode to DAC mode can be substituted by an automatic switch (transistor, relay) controlled with the parallel port itself. Also the software is very naive, I didn't care about timing, so now one have to try several times to play the data at the right speed. More efficient code could be written to use extended memory, to make some sound enhancement, data compression, etc.

As a closing remark, it is interesting to notice that there are several sound cards which use the parallel port, like Disney Sound. They are basically a DAC as described here. Therefore it is very likely that you can play the example found in the preceding page with the software there, in any of these cards. Conversely it's also true, you may use the design of this page with any program that allows sound cards attached to the parallel port.


E-mail: padilla at domain "gae ucm es" (my PGP/GPG public key)
First version: 26-Nov-1996, last update: 12-Dec-2002
This link: http://www.gae.ucm.es/~padilla/extrawork/adc.html
Color line
Back Go to the parent page: Sound digitizer.