# What's the easiest/cheapest variable-frequency sine wave oscillator?

A Google search will give you a few billion ideas. Which is the simplest/easiest/cheapest that you know of?

Generating a square wave and then filtering out the harmonics isn't a good solution unless the filter frequency can be varied along with the square.

• What frequency? – Leon Heller Aug 8 '10 at 4:50
• Audio frequencies, I guess – endolith Aug 8 '10 at 22:45
• easiest and cheapest are typically opposint parameters ;) – vicatcu Aug 9 '10 at 17:33

Making a numerically controlled oscillator (NCO) with uC + DAC is very easy. Could be a fun FPGA project. An advantage to an NCO is that you change waveforms.

I did a low frequency numerically controller oscillator Arduino sketch (see http://wiblocks.com/docs/app-notes/nb1a-nco.html). At the bottom of the webpage are a couple of references to the original articles,

• There are some pitfalls to generating waveforms digitally, so you need to design the firmware well to produce low-distortion waveforms, but that goes for analog circuits, too. So relatively, this is cheap, simple, and easy. :) – endolith Nov 23 '10 at 20:56
• At the bottom of the page there are references to the original articles published in the Computer Music Journals. These discuss the trade-offs in S/N. – jluciani Jan 3 '11 at 11:58
• My 'advanced' uP class in college had this as an exercise in ASM on the 8051. The project was called waveform generator and we had to do a ramp, sawtooth, and sine wave. I recommend it as a learning exercise but don't do it in ASM =P – NickHalden Jun 15 '11 at 14:15
• Use dither to keep distortion down, and if you're generating anything other than sine waves, use bandlimited synthesis methods to avoid aliasing. It's not trivial to make good quality signals. – endolith Oct 14 '14 at 14:28
• The link seems to broken (wiblocks.luciani.org: 4003). Can you provide the essential part here (e.g. a schematic and the principle(s) it is based on)? – Peter Mortensen Feb 2 '18 at 22:45

Wien bridge with a pot to vary the frequency. I bet you could build one for less than one US dollar.

• You should clarify that you need a dual element potentiometer to do this, and I'm not sure you can find those for much less than 1 US dollar. The circuit requires that R=R1=R2 (And C=C1=C2). Also, the gain needs to be controlled so that oscillation will continue, see this page for more details: ecircuitcenter.com/circuits/opwien/opwien.htm – Kevin Vermeer Aug 9 '10 at 13:40
• A good point, Nivek. I might suggest a dual digital pot like the Maxim MAX5496 or the Analog Devices AD5235, but that definitely increases the cost by two or three dollars. I suspect that there is also a way that you could use a current mirror made from some BJTs to make one pot do double duty, but I'll leave that attempt to someone who really knows what they're doing with analog stuff. – pingswept Aug 9 '10 at 14:07

You didn't specify the frequency (100Hz or 100MHz?) or how much the frequency had to be varied (0.01% or 1000% ?) or whether the frequency had to be varied by a voltage or a physical knob. Purity of sine wave and stability matters too.

A one-transistor FET Hartley oscillator is hard to beat for cheap.

You could also PWM or otherwise DAC values out of a table to produce sine waves. Then the filtering should be easier. A very cheap MCU could probably do it up to fair frequencies.

I might second some RC + opamp design in principle. Whether the output and adjustability suits you depends on the application.

There are also some function generator IC's, ranging from classic 8038 to various complex DDS thingies. They might not come that cheap, though.

I guess there's also the option of finding an affordable second hand lab signal/function generator. It might be a long search for a cheap one, but it's all relative. Or you could take a spare AC generator and turn the shaft with variable speed. Amplify for power/impedance/voltage :)

Cheapest DIY DDS signal generators (including sine wave):

http://www.myplace.nu/avr/minidds/index.htm

http://www.scienceprog.com/avr-dds-signal-generator-v20

You can still do it with a square wave and filtering out the harmonics. There are a number of high order filters that can be controlled with a microcontroller easily. This one allows the user to control the corner frequency with an outside clock (second square wave from the micro). Because of the large corner frequency to clock frequency ratio you could even do it without the need of another timer/interrupt with a simple software counter...

• If you're using a microcontroller, I would think PWM output would be simpler. Then you only need a simple fixed-frequency filter. – endolith Aug 9 '10 at 14:52

If you want to go the direct digital synthesis route with discrete chips, capacitors, etc. the result won't be nearly as compact as what could be done with a CPLD or micro, but would be pretty reasonable, especially since a significant amount of the circuitry could be shared among the five signal outputs.

Global signal generation requirement:

• Input clock source
• 12-bit counter (74HC4040)
• 14 inverters (3 of 74HC14, leaving 4 gates open)
• 13 small-signal capacitors
• 13 resistors

Per-output requirement:

• 13-input NAND gate (74HC133)
• 12-bit counter (MC14521 or CD4521)
• Lots of jumpers to set frequency

More details to follow. Given an input of 4,096,000Hz, the circuit should be able to produce square-wave outputs from 2KHz to 512Khz in multiples of 0.5Hz for signals up to 2KHz, 1Hz for signals up to 4Khz, etc. Other techniques can be used to convert a square wave thus generated into a sine wave.

Here's a circuit diagram to show the concept:

(HERE)

This circuit includes a configurable frequency generator (5 switches select input frequencies from 1/16 of the input up to 31/16 of the input). I also threw on a rough square-to-sine converter. Note that unlike most filtering techniques, this one maintains a reasonably consistent amplitude over the frequency range. The wave is quite rough because the above circuit only uses 4-bit counters. The MOSFETs would be replaced in practice by 4066 pass-gates (4 per chip).

Triangle oscillator with a triangle to sine converter.

• Are you being charged per-character by your ISP? I kid, but you could probably develop this answer a bit further... – Kevin Vermeer May 4 '11 at 13:57
• @Reemrevnivek, I had to rush to go to college, and had 2 mins to type out that answer... 1.5 mins of that were finding the link to what I wanted. – Thomas O May 4 '11 at 16:55