Go Down

Topic: Arduino Nano as a 4 channel Square Wave generator (Read 2021 times) previous topic - next topic

served

Hi.


I have one Arduino Nano.
And I would like to use it to build a 4 channel signal generator.
It should have one Frequency knob for each channel - I can use Analog Inputs for them. and 10k potentiometers.
It has to output 4 independent Square waves and each of them can be sepparately controlled by a frequency knob.

I would like to take the signal from PWM compatible I/O-s if its wise to do so. (maybe it is not)

My background is poor. I have not build anything huge with Arduino. Some very simple projects O-scope, some LED blinkers, one channel signal generator and something like that.

The main reason why I am writing is to figure out if Arduino Nano can handle what I am planning and to find out if anyone has an idea how to complete it.
Frequency will stay below 22kHz but it must  achieve it in all the channels.


johnwasser

The easiest knob input is a potentiometer connected to an analog input.  That will give you 1024 steps.

You didn't specify a lower frequency limit so I'll guess it's 0 Hz. 

To cover 0-22 kHz in 1024 steps you will need a step size of about 21.5 Hz.  Will that be OK?

If you go with an exponential scale (14+ octaves, 173+ semitones)  you can easily cover the range steps of  about 1/6th semitone.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

served

Hi. Thank you for your replay.

Do you feel that what I am trying to accomplish makes sense by using Arduino Nano? Is it fast enough.
For the O-scope I built, it was slow and didn't really work.

Grumpy_Mike

#3
Jul 12, 2012, 02:22 pm Last Edit: Jul 17, 2012, 07:02 pm by Grumpy_Mike Reason: 1
Controlling three frequencies is easy because the arduino has three timers. Four is difficult and you will have limited range and resolution. I have never seen a signal generator with four independent outputs why do you need that many?

johnwasser


Do you feel that what I am trying to accomplish makes sense by using Arduino Nano? Is it fast enough.


The Arduino executes about 16 instructions per microsecond so 44,000 pin changes per second (22 kHz) allows for 363 instructions per pin change or about 90 if al 4 at once are doing 22 kHz.  Shouldn't be much of a problem.

It would be great if the Arduino had four spare timer/counters.  They could generate the square waves in hardware and require very little programming.  You are going to have to do most of your four oscillators in software. I think your best bet is a timer set to interrupt very frequently, like every couple of microseconds.  Then use a software counter for each oscillator to count off the ticks per half-cycle.  Use direct port access to toggle the output pin because digitalWrite() is going to be too slow.

You might try the BlinkWithoutDelay trick only using micros() instead of millis().  The  You can toggle an output pin very quickly by writing a 1 to the bit in the PIN register for the port:
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

served

So I was messing around a bit.

I got it running with Delay function. But this led us to a problem. It only makes one sound at a time, but now its clear how to use Analog inputs and how to define Digital outputs.

I think that if using PWM would not lead us very far, because I can only divide the fequenzy with certain numbers, but I need it to be smooth.

What I am planning to do is a 4 channel wave generator. And it can be 3 channel if 4 is difficult. I can leave that pin for some extra feature it doesn't matter.

Can some one help me a little?
Maybe could you write me a guide of topics I should read before I can step into this.


Grumpy_Mike

As you slowly reveal more information you get better answers.
It is quite frustrating when people do this. A signal generator is a totally different thing to an audio oscillator.

So you want to make a four channel audio oscillator.
How do you want to control the frequencies?
What waveform do you want from it?
What frequency resolution do you need?
What frequency range do you want?

served

Hi.

Actually, its very close to audio oscillator. I am using sound to observe my progress. Because this is the equipment I have on my table.



I would like to use just a regular 10k potentiometers connected to A0 A1 A2 This should be all.

The form of a wave is not importand. Square was my initial idea as I can do what ever I want with it in hardware and square should be the easyest to achieve.

Resolution it can be 1-0 signal, it doesn't matter.

The range should stay in audioble range as I would need a o-scope to measure higher fequencies and it should be enough for a start.



Grumpy_Mike

I asked:-
Quote
What frequency resolution do you need?

you said:-
Quote
Resolution it can be 1-0 signal, it doesn't matter.

In what way is that an answer?

Frequency resolution means how fine a control on the frequency do you want.

Have you considered:-
http://little-scale.blogspot.co.uk/2008/02/simple-polyphonic-synth-with-just.html
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264923106
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264923106/15
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=print;num=1272512876

johnwasser


As you slowly reveal more information you get better answers.
It is quite frustrating when people do this. A signal generator is a totally different thing to an audio oscillator.

So you want to make a four channel audio oscillator.
How do you want to control the frequencies?
What waveform do you want from it?
What frequency resolution do you need?
What frequency range do you want?


> How do you want to control the frequencies?
   He said that in the original post:  "one Frequency knob for each channel"

> What waveform do you want from it?
   He said that in the original post: "output 4 independent Square waves"

> What frequency resolution do you need?
    Good question!

> What frequency range do you want?
   He gave the high end in the original post: "Frequency will stay below 22kHz"
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

served

Came back from reading some more info. And I am starting to see what I need.

> What frequency resolution do you need?
I could have ca 20Hz step but lets build it the way its reasonable.

> What frequency range do you want?
First I would like to have a range from 100Hz to 5kHz.
This should cover my need.

As I have been messing around with it more and more. The only issue I seem to have is how to get the signal out from multiple ports simultainously and how to control each output same time with different pots.

I am sorry if I am being such a hard time. Is probably caused by my enthusiasm and luck of knowledge. Till now I have been mainly working with analog electronics only. And its really easy to build such a thing with 555 or 556 chips. But Arduino feels far more interesting at the moment.

Grumpy_Mike

Quote
The only issue I seem to have is how to get the signal out from multiple ports simultainously

The simplest way is to connect the outputs together through a resistor on each line. This acts as an audio mixer.

Quote
how to control each output same time with different pots

Each output will be controlled separately. That top link I posted you looks like your best bet.

served


Quote
The only issue I seem to have is how to get the signal out from multiple ports simultainously

The simplest way is to connect the outputs together through a resistor on each line. This acts as an audio mixer.

Quote
how to control each output same time with different pots

Each output will be controlled separately. That top link I posted you looks like your best bet.



Now I need to figgure out how to use the link you posted :D
The code is written in unfamiliar way, so modding it is difficult for me currently.

Grumpy_Mike

This any better for you?
http://www.jeremyblum.com/2010/09/05/driving-5-speakers-simultaneously-with-an-arduino/

Quote
The code is written in unfamiliar way

You are wanting to do something that involves using timers so it will not look like conventional C code. This is because in order for it to work you have to tap into the hardware resources of your chip and do things like direct port access, bit manipulation and accessing machine registers. All of which take some learning.

Go Up