i can imagine that R2R will be much smoother than PWM after filtering. nice video !
@flywittzbeats4008 Жыл бұрын
Thank you so much for this! Now I dont have to build both versions to see or hear what they're like. Excellent explanation
@craighollinger9972 Жыл бұрын
Thanks for watching!
@unregistereduser23 жыл бұрын
Neat channel, some great stuff here. I'd suggest trying a higher order filter on your pwm. A 2 or 4 pole sallen key filter should allow you to increase your cutoff point, and still get good attenuation of your pwm carrier, and get some buffering too. R2r might benefit from a similar filter near your sampling frequency
@slawomirpiernikowski61506 жыл бұрын
Great job Craig. Keep going. Looking forward for more such proffesional series.
@bbreeuwer45777 жыл бұрын
Clear story! One thing though. You can make the output with PWM much better to use an higher slope filter. 2nd order works nicely, but you could go for 3rd or 4th order. Raising the samplerate frequency also helps,about a factor 10-20. It might be interesting to use a differential PWM output to even bring down the noise more (and you actually get an higher output amplitude). Differential means that you use two outputs with one that is inverted. This is also what you typically see in Class-D power amplifiers. With a standard Arduino, I typically use 31kHz or 62kHz samplerate with a 2nd order (Butterworth) filter. Only costs an extra little opamp and a few passive components. For DC applications that works great as well, for AC signals you can get a decent bandwith up to roughly 8-10kHz.
@craighollinger99727 жыл бұрын
Yes, higher order filters with steeper cut-off skirts would be an improvement as would a higher PWM frequency. If a frequency generator is wanted, a microcontroller is not the best way to do it. There are lots of dedicated D/A chips available that do a much better job. Analog Devices has a quite a number of different chips, and depending on the frequency range, they can be reasonably priced. Thanks for watching.
@noviy_polsovatel5 жыл бұрын
The best solution is to use r-2r ladder + Lowpass filter to eliminate steps. It is much easier to smooth small ladder steps, then to smooth full amplitude of PWM signal.
@craighollinger99725 жыл бұрын
Correct.
@HakAtIt3 жыл бұрын
I was thinking the same. The filter would not have so much effect on the output voltage too.
@bloguetronica6 жыл бұрын
The PWM "DAC" is potentially noisy. The R2R ladder is a proper DAC, and can be improved by using more bits and by implementing a reconstruction filter.
@acraigwest3 жыл бұрын
Have you done a test using a filter on the output of the R2R ladder? you should be able to tune it based on the time between samples, which is much more consistent than the overall frequency
@craighollinger99723 жыл бұрын
That's the way it is normally done, put a filter on the output of the ladder. Make sure the sampling frequency is much higher than the output frequency, to limit the constraints on the filter.
@albandaumer34413 жыл бұрын
I'm working on a music project, would you say that the limitation you showed for the pwm would affect the audio frequencies, or is it only a problem for higher frequencies ? the osciloscope you shoed at 3:37 is around 3Khz Or maybe we can add some kind of auto-gain amplifier (or a filter that let through the band of higher frequencies + an amplifier) to the end of the pwm filter for that purpose ?
@craighollinger99723 жыл бұрын
It's been a while since I made this video so I don't remember the setup. But looking at first principals, the Nyquist theorem says that you must sample at 2X the maximum desired frequency to reproduce a signal. An this is a minimum. CD quality audio is sampled at 44kHz, so you would need to do this as well. I'm not sure if my setup would work at this high of a frequency, the ATMEGA328 isn't a very powerful processor. Simply amplifying higher frequencies wouldn't do anything. You still have to satisfy the Nyquist theorem. There are electronics that are purpose built for this. Just do a search on the internet and you should find what you need. I hope this helps and thanks for watching.
@hamidreza69218 жыл бұрын
thank you for sharing :) can the wave width decreasing be solved by an amplifier or something? i mean without losing resolution. and would you mind to record a similar video about amplification?
@drivera05023 жыл бұрын
I combined an Arduino Uno with a shift register and R2R ladder to get 8-bits which I buffered using an MCP602 op-amp. With port manipulation, I was able to output a new value at ~290 KS/s by looping with a variable incrementing by 1. I was able to print audio files at about 11 kS/s from Matlab where the limiting rate was the serial port baudrate. I'm sure if I had a microSD card, the output rate would be significantly higher. If multiple shift registers shared pins, I would only need one additional pin per DAC, but I also know my "max" output speed would also drop by a third to half the current
@craighollinger99723 жыл бұрын
Good luck with your experiments. There is an 8-bit port on the UNO, Port D. You won't be able to use the serial monitor but you will get an 8-bit wide R2R ladder DAC. That should increase your speed instead of going through a shift register.
@drivera05023 жыл бұрын
@@craighollinger9972 thanks! I saw you mentioned that in your video, but most of the projects I'm working on need to keep the arduino serial port available for communication with a computer, and additional pins are needed for controlling the on/off states of some other equipment, so I moved to the shift register to reduce the pins required for the DAQ. It's definitely not as fast as setting a single port (or running port commands to manipulate the last 6 pins of 1 and the first 2 of the next with a LP filter to reduce the jitter of the pins switching asynchronously)
@drivera05023 жыл бұрын
It may also be worth it for me to look into getting a DAC breakout module now that I think of it
@uni-byte Жыл бұрын
You could do a full 8-bits using just 3 pins with a 74HC595.
@craighollinger9972 Жыл бұрын
Could do that, might make the frequency lower though.
@uni-byte Жыл бұрын
@@craighollinger9972 Should be able to get pretty close to the full audio range I think. It's doesn't take too long to shift out 8 bits.
@manny96396 жыл бұрын
Thank you, excellent comparison!!!
@aysinarseven75706 жыл бұрын
I cant find the source code of the sine wave. could you add the code please? (web site does not open) also i want to add 2 sine wave with different frequencies in arduino. is this possible ? thank you..
@craighollinger99726 жыл бұрын
I've corrected the link to the schematic on GitHub, it now works. If you go to another video in my series: kzbin.info/www/bejne/mHrVhYqfitCpkKM you can find the source code there. The code produces a DAQ output using both PWM and R2R Ladder. Thanks for watching!
@francoisdastardly44056 жыл бұрын
Very clear explained. Thanks
@microcolonel5 жыл бұрын
I guess your frequency limitation on the pwm is the main issue here. Presumably each doubling of modulation frequency gives you a bit of precision or nearly twice the bandwidth for filter of the same complexity.
@craighollinger99725 жыл бұрын
Yeah, the ATMEGA328 is not a very powerful micro. Some of the higher end ARM chips running at 200+MHz would to better. But using a microcontroller to generate signals, while a good exercise, is just not very practical. Analog Devices has a lot of dedicated chips to do this. Pricey though. Thanks for watching.
@Brant_Channel7 жыл бұрын
Thanks for that explanation.
@craighollinger99727 жыл бұрын
Thanks for watching!
@knighttime197 жыл бұрын
Nice tutorial. There is anyway that output voltage can be adjusted to be suitable for Mic in jack of smartphone. Thanks
@craighollinger99727 жыл бұрын
The maximum voltage is fixed by the logic voltage level (5V) of the microcontroller. An amplifier or an attenuator would have to be added to the output of the ladder to set the voltage level for the smartphone.
@knighttime197 жыл бұрын
Thanks!!
@noweare16 жыл бұрын
Nicely presented, thanks
@مقاطعمترجمة-ش8ث5 жыл бұрын
Great video very Great thanks .
@craighollinger99725 жыл бұрын
You are welcome. Thanks for watching!
@LostDeadSoul5 жыл бұрын
According to the datasheet of the Atmega 2560 it has only one 6-bit GPIO PORTG. The rest are 8-bit GPIOs
@andrewferg87374 жыл бұрын
Great video! I made this version out of discrete components: kzbin.info/www/bejne/oKuYn6iKqrtmfM0 however, I not sure if I should R2R the final output where it connects to 4 NPN drivers.... any thoughts?
@craighollinger99724 жыл бұрын
I'm not sure what you have done, but it looks like a good result. Don't over complicate things.
@andrewferg87374 жыл бұрын
@@craighollinger9972 Thanks again for your tutorial! I changed my binary ladder to an R2R and it seems much more stable and efficient. kzbin.info/www/bejne/bJPapXSVmchpgKM