I'm having a heck of a time just playing a basic sine wave via the DAC on the Zero.
I've followed this tutorial (second sketch, "ZeroWaveGen"), which is mostly copy/pasted from this code in the AudioZero library here.
The DAC output pin is going through a 1uF ceramic capacitor, and then into my Scarlett 18i8 audio interface.
It doesn't seem to work for me... sometimes it makes a reasonable sine wave, but depending on the number of samples and sample rate it usually it makes a vaguely-sine-linke wave with strange artifacts and distortion components, not the correct frequency, etc.
I can ask some more precise questions about that particular code, but I thought I'd check to see if there were any obvious and easy ways to do this that I am overlooking.
Constraints are these:
- PWM method instead of DAC is probably not an option (AFAIK) as we need frequencies up into 5 or 6kHz
- super precise frequency is not necessary -- that demo code above actually only approximates the frequency by using timers set to an integer division of the SystemCoreClock.
- frequency needs to be programmatically selected (i.e. I can't use stored WAV files of sine waves or something like that)
- ideally we can use the on-board DAC and not an external utility board/shield, though I'm reluctantly open to that if it simplifies things drastically.
I had assumed it would be something like:
SomeAudioLibrary.begin(sample_rate);
SomeAudioLibrary.sineWave(440.0);
...but I'm getting the picture that nothing like this exists?
Any tips getting me pointed in the right direction are appreciated. I just noticed this post so I'll check that out next to see if there are any appreciable differences to my code.
Thanks!