This R/2R DAC was my first sound card (just 8 bits) on my first PC back in the early ‘90s! I managed to fit 18 resistors and a 100nF capacitor for integration of the output signal in a DB25 plug back then, playing WAV files from the printer port of that old PC! 😊 Great video! It literally took me back to those years!
@@phant0masterr Also known as “Disney Sound Source”. I found the schematics of it back then, on the text “readme” file of the “MODplay” player of Amiga music tracks. Something like a MIDI file with 8bit sampled instruments. It was supported by 1 or 2 games but I remember that I had to write the software to play the WAV files in assembly, because even Pascal wasn’t fast enough to play them at the actual speed. My 386sx/16MHz back then was even slower than an Arduino in some tasks!
This is an excellent video explaining how early DACs were built and the principles behind them, nice work! One thing got me at the end however, you mentioned that the original input signal captured by the ADC could never be reconstructed exactly by the DAC. This is (mostly) incorrect though, as it ignores Nyquist-Shannon. If you band limit the input of the ADC at 1/2 your sampling frequency (idealized case) or lower (practically, 1/5 to 1/10 is sufficient for slow, non-specialty filters), then include an exact copy of this input filter on your output, you will reconstruct a mathematically identical signal to the one received! The limitation bit depth poses in this scenario is an increase in base noise floor, rather than a distortion of the signal itself. Because of this, these filters are nearly always included on off-the-shelf components designed for distortion sensitive applications.
Hi... I did a similar thing almost twenty years ago, through the "User-port" of my Vic 20 with 16 KBytes RAM expansion, to make a long research about PCM synthesis of percussive sounds (bass drums, snare drums, toms, claps, hi-hats etc... ). My "DAC" wasn't a R/2R type, but just eight resistors (10K-20K-40K-80K... ) from MSB to LSB, linked to a common line and "grounded" through a 10K resistor to convert the out from current to voltage levels. I created the sounds with BASIC programs that simulates sine oscillators, white and pink noise generators, "click" and "crack" A-R envelope generators, mixers and LP/HP filters (the elaboration's time was a little terrible, as you can guess!!!) and played with a simple Assembler programs, with a sample rate around 25 kHz. The result wasn't bad, it was a fun experience, but i soon discovered that 8 bit is too low as resolution for percussive sound voices (anyway some commercial drum-machines, as Korg's DDM 110/220 or DDD5 actually makes use of 8 bit samples... ). Now I'm thinking to assemble a vintage-style drum-machine with Eight sampled voice-cards triggered via MIDI by a DAW (as "Caustic 3" and the like), with a Pic and a simple cheap 16 bit DAC in any voice-card. Today a 16 bit DAC is cheaper than a bunch of 1% resistors... :-D Anyway I would like to listen to a 44/16 wav file through your home-made DAC expanded to 16 bit... Bye... :-)
I also did something like that with, believe it or not, the parallel printer port on my Ohio Scientific computer (very similar to an old PET computer). I built an 8 bit DAC resistor network into a printer cable which I connected to my amplifier and I "printed" various wave forms which sounded... interesting. Random numbers made something of a rumbling white noise which could have sounded like explosions if I had known how to code envelopes. BASIC was too slow to make anything but the lowest frequency sine waves so I wrote a BASIC program to make a lookup table which then jumped into a machine language routine which "printed" values through the table, skipping values to increase the frequency. It didn't really sound like a pure sine wave but it had a flute-like sound. I could have done much more if I had known what I was doing.
Although a year old now, just a quick thanks for the video. It has inspired me further, to explore the MCP4728 device on my latest IPEC ESP32 ATM90E32 IoT Power Energy Controller and Monitor board (variation on the original IPEM). So many different DACs and ADCs available v massive variations in cost and availability, it is sometimes not straight forward to choose one device for a particular design. Keep up the good work.
These DACS are still still used in single chips since waffering Resistors is easy and produces very high tolerances. There are different kinds of DACs, and each of them have there specific requirements on their implementation.
You can also use as an alternative, one of the cheap stepper motors with a 64x gearbox divider which, combined with the 64 steps of the stepper gives 4096 steps for 360º, resolving better than 1/10º. I used a stepper motor like that to drive my telescope’s focuser, because I wanted the accuracy, especially for a 5x teleconverter when I’m imaging planets, and also because I wanted to focus without touching the telescope at such high magnifications.
Useful for raspberry Pi GPIO also if you don't want to use any dedicated chips. If you use a standard shift register that almost any hobbyist has, you don't need many pins
It's good to be teaching hobbyists this. But a 12 bit DAC with 1% resistors? It is likely to have some serious non-linearity issues. You would need 0.025% resistors for an honest 12 bit converter. I did one of these for a my first serious professional project back in 1968/69. AFAICR is was 6 or 7 bits. I only had 5% resistors available. But I did have a kickass DVM available. So I soldered a bunch of resistors in a long chain, applied a stable voltage and measured and noted the voltage drop across each resistor. Then I sorted them in order of relative resistance and picked an optimum combination.
The tx and rx ports are always on due to the Serial.begin() command. This way, the first two bits are always on. To get over this problem you have two solutions, you can shift the pins by two, starting in pin 2, or just delete the Serial commands.
Thank you, this video really helped me. I have a question for you, if i were to use a controller that does not have any easy to use ports, could i use a shift register and a serial input to control the resistor ladder?
0:56 Isn't more bits purely the scale of assignable amplitude? Isn't 5:15 the digital version? I'd like to see the 8 bit sine on an oscilloscope after it is converted to analog.
Indeed the ADC of the Arduino is only 10bit, so reading back the 12bit output of the DAC will not be accurate, but it doesn’t mean that the DAC can’t be used to drive something else. After all, the redirection of the DAC’s output back to the 10bit ADC input of the Arduino was mostly to demonstrate the different bit depths ladder output on the video. On the other hand, a 12bit DAC on the 5V digital output of the Arduino, would theoretically resolve in 1.2mV per step. So using 1% resistors may give you noise higher than that in the end, assuming that your power source is also stable enough.
Question about the code. You step through i from 0 to 360 by 1 to calculate your sign wave. That is 360 steps. Shouldn't you have used MAX_12_BIT_NUM as the number of steps between 0 and 360? It still looks okay because you showed graphs of 8bit (255) and 12bit (4095)... I wonder if 10bit (1023) would look the same as 12bit because they both would have been truncated to 360 steps by your loop.
I’m honestly not sure. Jeff wrote that part of the code and I didn’t fully understand how it worked. But since I was trying to create an arc 360 sounded right at the time.
nice; two notes: - when you change resolution you movevtge jumper wire, but you do nit show on schematic which one... - would be good to actually see the dac output on oscilloscope as well ; plot from serial is still ‘software’, we need real hardware signal, dont we?
I noticed this too. Serial ports Rx & Tx are the problem here. By using 2 Arduino's, one to generate and another to analogRead the signal it works correct.
Hey Karen, I met you at the Milwaukee Maker Faire a few years ago. Will you be at the one for this year? I plan to be there. Maybe I will bring my rPi mini Arcade.
It is not possible to achieve 12-bit resolution using R2R ladder and simple microcontroller. The problem lies in the resistors mismatch. Theoretically, even to achieve 8-bit resolution, 0.1% resistors are needed. But that is only part of the problem - the uC pins all have output resistances variation in the range of 100-200 oHms which adds to the mismatch error. Then take into consideration the pin voltage,Vdd, which is not very stable (typ 1-5% noise). There's more errors coming from the high-speed glitches due to pins risetime / falltme mismatch. In practice, 4-7 bits of resolution is achievable, depending on the update rate. What was shown here was at best 7-bit resolution in nearly static conditions. After falling into a pitfall and making few R2R DACs myself, I advise not to utilize such approach - a simple PWM DAC is more than adequate for the Arduino users, and saves a ton of digital pins on uC!
Look at E-Tims 2007 R2R DAC for N64 to get digital RGB to Analogue, for a laugh. It's being commercialised. He compressed the shift register and D flip flops into a single CPLD but it's still using R2R.
It's why no one ever practically makes a discrete R/2R ladder network DAC. Covered it in a lecture at degree level in about 10 minutes. Never thought anyone would be stupid enough to make one and then try and teach people how to do it. It's pointless, it has no value, not even from a teaching perspective.
This "zooming in" to 12 bits waveform shows pixels of screen, not 12bits DAC steps. Unless you have screen resolution with 4096 vertical lines. Nice video anyway :)!
The jaggedness of the pixels isn't what she's referring to, but rather the slight waviness of the line that's similar to the previous stair-stepping of the output but on a scale of 4-5 pixels per step.
6:48 I'm sorry to say, but this is complete crap. An appropriate filter on the output completely eradicates the steps. Have a look at your CD output on an oscilloscope, for example.
This R/2R DAC was my first sound card (just 8 bits) on my first PC back in the early ‘90s! I managed to fit 18 resistors and a 100nF capacitor for integration of the output signal in a DB25 plug back then, playing WAV files from the printer port of that old PC! 😊 Great video! It literally took me back to those years!
Covox speech thing! 😊
Pp
@@phant0masterr Also known as “Disney Sound Source”. I found the schematics of it back then, on the text “readme” file of the “MODplay” player of Amiga music tracks. Something like a MIDI file with 8bit sampled instruments. It was supported by 1 or 2 games but I remember that I had to write the software to play the WAV files in assembly, because even Pascal wasn’t fast enough to play them at the actual speed. My 386sx/16MHz back then was even slower than an Arduino in some tasks!
This is an excellent video explaining how early DACs were built and the principles behind them, nice work! One thing got me at the end however, you mentioned that the original input signal captured by the ADC could never be reconstructed exactly by the DAC. This is (mostly) incorrect though, as it ignores Nyquist-Shannon.
If you band limit the input of the ADC at 1/2 your sampling frequency (idealized case) or lower (practically, 1/5 to 1/10 is sufficient for slow, non-specialty filters), then include an exact copy of this input filter on your output, you will reconstruct a mathematically identical signal to the one received! The limitation bit depth poses in this scenario is an increase in base noise floor, rather than a distortion of the signal itself. Because of this, these filters are nearly always included on off-the-shelf components designed for distortion sensitive applications.
Ahhh, good old Nyquist Shannon sampling theorem.
Hi...
I did a similar thing almost twenty years ago, through the "User-port" of my Vic 20 with 16 KBytes RAM expansion, to make a long research about PCM synthesis of percussive sounds (bass drums, snare drums, toms, claps, hi-hats etc... ).
My "DAC" wasn't a R/2R type, but just eight resistors (10K-20K-40K-80K... ) from MSB to LSB, linked to a common line and "grounded" through a 10K resistor to convert the out from current to voltage levels.
I created the sounds with BASIC programs that simulates sine oscillators, white and pink noise generators, "click" and "crack" A-R envelope generators, mixers and LP/HP filters (the elaboration's time was a little terrible, as you can guess!!!) and played with a simple Assembler programs, with a sample rate around 25 kHz.
The result wasn't bad, it was a fun experience, but i soon discovered that 8 bit is too low as resolution for percussive sound voices (anyway some commercial drum-machines, as Korg's DDM 110/220 or DDD5 actually makes use of 8 bit samples... ).
Now I'm thinking to assemble a vintage-style drum-machine with Eight sampled voice-cards triggered via MIDI by a DAW (as "Caustic 3" and the like), with a Pic and a simple cheap 16 bit DAC in any voice-card. Today a 16 bit DAC is cheaper than a bunch of 1% resistors... :-D
Anyway I would like to listen to a 44/16 wav file through your home-made DAC expanded to 16 bit...
Bye... :-)
I also did something like that with, believe it or not, the parallel printer port on my Ohio Scientific computer (very similar to an old PET computer). I built an 8 bit DAC resistor network into a printer cable which I connected to my amplifier and I "printed" various wave forms which sounded... interesting. Random numbers made something of a rumbling white noise which could have sounded like explosions if I had known how to code envelopes. BASIC was too slow to make anything but the lowest frequency sine waves so I wrote a BASIC program to make a lookup table which then jumped into a machine language routine which "printed" values through the table, skipping values to increase the frequency. It didn't really sound like a pure sine wave but it had a flute-like sound. I could have done much more if I had known what I was doing.
Although a year old now, just a quick thanks for the video. It has inspired me further, to explore the MCP4728 device on my latest IPEC ESP32 ATM90E32 IoT Power Energy Controller and Monitor board (variation on the original IPEM). So many different DACs and ADCs available v massive variations in cost and availability, it is sometimes not straight forward to choose one device for a particular design. Keep up the good work.
These DACS are still still used in single chips since waffering Resistors is easy and produces very high tolerances. There are different kinds of DACs, and each of them have there specific requirements on their implementation.
Hi Karen, really enjoy your approach. Make it easy to understand. I want my kids to get into circuits and your approach will really help, Thanks!
I will use this to power my stepper motor because i wanted to make a mechanical clock
You can also use as an alternative, one of the cheap stepper motors with a 64x gearbox divider which, combined with the 64 steps of the stepper gives 4096 steps for 360º, resolving better than 1/10º. I used a stepper motor like that to drive my telescope’s focuser, because I wanted the accuracy, especially for a 5x teleconverter when I’m imaging planets, and also because I wanted to focus without touching the telescope at such high magnifications.
Useful for raspberry Pi GPIO also if you don't want to use any dedicated chips. If you use a standard shift register that almost any hobbyist has, you don't need many pins
Why not using a low pass filter for the 8 bit one to see the difference to the 12 bit one?
4 bits should show 16 different values?
It's good to be teaching hobbyists this. But a 12 bit DAC with 1% resistors? It is likely to have some serious non-linearity issues. You would need 0.025% resistors for an honest 12 bit converter.
I did one of these for a my first serious professional project back in 1968/69. AFAICR is was 6 or 7 bits. I only had 5% resistors available. But I did have a kickass DVM available. So I soldered a bunch of resistors in a long chain, applied a stable voltage and measured and noted the voltage drop across each resistor. Then I sorted them in order of relative resistance and picked an optimum combination.
This is who I need to teach me arduino
Please next video on Delta Sigma ADC with Arduino
Where can I get the source code and full review of the schematic diagram..??
Will this be functional with music or just test tones?
I can't find the project code, is it available anywhere?
The tx and rx ports are always on due to the Serial.begin() command. This way, the first two bits are always on. To get over this problem you have two solutions, you can shift the pins by two, starting in pin 2, or just delete the Serial commands.
Does this cross 0v so it doesn't bias the audio signal by +2.5v?
Thank you, this video really helped me. I have a question for you, if i were to use a controller that does not have any easy to use ports, could i use a shift register and a serial input to control the resistor ladder?
Muchas gracias por tu tiempo.
0:56 Isn't more bits purely the scale of assignable amplitude? Isn't 5:15 the digital version? I'd like to see the 8 bit sine on an oscilloscope after it is converted to analog.
Love your clear explanations 💕
Karen is the best!!!!!
The delay() function pauses the program, is it still improves stability that way? 4:45
Congratulations ! Very good video. One question, please. Can I use this to audio? What is the high frequency possible? Thanks
Will it work with my SoundRocks™ and solid gold speaker bus bar?
I love your videos! Can you make one explaining class D amplifiers and PWM?
3:40 oh wow, this is exactly how a 6522 VIA is programmed, I didn't realize my Arduino was so similar to my homebrew 6502 computer, cool
great video, thanks
A question, the ADC on the Arduino is only 10bit, so surely the 12 bit is a bit fruitless?
Indeed the ADC of the Arduino is only 10bit, so reading back the 12bit output of the DAC will not be accurate, but it doesn’t mean that the DAC can’t be used to drive something else. After all, the redirection of the DAC’s output back to the 10bit ADC input of the Arduino was mostly to demonstrate the different bit depths ladder output on the video. On the other hand, a 12bit DAC on the 5V digital output of the Arduino, would theoretically resolve in 1.2mV per step. So using 1% resistors may give you noise higher than that in the end, assuming that your power source is also stable enough.
Cool! Thanks, Karen!
@0:58: 6 bits is 64, 8 bits is 256.
Question about the code.
You step through i from 0 to 360 by 1 to calculate your sign wave. That is 360 steps. Shouldn't you have used MAX_12_BIT_NUM as the number of steps between 0 and 360? It still looks okay because you showed graphs of 8bit (255) and 12bit (4095)... I wonder if 10bit (1023) would look the same as 12bit because they both would have been truncated to 360 steps by your loop.
I’m honestly not sure. Jeff wrote that part of the code and I didn’t fully understand how it worked. But since I was trying to create an arc 360 sounded right at the time.
Nice! Using any board, low budget , audio DSP 24bit 96khz, ADC- DAC, with room correction, pls if any do respond. Thanks
You are a scientist
nice; two notes:
- when you change resolution you movevtge jumper wire, but you do nit show on schematic which one...
- would be good to actually see the dac output on oscilloscope as well ; plot from serial is still ‘software’, we need real hardware signal, dont we?
Awesome content. Thank you
Thanks for the video, I enjoyed it.
At 05:15, this appears to be 2-Bit (4 values) rather than 4-Bit (16 values).
I noticed this too. Serial ports Rx & Tx are the problem here. By using 2 Arduino's, one to generate and another to analogRead the signal it works correct.
Time to see why 256 actually looks like 😂! I wouldn’t mind seeing a video on how this effects audio quality either
Hey Karen, I met you at the Milwaukee Maker Faire a few years ago. Will you be at the one for this year? I plan to be there. Maybe I will bring my rPi mini Arcade.
Yes. I’ll be working on the Powerwheels track helping run the races.
Well done! Good review
Why dont we use 1 resistor set at maximum loudest point
brilliant idea actually !!!! !!!! !!!!
Nice demo!
Glad you think so!
It is not possible to achieve 12-bit resolution using R2R ladder and simple microcontroller. The problem lies in the resistors mismatch. Theoretically, even to achieve 8-bit resolution, 0.1% resistors are needed. But that is only part of the problem - the uC pins all have output resistances variation in the range of 100-200 oHms which adds to the mismatch error. Then take into consideration the pin voltage,Vdd, which is not very stable (typ 1-5% noise). There's more errors coming from the high-speed glitches due to pins risetime / falltme mismatch. In practice, 4-7 bits of resolution is achievable, depending on the update rate. What was shown here was at best 7-bit resolution in nearly static conditions.
After falling into a pitfall and making few R2R DACs myself, I advise not to utilize such approach - a simple PWM DAC is more than adequate for the Arduino users, and saves a ton of digital pins on uC!
Look at E-Tims 2007 R2R DAC for N64 to get digital RGB to Analogue, for a laugh. It's being commercialised. He compressed the shift register and D flip flops into a single CPLD but it's still using R2R.
It's why no one ever practically makes a discrete R/2R ladder network DAC. Covered it in a lecture at degree level in about 10 minutes. Never thought anyone would be stupid enough to make one and then try and teach people how to do it. It's pointless, it has no value, not even from a teaching perspective.
Great video 👍
This "zooming in" to 12 bits waveform shows pixels of screen, not 12bits DAC steps. Unless you have screen resolution with 4096 vertical lines. Nice video anyway :)!
The jaggedness of the pixels isn't what she's referring to, but rather the slight waviness of the line that's similar to the previous stair-stepping of the output but on a scale of 4-5 pixels per step.
thx
Could you please demonstrate a 12 bit DAC without the use of an Arduino please?
Good
Hi Karen
Oh my goodness 😍😍
Next video: building a 32 bit audiophile audio DAC with arduino😂
super video😍👍🚂😉🍻
Ok Teach!
"Smooth and Siny" is t shirt material
ADCs are not stairstep! 🤯 yes stairstep exists in sample hold. But it’s a bad way to explain ADC.
And why 2r between r s .i dont have time think .just question for save my time😂😂😂😂
6:48 I'm sorry to say, but this is complete crap. An appropriate filter on the output completely eradicates the steps. Have a look at your CD output on an oscilloscope, for example.
Pi pico pwm
So lovely, but all this is beyond my understanding
The programmer/nerd in me wants to declare the constants:
MAX_4_BIT_NUM (1 >> 4) - 1
MAX_6_BIT_NUM (1 >> 6) - 1
MAX_8_BIT_NUM (1 >> 8) - 1
// etc.