I need 2 seperate sinewave signal sources, 20khz and 25khz.
Is it possible do this, with 2 analogue outputs.
Is there any example coding?
It might sound silly, and not too sure, but whilst the main program is running and doing other things, what happen to the 2 analogue outputs. Do they still keep oscillating??
I assume you cannot get a + and - sine wave, and only 5v peak (+-2.5v).
Or if a sinewave is not feasible, can I run 2 digital outputs.
The Mega has only digital outputs. Timers can be used to generate 20 kHz and 25kHz digital signals on different pins, which are fine for driving ultrasonic transducers.
Check up instead of guessing. There exist a few Arduinos with a DAC (analog) output.
Naturally, you will also want to check if the DAC can generate a sine wave signal of the desired frequency and quality, if you believe that a sine wave is important.
It would appear that if the board has PWM this can be used with RC filters to get a sinewave.
But I think thats getting outside of my comfort zone. Maybe I have got to learn. Or just revert back to switching the power supply to existing oscillators.
Yes that can be done. But many arduinos are not fast enough to do this. You would need something like 250 kHz pwm to get a nice sine wave...
The counters simply run not fast enough to do that with a bit depth of 8 bit...
No idea how fast the esp32 counters can go...
If you want do your own experiments with DDS, ATmega with R-2R ladder can produce quite nice and smooth sine wave but 8-bit max. I'm not sure about ESP32, probably cannot avoid some jittering in the signal, but I am not an expert in ESP32 field. ATmega has an advantage that it is able to disable all interrupts so the output signal will be complete without any jittering. It is fast enough to produce 25kHz, even more. Years ago I did some experiments with ATmega1284P and the result was really impressive.