# Computing stuff tied to the physical world

## A better sine wave

In Hardware on May 20, 2012 at 00:01

After the pretty bad sine wave trial of the last two days, it’s time to try another circuit:

This is a “Phase Shift Oscillator” from the same op-amp book as the other one. I used half a TLV2472.

This one is actually a bit simpler to explain: the op-amp is set up with 25..50x amplification, i.e almost a comparator (with 50x amplification, a 50 mV input above or below the 2.5V will drive the output to its limit). And indeed, the output signal of the op-amp looks somewhat like a heavily clipped sine wave:

The 3 resistors and 3 capacitors create 3 RC “low-pass” filters in series, removing all the higher frequencies, i.e. harmonics. A fairly clean sine wave comes out at the end, as you can see here:

The only problem is that the signal level has been reduced from a ±2.5 V level to ≈ ±65 mV, a 40-fold reduction!

So the op-amp itself has to amplify that level back up to produce the clipped ±2.5V signal again.

The frequency is determined by “phase shifts”. Each RC filter changes the phase of its input signal, and it will be by 60° at a certain frequency, so that 3 of them in series will then shift it by 180°. Since the signal is fed back to the “-” pin of the op-amp, that’s exactly the proper signal to generate the opposite output, i.e. shifted 180° out of 360°. This analog stuff gets complicated – don’t worry too much about it: just pick R and C values to get the right frequency, and make all of them the same.

I used 0.1 µF caps i.s.o. 10 nF caps, i.e. 10x larger than the original circuit. With these values, the oscillation in my setup turned out to occur at just about 440 Hz, i.e. a pure musical “A” tone!

I did have to increase the gain (1.5 MΩ / 55.2 kΩ = 27 in the above setup) to force oscillation. I changed RF to 1 MΩ and RG to 22 kΩ, for a gain of 47. This RG value is a bit low, it loads down the last RC section quite a bit.

What you’re seeing here is a classical example of a negative feedback loop, which ends up in a very stable state of oscillation. It oscillates because we’re delaying the feedback signal by about 2.27 ms through the RC chain. So the op-amp constantly overshoots around its mid-point (the 2.5V applied to the “+” input), but does so in a very controlled way. The amplitude can’t increase any further, since the op-amp is clipping at its limits already, and the amplification factor is large enough to keep boosting the swing up to that limit. You can see the startup ramp and stabilization when powering up:

Here’s the FFT spectrum analysis of the generated sine wave:

A clean signal compared to the previous experiment. The 2nd harmonic is ≈ 42 dB below the fundamental wave, the rest is even lower. Using this calculator, we can see that this represents about 0.8% harmonic distortion.

The only issue is that the signal is much weaker than the ±10V needed for a standard Component Tester.

But hey, let’s declare success for now – we’ve got a clean sine wave!

1. Glad you got a working sinewave circuit! It seems easy enough to use another opamp stage to get whatever level output you need, I assume you’ll be using a separate driver anyway if you need significant current.

• Coming up!

2. Not sure if this has been suggested before but in one of my classes we produced a pretty clean sine wave from a 50% duty cycle squarewave by just using a resonant filter tuned to the fundamental frequency. In my case I used an LRC circuit but active filters work too.

• Yes, @Rubi also suggested this yesterday.

I was thinking of trying that out as well, but you need a low-pass filter with about 20 dB/octave roloff to get the third harmonic 40 dB down, if I understand things correctly. Doable, but it might be slightly more complex than this analog sine wave generator. If more than 1% distortion is ok, then I guess a one-opamp active filter (12 dB/oct) would be good enough.

Yet another approach would be to use a switched-capacitor filter – then you can digitally control the filter frequency and make the whole thing adjustable over a wide frequency range.

It’d be worthwhile trying out a few approaches starting from a square wave, just to see how things compare.

(off the record: I was also looking for an excuse to sneak some op-amp circuits into this weblog :)

3. I still say to use a Wien-bridge oscillator – good designs achivev about 0.0015% THD and the best designs are down in the 0.0003% THD range. (The latter is very hard to measure!) See the discussion starting at page 29 of http://cds.linear.com/docs/Application%20Note/an43f.pdf for lots of good information on how to design such a beast. (The tried-and-true lightbulb design is guaranteed to drive you crazy with microphonics, by the way; don’t waste your time on it unless curiosity trumps convenience.)

• Yes, I’ve read that article by Jim Williams (and many more) – fascinating! But I’m not after that level of purity here. Lamp control has been around for a long time, but lamps are harder and harder to get. The above circuit appears to have good frequency and amplitude stability, and low enough distortion.

4. Sorry to reply to my own post, but “Click to Edit” is coming up blank…

Anyway, I was just rereading that paper – it’s a classic – and I realize that I forgot to mention that figures 47 and 48 are interchanged. Might help avoid some confusion.

5. The 8038 IC is one I’ve used in the past, but I see it’s now obsolete. Perhaps someone can suggest a replacement?

David, GM8ARV

6. An interesting mechanism is visible in the first ‘scope trace. The TLV2472 is a ‘rail-to-rail’ output device, but in practice these designs can only approach the rails with dramatic shifts in gain in those regions. Note the asymmetry of the recovery. The positive case shows a short almost vertical section, the negative maintains gain better in recovery, which gives a better fit to the expected straight integration line.

How does this reflect in the performance? These artifacts cannot be removed by the filtering action of the RC ladder, some vestiges are there in second ‘scope trace. This makes the waveform asymmetrical about the x-axis; Fourier transform theory tells us that this generates even harmonics – a major contributor to the size of the F2,F4 spikes shown in the FFT.

