It's flawed simply because it didn't do what you wanted it to do.
The low pass filter comprises of a resistor and capacitor, and an op-amp buffer.
As these are hardware components, I can't add them to a sketch.
It would be up to you to add the low pass filter if you continue with the Uno. However if you have a Due arriving tomorrow, that might be the best way to go.
the code of post 12 for is a ESP32 but similar code should run on a Due
I tend to prefer ESP32s as they are a lot cheaper than a Due - also I managed to destroy one of the DACs on a Due
No it is not. This is due to the way the frequency waveform is generate. These is no speed up using D/A converters.
When I refer to the lower frequency I refer to the frequency content of the generated signal, not how quickly one can output samples.
Then use the right words and maybe we can have an intelligent conversation, but my hopes are not high.
What you are are saying is that the the output of a 12 Bit D/A has a higher bit resolution than one from an 8 bit timer well derr!
And so because of this you can make the waveform more complicated.
NO NO NO NO NO
If you are trying to make the difference show in an increased sample resolution. You do not make the wave more complicated. You make the wave smoother. This means that the "quantitation error" will be smaller and it will sound better. The exact opposite of what you said.
If you do use the the extra resolution to make the wave more complex then you will only add higher harmonics to the waveform and these will mainly be above the range of human hearing, it will not result in a more complex sounding waveform.
Now to increase the sample resolution using a timer, then you have to go to two timers connected together to form a 16 bit timer. This can be done with this like:-
But admittedly not with a UNO.
So my conclusion is that you know little about audio and signal processing, and have absoloutly no actual practical experience the subject. Am I wrong?
@Grumpy_Mike This isn't a very kind thing to say. You can do better.
What i was trying to get across is that there is a resolution bandwidth tradeoff while using PWM. Therefore certain waveforms may not be feasible with PWM (high resolution and high frequency) and a true DAC is required.
I wouldn't say absolutely no practical experience. I have developed real-time filters and dynamic range compression for Bluetooth audio using ESP32. Audio over USB for RP2040 and generic digital 4th-order delta-sigma modulators that also give very nice audio output on the rp2040. People do seem to enjoy these projects and they get reasonable traffic via github. Therefore, I will comment here and there on signal processing matters, even if I risk provking your ire @Grumpy_Mike
And what In was trying to get across is that there is no difference between using PWM to output a signal as opposed to using a D/A.
Indeed yo can get information of an arbitrary complex waveform by using just a 1 bit sample, if you go about it the right way. However, I see you have experience of delta-sigma so you should know that.
I think your problem is using words incorrectly to express concepts you seem to know little about.
A very "complex" waveform, to use your words is a human voice, here is an example of how using 8 bit samples you can get quite good results.
Sure that is not the best quality in the world but you have to admit that it is a complex waveform, and so your previous statement :-
Is totally and utterly wrong.
Sampling theory shows that given two samples (or more) per period is enough to recover the original information. It mentions nothing about the bit size of these samples, nor how these samples are reconstituted.
It is very annoying when someone makes false statements, especial on a topic I have spent a lot of my adult life studying.
Doing postgraduate research into adaptive pulse code delta modulation, in the days before microprocessors could handle such fast signals, so everything had to be built by hand. Even a 12 bit A/D converter cost the same money as I had to live on for three months. Then lecturing on a MSc course in signal process at a UK University. And also many magazines articles thought the 1980s, to the present day. Good grief I even wrote a book about it.
@Grumpy_Mike Would you say your biggest issue with what I have said is that I am using the word complicated where you feel I should be using the word quality?
hello @Grumpy_Mike I know how you fell about it. When you have spent so much time on a topic, expecially as a post-graduate fellow, you don't want to listen to naive replies. That being said, I know you would like me to purchase your book, but right now I am searching for something far more immediate. I am a neuroscientist trying to make an optogenetics device works. I am not interested in becoming an expert in the field and thus I would like to rely on someone more skilled. So, if you want to help with the code and and explain why nothing works and only a square wave is being generated out of my code I will appreciate.
Thanks
I was typing this reply and my internet crashed. I think I have a problem with the internet card. This is a borrowed temporary machine.
It is quite simple, as has been pointed out by other posters. You get square waves out because you are only writing digital outputs which are either zero or one, or High and Low. So how do you expect this to generate a ramp?
A ramp consists of a number of increasing small voltage steps and your original code can simply not do this. You need to use something that will give you a lot of different small voltages.
One of these methods is to use PWM, it stands for Pulse Width Modulation and if you want to know how this works see
http://www.thebox.myzen.co.uk/Tutorial/PWM.html
The other way is to use a Digital to Analogue converter known as an D/A. These come in various forms from a few resistors connected to several output pins on an Arduino, to a complete chip that attaches to the Arduino through an interface like the SPI or I2C interface. These D/A come in lots of resolutions known as bits. For each bit of resolution you double the number of different voltage levels you can get it to generate. So a 1 bit D/A is just like a digital output it generates only 2 voltage levels, a 2 bit D/A will generate four levels and so on.
Most chips have a minimum 8 bits resolution so that is 256 different levels.
The problem with a Due is that you can only get 3mA from A0 D/A otherwise it breaks. Also your output will not go down to 0V.
No I am not wanting you to buy my book I am trying to help.
No more sniping.
@zonedro, this post is not addressed to you.
@zonedro
Why did you decide against the MCP4725
hi've just bought both arduino due and MCP4725. Arduino due should not work properly as my desired output should go high at 5V (i didn't try it out yet). I am playing around with MCP right now, and wondering which circuit could work. I can tell, I am confused. I need a output to be a BNC cable connected to a led generator device, but I am not figuring out the right way to do so.
Hello @Grumpy_Mike , and thanks for your explanation. Now it does make sense (finally). Unfortunately, I am having still hard time in order to figure out the correct way to connect my circuit. If I am correct, out of a PWM pin (let's say 5) i will generate the digital wavefor, which will then be converted to an analog one. Then I need to "collect" this analogic signal and send it through a BNC cable. Any hint?
@jim-p please read my reply
these work ok for prototyping
https://www.mouser.co.uk/ProductDetail/Gravitech/BNC-F-TERM-S?qs=unwgFEO1A6tHUOL9IlhrFA%3D%3D&mgh=1&vip=1&gclid=Cj0KCQjwzdOlBhCNARIsAPMwjbyF1-cJM2CT499qIJNtJ060mFB_ka1ERNHp35ElgOH5DGJc2PFeMYYaAghnEALw_wcB
Can you please provide some information about this led generator
You can actually connect the MCP4725 directly to that LED driver.
Use short wires (16" or less) twisted together and maybe a BNC adapter
like this: