# Possible to output sinusoidal signal with an Arduino?

Is there a way to output a sinusoidal wave with an arduino? Perhaps using PWM? It would be nice to be able to simulate something around 10kHz. Is this even possible with the hardware on the Uno?

-

Yes, you use a low pass filter combined with PWM. The lower the duty cycle the lower the value of your output. So you modulate your duty cycle like a sinusoid and pass the PWM output through a LPF. The output of the LPF will then be a sinusoidal waveform, though it will have a DC offset.

-

Look for DDS (Digital Direct Synthesis) which uses a low pass filter as mentioned in the other answers:

It then uses a varying PWM signal to create a sine wave:

All you need in order to implement it with an Arduino, including the source code for the PAM generator, can be found in this article.

-
right on, they claim to be able to generate up to 16kHz sine waves... not too shabby –  vicatcu Sep 20 '12 at 4:09
Other than PWM + Low Pass Filtering, another way is to use an R-2R ladder DAC, and drive the output with a PORT. But you're not going to get much frequency out of it using the digitalWrite function. Like I said, at a minimum you'll need to do direct port assignments.
digitalWrite() won't provide the frequency for the R-2R ladder? Is it capable of doing so for PWM + low pass filtering method, or is there a limit on the frequency digitalWrite can operate on? –  Joshua Jefferies Sep 20 '12 at 3:06
digitalWrite() is very very slow... and is a well-documented "issue" with the Arduino core. There's been a lot of discussion surrounding it on the developers mailing list of late. It's unsuitability for the R-2R ladder is that you would have to set each pin with a separate call instead of changing the R-2R ladder's control points all at once. You could use it to do "soft" PWM, but again, at very slow speeds as compared to the hardware PWM (i.e. using the hardware timers as is done in the analogWrite() function) –  vicatcu Sep 20 '12 at 4:06
And the analogWrite function is itself only at 490 Hz, right? So that means neither are a valid option for the speeds we need... (Or am I mistaken?) –  Joshua Jefferies Sep 20 '12 at 4:11