DAC stands for Digital to Analog Converter. This article explores the code created by Michael Smith for a PWM-based DAC. The code has been modified to allow for the testing of various DAC options. A comparison is made between the 8-Bit PWM DAC and the R2R DAC at different bit resolutions, revealing that a 4-bit DAC can produce surprisingly good sound quality. The article includes several sound samples for the various DAC configurations and demonstrates a software abstraction that facilitates the use of multiple DAC options. It is part of a series on Arduino Sound Generation, with the distinction of Parts 1, 2, and 3 removed, as much of the content is independent of previous articles. Among the various sound generation methods, the DAC approach appears to be the most versatile. A DAC converts a binary or digital value into an analog voltage value. An 8-Bit DAC converts a binary value ranging from 0 to 255 into an analog voltage from 0 to 5V, although the exact voltage range depends on the DAC configuration. Typically, a range of 0 to 5V is used for most applications. Since analog signals, particularly sound, need to oscillate around 0V, the DAC is often biased so that the midpoint is considered 0V. When a DAC outputs from 0 to 5V, this usually means that 2.5V is interpreted as 0V. By generating output signals such that half scale corresponds to 2.5V, an AC coupling can be established to create a +/- 2.5V swing. The concept of half-scale biasing can be confusing; however, it becomes clear once the general principle is understood. The values above half scale are treated as positive, while those below are treated as negative. For an 8-bit converter, the Most Significant Bit (MSB) can be utilized as a sign bit to implement this. For instance, the decimal value 128 is represented as 10000000 in binary, with the MSB set, indicating half scale of the 0-255 range. The MSB can be viewed as a sign bit, where 1 indicates positive values and 0 indicates negative values. Through this half-scale bias, any digital number representing sound data can be converted into a value suitable for loading into a DAC. The initial step involves converting the number into the range of +/-127 and then adding 128 to it. This conversion allows the analog output to swing from 0 to 5V, with the original zero point established at 2.5V. The 2.5V bias can be eliminated in hardware using a simple series capacitor, although it is not necessary in most applications. For example, a sound card's line input can be used for these experiments, which already includes a series capacitor for AC coupling. This ensures that the signal oscillates evenly around 0V, with the +/- voltage swing maintained around the average DC level by the capacitor. Although the series capacitor has a frequency response, its value is typically high enough to avoid issues within the audio frequency range. The circuit diagram illustrates the setup used between the various DAC outputs and the PC sound card input. A series resistor and capacitor to ground create a simple filter to eliminate high-frequency noise generated by the DAC's rapid switching between voltage values. This filter effectively removes high-frequency components. A 100K variable resistor (POT) allows for adjustment of the output voltage level for each DAC. The line input should remain within the 1V peak-to-peak range, or +0.5 to -0.5V range. Since the sound card features AC coupling, the amplitude only needs to be adjusted using this POT as a voltage divider. Both the right and left side inputs are connected to the filtered output without requiring additional components for implementing the PWM sound output. Michael Smith's PWM code generates a PWM signal at approximately 60KHz, which is easily filtered by the aforementioned filter. In fact, the filter may not even be necessary, as the sound card is equipped with input filters. Even for driving a speaker, the need for additional filtering is minimal.DAC is short for Digital to Analog Converter. In this article we play around the code Michael Smith created for a PWM based DAC. I modified his code so that other DAC options could be tried. I compare the 8-Bit PWM DAC with the R2R DAC at various numbers of bits. You might be surprised at how well a 4-bit DAC sounds. This article includes several sound samples for the various DAC options and demonstrates some software abstraction that allows for multiple DAC options. This article is part of the series on Arduino Sound Generation. I decided to drop the Part 1, 2, 3 distinction as much of the content is not dependent on the previous articles.
Of all the various methods of sound generation the DAC method seems most versatile to me. As mentioned before DAC is a common short name for Digital to Analog Converter. Basically a binary/digital value is converted to an analog/voltage value. An 8-Bit DAC would convert a binary value in the range of 0 to 255 into an analog voltage from 0 to 5V. The exact voltage range of the conversion is dependent on the DAC configuration but for most things we will play with, 0 to 5V will work.
Since analog signals, especially sound, needs to swing plus and minus around 0V we often bias the DAC so that mid scale is considered 0V. If the DAC outputs from 0 to 5V then we usually bias the signals so that 2. 5V is translated to 0V. If we generate our output signals so that half scale is 2. 5V then we can AC couple the output to get a +/- 2. 5V swing. The half scale biasing may be a bit confusing but really it`s easy once you get the general idea. We just call 1/2 scale zero so that any numbers above 1/2 are positive and below are negative. For an 8 bit converter we can use the MSB as a sign bit to make this happen. Consider that decimal 128 is 10000000 in binary. Note that the MSB is set and this is basically half scale of the possible 0-255 range. Think of the MSB as a sign bit, it`s one for positive values and 0 or negative. Using this 1/2 scale bias we can convert any digital number that might represent sound data into a value to load into a DAC.
The first step is to convert the number into the range of +/-127 and add 128 to it. In this example that will make the analog version swing from 0 to 5V with the original zero point set at 2. 5V. We can remove that 2. 5V bias in the hardware with a simple series capacitor. The series capacitor is not even needed in most applications. For example I use my sound card line input to do these experiments. This input has a series capacitor. The series capacitor is used to provide A/C coupling. This just means that the signal swings evenly around 0V. The +/- voltage swing is enforced about the average DC level by the capacitor. Of course there is a frequency response for the series capacitor but the value of the capacitor is usually high enough so that it will not be a problem for audio frequency ranges.
This diagram shows the circuit I used between the various DAC outputs and my PC sound card input. The series resistor and capacitor to ground form a simple filter to knock off the high frequency noise caused by the DAC switching instantly between the voltage values. It removes the high frequency components. The 100K variable resistor (POT) lets me adjust the output voltage level for each DAC. A line input should be kept in the 1V Peak to Peak range or +0. 5 to -0. 5 range. Since the sound card has A/C coupling I only need to adjust the amplitude using this POT as a voltage divider.
Also note that I connected both the right and left side inputs to the filtered output. There is no additional parts required to implement the PWM sound output. Michael Smith`s PWM code generates PWM at about 60KHz. This high frequency is easily filtered with the filter described above. You really don`t even have to have this filter as the sound card has input filters. Even if you wanted to drive a speaker, you would not need to f 🔗 External reference
A passive high-pass filter has been added after the output of the operational amplifier (op-amp) to eliminate DC offset, with the op-amp powered by +12V and the negative supply at 0V. A feedback resistor (Rf) of 500K Ohms is...
Q1 is a fixed oscillator operating at 455 kHz. U1 is a mixer with its own internal oscillator running at 45.5 kHz. FIL1 and FIL2 are Murata CSB455E filters or equivalent. D1 is a varactor diode (an IN4002 used...
This tutorial demonstrates how to connect an LCD display to an Arduino and test it. It provides a step-by-step guide for beginners on using a breadboard to establish the connection.
To connect an LCD display to an Arduino, first gather...
Two low voltage, low power zeners are used to control electronically the level of an audio signal. The attenuation range is from 6 to 58dB for an input current from 0.042 to 77 mA corresponding to a control voltage...
The circuit diagram illustrates a five-use tri-state audio logic pen utilizing components such as the CD4066 and a 555 timer. The primary elements include a multivibrator, a four-way switch (CD4066, designated as IC1), and a gate circuit formed by...
No setup is required: if correct values are used for resistors R3 to R7, LED D1 will illuminate at 0 dB input (0.775V RMS), LED D2 at +5 dB input (1.378V RMS), and LED D3 at +10 dB (2.451V...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more