Arduino Forum

Using Arduino => Audio => Topic started by: dgtldan on Aug 06, 2019, 01:31 am

Title: Using two oscillators dual DAC
Post by: dgtldan on Aug 06, 2019, 01:31 am
Looking for recommendations for using a simple sketch to utilize two DACs on DUE or comparable unit to generate a low freq wave (.1 Hz to 30 Hz) as one component with the other oscillator riding on the same wave form with an adjustable frequency of 1 Hz to 100 Hz.

I'd use two analog inputs to set the frequency pots.

Would I have to take one DAC output and use as analog reference to achieve this as a mixer?

Ideally would like to be able to control this from an iPhone.

TIA
Title: Re: Using two oscillators dual DAC
Post by: DVDdoug on Aug 06, 2019, 02:34 am
Mixing is done by summation so it's easy to do it in software.   For example, add sample-1 from the 1st waveform to sample 1 of the 2nd waveform, add sample-2 to sample-2, etc.*

But there are a couple of "extra things".    ...If the sum exceeds the voltage limits (typically 5V peak-to-peak) you'll get clipping so you'll need to scale-down** before or after summing.

...Analog mixers are built around summing amplifiers and that's pretty easy too.   

Most mixers have level controls for the channels (before mixing) plus a master level control (after mixing) so in practice it's a weighted average instead of a simple sum.

Most mixing software works in floating-point so the software itself won't clip, but you can still clip the DAC (which is integer based) so the level has to be reduced before sending the data to the DAC.   

Floating point in the Arduino is probably too slow, but you can use type-longs, etc., but you'll still need to scale-down to 16 or 24 bits to match the DAC.

Or you can make a passive mixer with resistors, and again it works out more like averaging than summing.



* If you're new to digital audio and you don't understand sampling, the Audacity website (https://manual.audacityteam.org/man/digital_audio.html) has a nice tutorial.    i.e.  CD audio is sampled 44,100 times per second with each sample representing the amplitude/height at one instant in time.    The DAC "connects the dots" and smooths/filters to re-create the continuous waveform.

** Volume changes (scaling) is done by multiplication...  Multiply all of the samples by 2 for a +6dB boost, and Multiply by 0.5 for a 6dB cut, etc.
Title: Re: Using two oscillators dual DAC
Post by: ballscrewbob on Aug 06, 2019, 05:02 am
DO NOT CROSS POST.

Other copy DELETED.

Bob.

Title: Re: Using two oscillators dual DAC
Post by: Grumpy_Mike on Aug 06, 2019, 07:42 am
Quote
Floating point in the Arduino is probably too slow
He is using a 48MHz Due so for the very low frequency wave he is using then it will be fine.

However a word of caution about those D/A outputs on the Due.
1) They don't operate over the full range of 0 to 3V3 but over a smaller section. Can't remember of hand what so look it up if it is a worry.

2) Those pins are extremely delicate and are only rated for 3mA. It is very easy to burn them out as I, and many others, have discovered. Ideally they should be buffers by an op-amp wired as a voltage follower.

Quote
Would I have to take one DAC output and use as analog reference to achieve this as a mixer?
No that would not mix the signals but would amplitude modulate them. Unless you are using the word mix in RF terminology and not audio terminology.
Title: Re: Using two oscillators dual DAC
Post by: MarkT on Aug 11, 2019, 10:29 pm
The DACs go from 1/6th of the supply voltage to 5/6th of the supply voltage (its stated in the
datasheet in a very non-obvious place).  Despite being 12 bit you get far less accuracy than you'd
expect as they have very poor performance (speckle patterns of many LSBs).  They are also very
delicate output pins and many people have fried them.

I strongly recommend using an external SPI (or I2S) DAC using a clean supply voltage from a linear regulator. 
The analog side of the SAM3X8 chip is not upto par, and the Due board 3.3V analog rail is noisy.