Create two variable sinusoid waves on UNO

Hi to all,
I want to have a wave form generator "arduino copy" to perform some test on oscilloscopes.
Obviously, the waves must be variables in frequency...

My first approce was to create SPWM like These project but seems to be some limitation (library or board linked, i didn't understand) to use two timers at the same time timer1 to trigger wave1 - timer2 to trigger wave2.
Other users have same issue like writteln in These topic

can someone give me some hint about the feasibility of the project? I need external Integrated circuits like N555 or other stuff?

Thanks to show me the way.

best regards.

Perhaps a good starting point would be to explain the nature of your oscilloscope tests. It would determine many things about the hardware and software you would use.

You can buy a waveform generator for less than a dollar:

I wonder how a 555 would produce sine waves suited for a scope test. I think that it would allow to check the sine wave generator by means of a scope :frowning:

Also an Arduino is good in producing square waves, but poor in properly shaped sine waves.

DrDiettrich:
I wonder how a 555 would produce sine waves suited for a scope test. I think that it would allow to check the sine wave generator by means of a scope :frowning:

Also an Arduino is good in producing square waves, but poor in properly shaped sine waves.

Double integration with two stages of op amp integrator. The first integration gives you a triangle wave. The second one gives you an "almost" sine wave.

The first project referenced does produce a sine wave by using Arduino digital outputs as the inputs to a R2R ladder which is a crude, cheap way to create a digital to analog converter (DAC).

The limitation is ultimately frequency, about 10 KHz is the maximum before the output becomes distorted when you run out of processor clock cycles.

You can also buy a DAC chip and drive it from an Arduino. Look up the MCP4725 on Adafruit for an example but know that they too have frequency limitations. An SPI interface DAC will have a higher maximum frequency output.

What maximum frequency and amplitudes do you need for these tests? Does the amplitude need to be adjustable or is fixed okay?

I did not need high freq. A couple of KHz is enought.
Wave must be variable

Thank you

I would use a DDS device such as the AN9833

aarg:
Perhaps a good starting point would be to explain the nature of your oscilloscope tests. It would determine many things about the hardware and software you would use.

You can buy a waveform generator for less than a dollar:
/Square Generator Waveform Signal Generator DIY Kit DC 6 12V NE555 Generator Module|Signal Generators| - AliExpress

Basically I want to verify the accuracy of a self-made arduino Due based oscilloscope.

For sure I can buy some low cost device, but my approce is DIY...

For such projects I use a USB scope with built-in function generator. The function generator to test my DIY scope, and the scope to test my DIY function generator.

How many support points (digital values) do you want for each cycle, in order to get a smooth enough sine wave? A 16MHz Arduino can output about 100k/s values to a R2R ladder or built-in ADC. External ADCs are slower by the bit rate required for serial transmission of the values.

DrDiettrich:
For such projects I use a USB scope with built-in function generator. The function generator to test my DIY scope, and the scope to test my DIY function generator.

How many support points (digital values) do you want for each cycle, in order to get a smooth enough sine wave? A 16MHz Arduino can output about 100k/s values to a R2R ladder or built-in ADC. External ADCs are slower by the bit rate required for serial transmission of the values.

256 point (8bit) is enought to start. .. The real problem I see for a R2r ladder is the big number of pins to use...Not enought on an Arduino Uno for 2 waves + 1 rotary encoder...

Basically I want to verify the accuracy of a self-made arduino Due based oscilloscope.

If you want to verify accuracy then you need a properly calibrated reference or instrument to verify against. You can't verify the accuracy of one Arduino project against another as neither one will have a sufficiently accurate reference, and neither will be traceable back to a reference standard. You need an instrument that has been calibrated by an accredited calibration house.

The best reference I personally have access to is the 1 pulse per second output from a GPS receiver, which, being GPS, is referenced to an atomic clock.

PerryBebbington:
If you want to verify accuracy then you need a properly calibrated reference or instrument to verify against. You can't verify the accuracy of one Arduino project against another as neither one will have a sufficiently accurate reference, and neither will be traceable back to a reference standard. You need an instrument that has been calibrated by an accredited calibration house.

You absoluttely right.
I forget to tell that I will compare the results with a real oscilloscope indeed. (my friend scope because I dont own it)

Muplex:
You absolutely right.
I forget to tell that I will compare the results with a real oscilloscope indeed. (my friend scope because I dont own it)

Well in that case use the oscilloscope or buy one. If you calibrate your home made reference to your friend's oscilloscope then it will be less accurate than your friend's oscilloscope. You need to decide how much accuracy you need and purchase instruments accordingly, and if accuracy is important get them calibrated at a calibration house annually.

You also have to consider how stable a reference is and whether it is good enough your your purposes. An RC oscillator is the worst and will drift all over the place, a crystal is pretty good and if you want better then you need temperature controlled crystal oscillator (TCXO). After that it's an atomic clock, which don't come cheap but you can buy them if you want to.

Muplex:
256 point (8bit) is enought to start. ..

That means how many time steps from min to max?

Muplex:
Basically I want to verify the accuracy of a self-made arduino Due based oscilloscope.

Then you're completely off track. Scope calibration is done with precise square waves, not sine waves or any other kinds of waves. The UNO has no reliable time base, except for the clock of the 16U2 serial-USB device. The voltage is uncalibrated. So you have two problems even to generate a precise square wave, let alone a sine.

Hei guys,
thank you for your attention, but i'm not NASA :slight_smile: , sometimes I like to test and try just to do it and understand how the stuff works a little deeper, that is DIY approces!!!

Why you use arduino UNO? I use to discover new things and open my mind.
After all, there were many other sophisticated and reliable (and $$$) stuff out there!!

When I say TEST my "self made" oscilloscope, I ment draw a sine wave on a LCD that seems to be a sine wave...stuff like these...

Please do not hijack the topic on Why you are doing something....
To be honest one of the thing I wanna try is to draw very simple Lissagiouss curves (XY mode) with my self made oscilloscope and for me is a HUGE target draw it properly.
Doing that I discovered many new things about sinusoids, arduino timers, ADC/DAC and many other thing that for me (junior chemical engeneer) is not a part of my daily work or backgroud.

Sometimes (i'm sure of that) your first prototipe sucks but working on it you are able to find a good compromise on what you want and what you can do with your budget isnt'it??


After that,
I came back to my first topic question:

Is there a way to generate Two freq. variable Waves on two pins of an arduino UNO ??

I try these two ways, without success:

  1. SPWM have strong limitation due to the internal arduino's Timers. I'm able to create a Single Wave, but not two

  2. R2R DAC Ladder requires a lot of pins for a 8bit wave + 1 rotary encoder = Not enought Pins....

Do you know some other way to explore?

I was thinking; maybe ArduinoMega is suitable for SPWM because the larger numer of pins and timers?

Horace give me a good IC component to achive the target.

Thank you all for your effort,
best regards.

Muplex:
Please do not hijack the topic on Why you are doing something....

This is really an unfair evaluation. The reason I ask such questions (reference reply #1) is to narrow the scope of the question. There are really so many different ways that your project could be made, each one with different specifications and performance... without being inside your mind there is no way to know what your targets are without asking.

In the reply to my first question, you continued to focus on the oscilloscope aspect. You should hardly be surprised if the following answers focused on that. Right up through and including your reply #11, you continue on the same tack. We do not discover your actual motives until your reply #15. That I didn't know until then, is thus not my fault. Also, thus, it is no kind of hijack.

Now that I know your true aims, I have some suggestions. But after being gunned down, I think I'll pass.

aarg:
This is really an unfair evaluation. The reason I ask such questions (reference reply #1) is to narrow the scope of the question. There are really so many different ways that your project could be made, each one with different specifications and performance... without being inside your mind there is no way to know what your targets are without asking.

In the reply to my first question, you continued to focus on the oscilloscope aspect. You should hardly be surprised if the following answers focused on that. Right up through and including your reply #11, you continue on the same tack. We do not discover your actual motives until your reply #15. That I didn't know until then, is thus not my fault. Also, thus, it is no kind of hijack.

Now that I know your true aims, I have some suggestions. But after being gunned down, I think I'll pass.

+1 for that.

aarg:
This is really an unfair evaluation. The reason I ask such questions (reference reply #1) is to narrow the scope of the question. There are really so many different ways that your project could be made, each one with different specifications and performance... without being inside your mind there is no way to know what your targets are without asking.

In the reply to my first question, you continued to focus on the oscilloscope aspect. You should hardly be surprised if the following answers focused on that. Right up through and including your reply #11, you continue on the same tack. We do not discover your actual motives until your reply #15. That I didn't know until then, is thus not my fault. Also, thus, it is no kind of hijack.

Now that I know your true aims, I have some suggestions. But after being gunned down, I think I'll pass.

Hei, i dont aim at you at all, indeed I answer your absoluttely legit questio but I was surprised from post #10, #12 and #14 especially.

Muplex:
Basically I want to verify the accuracy of a self-made arduino Due based oscilloscope.

For sure I can buy some low cost device, but my approche is DIY...

I can give you a working code for a Due as generator (because it has two DACs)

int8_t x ; 
int8_t y ;

void setup() {
y= 114; // put less to change amplitude but not less than 64, else it will deteriorate the sine quality
        // 114 gives 2v PP and 0.70V RMS, which is 10dB
 // Serial.begin (9600);        // to test show on serial (jeopardizing frequency, obviously)
}

void loop() {
x += (y / 4);
y -= (x / 4);
// printf ("%i  %i \n", x , y ); // to test show on serial
delayMicroseconds(1);   // put anything to slow down the sinus (10 will give 2KHz, 29: 1,02KHz, no delay: 4,23 KHz)
//analogWrite(DAC0, x + 127);
//analogWrite(DAC1, y + 127);
}

You will not find a faster sinus/cosinus code...

P.S. a scope with a Due is not a very good idea...

P.P.S. if you just want to test your skills to draw a sine on LCD (having no DAC/ADC) this is the right code for you...