Program turns PC sound card into a function generator
You can use a low-cost PC sound card as an analog-function generator by controlling the PC with the program "SoundArb." [To obtain SoundArb, download di2409setup.exe, a 1.06-Mbyte self-extracting installation program.]
The program generates standard waveforms, noise, and arbitrary waveforms. The program reads arbitrary waveforms from simple ASCII text files consisting of white-space-separated numbers. You can use a program such as Mathcad to create such files. SoundArb provides common triggering modes, such as continuous, one-shot, burst, and toggled. An on-screen "button" serves as the trigger input. The program's user interface is a dialogue-box-style control-panel window.
The main advantages of using a sound card as a standard and arbitrary waveform generator is its low cost and ready availability. The typical 16-bit resolution is better than many arbitrary- waveform generators, the output drive capability is generally good, and you can't beat the price: as low as $10.
The disadvantages include poor waveform quality, including distortion, noise, and ringing; ac-coupled output only; limited triggering modes, including no external trigger; imprecise amplitude adjustment; and the possibility of interruptions in the waveform due to other system demands. All in all, the quality of the generated waveforms depends directly on the quality of the sound card, and the cheapest cards generate the worst waveforms. An oscilloscope photo (Figure 1) shows a 1-kHz triangle wave such as those generated by cheap sound cards. The photo shows rounding of the points of the triangle wave due to limited high-frequency bandwidth.
SoundArb is a 32-bit application that runs under 32-bit Windows. The program communicates with the sound card through the Windows multimedia application-programming interface, so it should work with most sound cards. SoundArb places relatively light demands on the system, so a fast CPU and large amounts of memory are usually unnecessary. Long arbitrary waveforms may require more memory. Low-cost sound cards rely on the computer's main memory for waveform storage, which means that, if the system is slow or busy, the waveform may be interrupted. The sound card must support the pulse-code-modulation, audio-wave format; must have 16 bits of resolution; and must have a maximum sample rate of at least 44.1 kHz. Although standard sample rates are 10.25, 20.5, and 44.1 kHz, many sound cards support any integer sample rate within a much wider range. Such a card is a more versatile function generator than one that supports only the standard sample rates.
The resolution and full-scale range of the amplitude adjustment depend on the design of the sound card. Unfortunately, no way exists to set the amplitude to a known voltage other than by observing the waveform on an oscilloscope. Many sound cards have relatively few amplitude levels, and these levels do not necessarily follow either linear or logarithmic curves. One card tested provided 16 amplitude steps, including "zero." The remaining 15 steps followed a two-part piecewise-logarithmic curve.
If you have a stereo sound card, SoundArb allows you to use the "right" channel as a "sync" output to mark the start of the analog waveform. Note that a sound card reproduces only audio frequencies. Most provide no dc-coupled output. The output bandwidth typically approximates the 20 Hz to 20 kHz audio band. A good first test of your sound card is to generate square waves of various frequencies and lengths while monitoring the output with an oscilloscope. Low-frequency square waves may show a pronounced droop due to an ac-coupled output, and ringing on the edges may be severe. The amplitude and frequency of the ringing may depend more on the sample rate than on the waveform repetition rate. Much of this depends upon the analog-to-digital-conversion technique that the sound card uses. Take the time to familiarize yourself with the analog limitations of your sound card before relying upon it for important work. For more information on this, search the online help index for the keyword "Distortion."
To use the sound card for electronic testing, you probably need to make an adapter cable (Figure 2). A convenient way to make the cable is to obtain two male BNC-to-cable connectors, a stereo miniphone plug, and a short shielded wire. Because of the low frequencies involved, you need no coaxial cable. You then connect your normal BNC-to-clip-lead test cables to the male BNCs. Alternatively, you can make a longer cable by terminating the right channel in a female BNC, which you can connect to the sync input of your oscilloscope. You can terminate the left channel in an alligator clip or a minigrabber. If you don't use the right-channel sync output, you can get by with one BNC and one piece of cable because the program supports only "right-channel-sync" mode. The tip of the miniphone plug carries the left-channel signal, the first ring carries the right-channel signal, and the main ring provides the ground. Separate shielded cables, rather than a shielded twisted pair, between each BNC and the phone plug are recommended because with the twisted pair the sync pulse edges capacitively couple into the waveform and cause glitches. As an alternative to using a miniphone plug, most sound cards have an internal waveform output comprising a pin header on the card. Some cards also have jumpers that you can use to select between "line out" and "speaker out," the difference being the output impedance or voltage.
Grounding may be less than optimum because no good way exists to connect the PC's ground to the ground of the device under test. If glitches from the sync line are a problem, you may be able to disconnect that line's shield from its BNC shell, assuming that the waveform line's shield remains connected to its BNC's shell. If necessary, you can break a bad ground loop by isolating, or floating, the PC and its monitor from the power-line ground. You cannot use a "cheater" plug because it defeats the safety aspects of grounding and can allow the PC chassis and peripherals to become hot. To isolate the PC from the power line and its ground, use a medical-grade isolation transformer that includes a Faraday shield between the primary and secondary windings. This transformer often reduces interference from noisy power lines and may reduce conducted EMI, especially if used with an RF-line-filter block.
Never float the PC or any other test equipment as a way to connect the ground to a high voltage, for example, to connect an oscilloscope probe across a current-sensing resistor in a hot ac power line. Doing so could kill you, and you could destroy expensive test equipment whose power supply was not designed for a ground-to-neutral voltage of more than 30V. If you need to connect test equipment to a high voltage, use optical or magnetic isolation in the signal wires, not in the equipment's power supply. Small, modular isolation amplifiers with low distortion are readily available at reasonable prices. (DI #2409)