Loading...
Pages: 1 [2]   Go Down
Author Topic: Arduino DDS Sinewave Generator  (Read 10121 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Came across this utility/routine for the Arduino, looks great.  I am still digesting the program as I have very basic knowledge of C language and specifically some of the commands used in this routine.

My question is this;
I would like to modify this to be able to generate 2 sine wave outputs, same frequency, but one of the sine wave needs to be shifted 90 degrees from the other.  Can it be modified for this?  Some help in finding where explanations of all these particular commands could be found would be useful.  I imagine that the commands to drive the second sine wave would need to be contained in the interrupt service routine.

I think I should be able to use the same sine value table but shifted by 64 values for an out of phase wave of 90 degrees.
Thanks for any help.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can't you just maintain two table pointers 90 degrees out of phase, and do the summing in the ISR?
(watch out for unsigned arithmetic summing the samples)
It would limit the highest frequency you could generate.
Or, if the two signals are always the same amount out of phase, simply generate a single lookup at compile-time.
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL nailed it.

As mentioned above, just initialise the two phase accumulators with 0 and 16384 (pi/2).

The rest of the DDS is the same...
Logged

Arduino sound Reseach - http://bit.ly/fullmaj [fr][en] | Homemade Free VST - http://zomg.zxq.net [en]

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the suggestions.
I got it working just as hoped.  I simply initialized the second PWM output then created a second sine table lookup pointer that is shifted by -64 bytes, which generates the same wave but phase shifted by 90 degrees.  Awesome.  My project can now move ahead.
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 302
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A question for those who used this code ( And apologies if some of the question might sound silly, but my issue will be more to do with the hardware).
Would i be feasible to transform this code to  also modulate the signal, using an input ( from a pot, lets say) to influence the speed of modulation ( a LFO, lets say) ?!?
I notice there is a pot...Is that pot influencing the frequency ?!?
Always found this code interesting, but only more recently im getting to grips with the hardware features and limitations.
My aims are low frequencies, audio based anyway. By the way, what would be the limitations of this, as is ?!( I noticed the ook-up table issues for higher frequencies etc)
*PS-GOT IT
Quote
The frequency range reaches form zero to 16 KHz with a resolution of a millionth part of one Hertz!


Thanks in advance and many thanks to the original programmer above all !!
« Last Edit: June 02, 2012, 04:17:43 am by iyahdub » Logged

10 LET Loop=Infinite
20 GO TO 10

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it would be easy to use a potentiometer.  Since the program requires that you specify a frequency value, you can read the pot and use that value to specify the frequency to generate.  The original program used a pot for this very purpose.  I took this out of the code as I needed specific digital frequency values entered by the user.

Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Late reply but hey...

The answer to the question is : probably yes, but not sure at all. Let me explain : LFO, modulation and so on, those require multiplication at which Arduino does not excel at. Multiplication take several clocks depending on what you are doing, and this definitely makes the point.

44.1kHz clock means... one sample every 22 micro second.

You roughly have 18us to do the job, so the math of your modulation shall not be too big, indeed.

Hope this helps.
Logged

Arduino sound Reseach - http://bit.ly/fullmaj [fr][en] | Homemade Free VST - http://zomg.zxq.net [en]

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I added a TI 5515 DSP which sped things up a bit ..
Logged

Pages: 1 [2]   Go Up
Print
 
Jump to: