Go Down

Topic: Arduino DDS Sinewave Generator (Read 23 times) previous topic - next topic

BitChanger

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.

AWOL

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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

D4p0up

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...
Arduino sound Reseach - http://bit.ly/fullmaj [fr][en] | Homemade Free VST - http://zomg.zxq.net [en]

BitChanger

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.

iyahdub

#19
Jun 02, 2012, 11:11 am Last Edit: Jun 02, 2012, 11:17 am by iyahdub Reason: 1
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 !!
10 LET Loop=Infinite
20 GO TO 10

BitChanger

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.


D4p0up

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.
Arduino sound Reseach - http://bit.ly/fullmaj [fr][en] | Homemade Free VST - http://zomg.zxq.net [en]

moxy

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

vanashree

hi,
in my project i want to use dds with arduino for generation of desired frequency upon command in the range of 125 hz to 8khz and then also vary there amplitude (increase or decrease) upon command using a variable gain amplifier.I want this selection of frequency and amplitude to be done using computer i.e. generation of desired frequency and amplitude upon a click on computer.
Kindly suggest me a proper board and its cost in India.
Kindly reply as soon as possible.

NI$HANT

Quote
Kindly suggest me a proper board and its cost in India.
Kindly reply as soon as possible.


Well you just need a standard Arduino Deumilanove or uno etc clones out there remember that the code used is working with registers of an ATmega328 (ATmega168 and 88 will suffice too!) so lookon to have the arduino clone or original arduino which these chips, also you would needsomepassives to create the low-pass filter.

How to make it: The linkis here:

http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

????? ???? !

tjk3052

Hi. I have a question about this DDS sinewave generator. Why is Timer0 is disabled in the setup? I need to use the millis() function and it doesn't work without Timer0.

Code: [Select]

  // disable interrupts to avoid timing distortion
  cbi (TIMSK0,TOIE0);              // disable Timer0 !!! delay() is now not available
  sbi (TIMSK2,TOIE2);              // enable Timer2 Interrupt

dc42


Hi. I have a question about this DDS sinewave generator. Why is Timer0 is disabled in the setup?


Probably because if you don't disable it, the interrupt service routine for timer 0 that gets executed nearly every millisecond causes the DDS interrupt service routine to be delayed a little, and that spoils the purity of the signal.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

iyahdub

#27
Nov 16, 2013, 06:24 pm Last Edit: Nov 16, 2013, 06:36 pm by iyahdub Reason: 1
If you dont need much accuracy, you can count time using many other methods... Interrupts being one of them ?! If not, there is always the option of a real time clock chip  ?! Or the proverbial 32.768 kHz crystal, to keep the time? I think it depends how accurate you need it to be !

PS: Actually, the interrupt on the code is quite close... Every 31250  Clock Interrupts, will be  a second, 15625 half a second, and each interrup 0.000032  of a second... A millisecond will be 31.250(31+1/4) and 125 will, make exactly 4 millis...
10 LET Loop=Infinite
20 GO TO 10

hessaacd


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.



I want to do the exact same thing, which is to shift a second sine wave by 90 degrees. Can anyone provide the updated code to perform this? I'm having trouble figuring out what needs to be added.
Alan

vanashree

i have bought arduino uno borad. i found the attached file from arduino forum. but shows compling errors:
AD9835 doesnot have a name type.
and in the other file:
ad9835_forum_arduino.ino:4:22: error: WProgram.h: No such file or directory.
i want to program my dds kindly help this is urgent.
reply soon.
regards
vanashree.

Go Up