This is different from the DC offset that is also present – that simply moves the whole waveform up or (in this case) down the y-axis. The offset at -1.60mV is significant (-14dBV) compared to the 44.46mV RMS of the waveform. Does this affect the signal purity?

It is visible in the FFT – to the left of the main peak at F1, you can see an F0 signal overlaying the white y-axis line. That is scaled in dBm, so converting -14.45dBV gives -28.9dB below the power of the whole signal. Most is carried by F1 at -15dBm, hence predicting a value ≈ -44dBm. The trace shows about 44-45dBm.

However, this does not directly affect the signal purity – F0 is DC. Intuitively this makes sense. DC can be removed with a simple blocking capacitor without changing the shape of the waveform.

7. @GM8ARV, for 8038 functional replacement, try XR2206 or AD9833.

• “for 8038 functional replacement, try XR2206 or AD9833”

Thanks, Martynj. I’ve bought a couple of evaluation boards from a well-known auction site for the AD9850, and controlled them via an Arduino Nano. Somehow I had thought of them more as RF rather than audio devices.

8. Really nice read, thanks for the posts! I’m learning electronics with the 6002x online course from MIT, and it’s nice to see some practical applications of what I’m learning — just yesterday I was learning about phase shift in RC circuits.

I have one quick question: what oscilloscope do you use for those measurements/plots? I’m playing with some circuits at home and I feel more and more the need for an oscilloscope, using the old multimeter I inherited from my father can only take me so far when trying to understand circuit behavior.

Thanks!

9. A variation on this circuit is described in an article by David Griffiths in the February 1996 issue of Electronics World. He uses a dual OPAMP. The first section is arranged to have a non-inverting gain of about 15, and amplifies the output of the last stage of the 3 cascaded R-C sections. This provides a low impedance, high level sine wave output. Oscillation is sustained by the second OPAMP, acting as an inverting comparator. Its output (a rail-to-rail square wave) drives the first R-C section, and it’s input comes from the output of the other OPAMP.

The amplitude of the oscillation is set by the output levels of the comparator. The 3 R-C stages filter out most of the harmonics leaving a reasonably low distortion sine wave – about 2.5%, mainly 3rd harmonic. The amplifier gain is chosen to give an almost rail-to-rail swing, but without clipping. The comparator provides the extra gain to make the loop oscillate. He suggests AD822 or LMC660 devices. His design is single rail, but you will need to use a dual supply for your component tester application.

By the way, both this circuit and the quadrature oscillator require all the capacitors to have the same value for correct operation. Mismatched values alter not only the frequency of oscillation but also the loop gain. I notice you were using Z5U ceramic capacitors: these have wide tolerances and large temperature coefficient. This is probably why people were having trouble getting the quadrature circuit to oscillate. The phase shift oscillator as you tried it doesn’t suffer from this problem as it has plenty of loop gain – which is why you get a clipped output.

• Thanks – hadn’t realized that the cap tolerances could make such a difference. Tomorrow a post about a second op-amp to get the output signal to ±10V. I don’t know which would work better: the extra op-amp inside or outside the feedback loop. I’ll see if I can experiment with this a bit more.

• I’m looking at my original (paper) copy of the magazine. The magazine website doesn’t have an archive, but apparently there are some paper backnumber copies still available. I don’t know if they have this issue.

11. @jcw – If the amplifier is inside the feedback loop, it can be non-inverting, instead of inverting as in the circuit you used, because the necessary phase inversion for oscillation can be provided by an inverting comparator. In your circuit, the inverting amplifier’s 55k2 input resistor loads the R-C network, which limits the maximum usable value of R. A non-inverting amplifier has no input resistor so doesn’t have this loading effect. The input bias current is supplied through the network resistors.

The key point is that the R-C network is being used to filter out the harmonics from a fixed amplitude square wave, so the signal at the amplifier input is at a known level, hence the gain to get a full scale, but non-clipped sinewave is also known.

• Ok, perfectly clear! Would the use as comparator explain the THD difference too? The signal above is, eh, “closer” to a sine wave, so the 3 RC filters end up with a slightly lower THD sine? Not that it matters – I like the idea that your suggestion exactly controls the amplitude.

But now I have to wonder: given the presence of an MCU with square wave capability, I might as well use a digital signal + 3 RC’s + output buffer op-amp, right? That would give me slightly more control over the exact frequency, and then a trimpot to adjust output to ±10V?

12. @David, GM8ARV – Fancy meeting you here! Last time we were in touch was when you were developing SatSignal & I had modified the RX-2 receiver for serial control. Years ago now!

• Max, greetings. I still use the modified RX2 for receiving the analog APT weather satellite signals with your computer control modifications and SatSignal for decoding, but for many in Europe, digital data from the EUMETCast system is now their prime source.

http://www.satsignal.eu/wxsat/atovs/index.html

13. @jcw – Yes: since the signal your circuit feeds into the R-C network contains fewer harmonics than a square wave, the filtered output is lower distortion. But the amplitude is not so well controlled.

You certainly can use a square wave driving a low-pass filter to get a similar result: but as you noted the component tolerances mean you will need to trim for amplitude – or you could digitally adjust the frequency for the same effect. You can probably get even lower distortion by using the R’s, C’s and OPAMP to make an active filter with a sharper cutoff, but again this must be tuned to match the square wave frequency.