Computing stuff tied to the physical world

Generating a sine wave

In Hardware on May 18, 2012 at 00:01

After the recent pretty disappointing results with a transformer-based Component Tester, I’d like to try and generate a ± 10 V sine wave at approximately 50 Hz in some other way. Using as few components as possible.

This is where we enter, eh, squarely into the analog electronics domain. Yes, we could generate it with an ATmega, but frankly that sounds like a bit of overkill, would require a fair amount of filtering to remove residual switching effects, and besides we’d still have to amplify it up to 10 Vpp.

Time to introduce some new circuitry!

One of the most incredible electronic building blocks invented in the second world-war era was the Operational Amplifier, or “op-amp” in short.

There’s way too much to say about this amazingly universal circuit, which even has its own schematic symbol:

180px Op amp symbol svg

A positive and negative power supply pin, a positive and a negative input, and an output pin. That’s it.

I’ve only just started exploring op-amps, really – one superb resource on the web comes in the form of a free eBook from 2002 on the Texas Instruments site, titled “Op Amps For Everyone”, by Ron Mancini.

In his chapter on Sine Wave Oscillator, he mentions a “Quadrature Oscillator” built from two op-amps:

Screen Shot 2012 04 18 at 01 08 17

It uses very few components. This one was dimensioned for about 1.6 KHz, so I started with capacitors ten times as large, i.e. 0.1 µF, to lower the oscillation frequency. Here’s the result, using a TLV2472 dual op-amp:

DSC 3056

Powered by a supply of ±2.5V (i.e. 0 / 2.5V / 5V), I see this result on the scope, when attached to the sine output:


Yeah, right. Clipping like crazy, i.e. overshooting into the limiting 0V and 5V power lines. The FFT shows it’s not anywhere near a pure sine wave, even though the shape vaguely resembles one:


A pure sine wave would have a single peak at the oscillating frequency.

Here’s the cosine output, again showing that it’s running way outside its linear range:


So yeah, we’re generating a 160 Hz signal, but it’s no sine wave and it would be useless as Component Tester.

Oh well, it was still an interesting first trial!

  1. Hmm. Looks quite good here, just tried it with an LM358. With 10k resistors, 100nF capacitors and two 330R resistors for getting V/2 I get a clean sine wave of about 170Hz. Cosine looks also nice on my Rigol, X-Y shows a nice circle. After some minutes of measuring though, the amplitude of the signal slowly faded to zero, and now it doesn’t even start to oscillate at 5V. Raising the power suuply to 7V seems to fix that. Will have to have a look what could cause that…


    • Great – check this page for a comment on how to make it oscillate better. This probably also explains what I saw: a very brief oscillation, dying out within a second.

    • Indeed, adding a 100 kΩ resistor in parallel with R2 kicks things into oscillation here and produces an excellent sine wave – only 0.6% harmonic distortion! Only trouble with this circuit is that the amplitude isn’t stabilized – it’s all over the map. This can be solved by adding 2 1N4148 in anti-parallel over the first op-amp, then the amplitude “sort of” stabilizes around 0.7V (still a 10% swing), a perfect circle on the scope, but its size varies!

  2. For me, a 220kΩ resistor in parallel with R3 worked for making it start better, but the sine wave is a bit flattened at the top then. This seems to get better the higher the resistance of the parallel resistor is – but then it won’t start all the time. But the amplitude is stable here as long as the power supply voltage is constant.

  3. one classic solution to stabilizing the output of a low-distortion sine-wave oscillator is to use a relatively long-time-constant nonlinear resistance in the form of a light bulb! For example, the last page of this app note:

    or a simpler version here:

  4. Using zener diodes across the second op amp will improve the level from 0.7v, but this topology can’t really be tamed without some form of AGC as suggested by jbeale.

    More ‘modern’ control loop designs use a FET as the controlling element – audio purists claim that the 60′s signal generator/THD distortion meter designs with a tiny thermistor in an evacuated tube get the cleanest results. Unfortunately, this component is no longer manufactured.

  5. A light bulb is a nice cheap variable resistance – and I used that design for years – but it’ll drive you crazy with microphonics. Martyn may be right that the 1960′s isolated-thermistor gives the best results, but I’ve seen those claims advanced chiefly by audiophiles who also make ridiculous claims about other components. (I’m sorry, you don’t get a “warmer” sound with heavier-gauge digital interconnects!)

    There’s a really good discussion of gain-stabilized sine-wave oscillators at – that whole document is a classic of analog design.

Comments are closed.