Electronics

Squashed triangles: sines, but with teeth?

[ad_1]

A while ago, I needed (or wanted) a pocket-sized audio sine-wave generator: simple, stable, repeatable, single-gang control pot, 9V battery-powered. A “squashed tri-wave” approach looked appropriate. While the principle is easy—make a triangle wave, feed it into a pair of back-to-back diodes through a resistor, take the sine(ish) wave from the diodes and amplify it—the drive level and the resistor value both proved to be critical. It worked well enough to set me wondering what the limits were: just how closely can we approximate a sine wave like this?

Wow the engineering world with your unique design: Design Ideas Submission Guide

This DI, which I have kept practical and largely non-mathematical, takes my original concept and refines it further, perhaps complementing the recent DIs on oscillators, for example here and here.  We’ll take it stage by stage, starting with triangle generation, continuing with the squashing, and then tidying up whatever other error sources we can.

First test circuit

Initially, I had planned to model things by calculating the voltage across a resistor-fed diode for a linearly-increasing feed, comparing that with the corresponding sine values over a single quadrant, looking at the differences, and iterating until the optimum values for the feed voltage and the resistor appeared.  However, this Wikipedia article disillusioned me, instructive though it was; it also explains the workarounds that SPICE uses. A real-life approach was needed which is often more fun, anyway.

My original starting-point was the well-known oscillator shown in Figure 1, which effectively combines an integrator with a Schmitt trigger. RT and CT are respectively the tuning resistor (variable) and capacitor (probably switched).

Figure 1 A basic oscillator that effectively combines an integrator with a Schmitt trigger.

When the op-amp’s output is high, CT charges through RT until its voltage reaches a trip point given by the ratio of RF1 to RF2, driving the output low, thus charging CT in the opposite direction until the opposite trip point is reached, and repeating indefinitely. Thus, the output is a square wave, with an exponential tri-wave present on CT. While the duty cycle is exactly 50% and the operating frequency is stable with supply variations—assuming balanced power rails and a rail-to-rail op-amp output—neither square nor exponential waves are much use for generating sines, especially when their amplitudes depend on the supply. (My original design spec was for a PP3/6LR61 battery, giving about 9V—or ±4.5V—when new, and a lot less when not.)

A different approach was needed, and Figure 2 shows the core of the new circuit. (Assume balanced +/- supply rails.) I had wondered if the best level for the tri-wave might be exactly one diode-drop each way, and if we could define everything in terms of a diode’s forward voltage (VF): that was the germ of the idea, and now of this DI.

Figure 2 Simple, novel tri-wave generator and sine converter.

In effectively combining the generation of the tri-wave with its conversion to a sine wave, first-order errors could be eliminated, so minimizing frequency changes with supply voltage and temperature, and allowed final trimming to between 0.7 and 3% THD depending on the frequency. There are other ways of arranging the same elements to get the same results, but this one minimizes delays and so works better. We’ll be improving it further, later.

First, we replace RF2 with a pair of diodes, D1 and D2, so that the trip points are defined by their VFs, the voltage on CT now swinging by ±VF. Next, we add bootstrapping to linearize the waveform. (This DI shows another application of this technique.) RT is driven by a buffered copy of CT’s voltage plus/minus the voltage across D3/4, so the voltage across it is always 2VF, giving linear ramps. Thus, CT’s voltage and hence A2’s output is a clean triangle wave with a peak-to-peak amplitude of 2VF. Supply variations are largely absorbed in R1 and R2—not fully, but we can ignore this as being a second-order effect; oscillation frequency is within 1% from 3 to 15V across the rails. A3 buffers the feed to RT so that R2 and D3/4 remain unloaded. Figure 3 shows the waveforms for the circuit and the FFT of the output with R3 critically adjusted at ~1kHz.

Figure 3 Waveforms and FFT plot for the circuit in Figure 2. The FFT of the output with R3 critically adjusted at ~1kHz.

Diodes are inherently temperature-sensitive, their forward voltage dropping by about 2mV/°C. Thus, the trip points change by this amount, potentially leading to an increase in operating frequency with temperature. However, the voltages across D3/4 fall by the same amount, reducing the drive to RT in proportion, thus cancelling out variations due to temperature changes. We now have an excellent, symmetrical tri-wave with a defined amplitude of 2VF pk-pk and frequency-stabilized against variations in temperature and supply voltage. 

Feeding it through R3 into D5/6 squashes it into a reasonable sine wave, thanks to the diodes’ log relationship between current and voltage (but see this Wikipedia article again). D5/6’s VF falls with temperature, but so does the triangle’s amplitude. A4 amplifies the sine wave to give an output level of about 2.2V pk-pk—0.775V RMS, or 0dBu. (Not shown is the range switching of CT, output level control pot, gain-of-3 output amplifier.) R3 is trimmed for minimum third-harmonic content using a scope’s FFT; around 20k is the best compromise value. 

However, on setting set this up at, say, 1kHz, distortion is much worse at other frequencies, especially beyond 8kHz. This is due to A1’s performance, and we’ll look at this later. But while the third harmonic is the one we are concentrating on, what of the others? A simple twin-tee notch filter with feedback, built for close to 1kHz with a q of 2 and a gain of 10, allowed the scope’s rather basic FFT to reveal harmonics previously buried in the sampling noise. This clearly showed the third, but revealed that the level of the fifth also changed when R3 was varied, but out of step with the changes to the third, with hints that the balance depended critically on the level applied to R3 as well as R3’s value. Higher harmonics—seventh and above—were largely unchanged. 

Time to build a test rig to check what’s going on, but first let’s look at the oscillator problem.

Its frequency is theoretically given by 1/4RTCT. (Think CV = IT, where C is capacitance, V is (change in) voltage, I is charging current, and T is charging time (all for a linear ramp). But the higher the frequency, the worse the mismatch with reality and propagation delays. This is mainly due to A1 as it must be added to RTCT.  For a frequency of 1kHz, RT measured 22.8k with CT = 10n, rather than 25k; 1M0+10n gave 24.5Hz; 10k+10n, 2.12kHz; 10k+1n0, 15.1kHz. 

A1 is a TLV237x op-amp (3MHz, 16V, RRIO). Its internal signal delay and finite slew rate mean that the triangle amplitude rises steadily with frequency—doubling by about 25kHz—over-driving the sine conversion and leading to increased distortion. It should ideally be a fast comparator, but those with decent supply voltages and bipolar rail-to-rail outputs currently seem to have 2-digit (in £/$/€) price tags and 3-digit (in weeks) lead times. (Suitable 5V parts, and matching op-amps, are available from several manufacturers.) To cure the symptoms, if not the cause, we must stabilize the amplitude after generation.

Second test circuit

I looked at several types of AGC circuits (strictly, Automatic Level Control). JFETs are the usual starting-point but are inherently non-linear and need to be surrounded by lots of stuff to limit the signal voltage across them and cancel their remaining distortion—several op-amps and a couple of trimmers to do it properly. An LDR avoided the linearity problem, and while this solution may look almost barbarically simple, it works well here. Figure 4 shows the new circuit with the latest modifications.

Figure 4 New tri-wave generator and sine converter test circuit, with AGC.

A5, half of an LM393 dual comparator, senses when the tri-wave’s tip exceeds the reference value and then drives LED1 to illuminate LDR1, whose resistance falls, reducing the signal across R3. The reference is provided by R6 and D6, which track R1 and D2 in the oscillator itself. A4 buffers the output, which is now almost constant below 10kHz and only 10% up at 25kHz. (LDR1 was a Silonex NSL-19M51, the LED being a generic T-1 clear white 8cd device, though an efficient 550nm green/cyan one would match the LDR’s response better. Thick, black heat-shrink joined and shielded them.) An op-amp with a series pull-down diode replacing R5 also works, but only up to 10kHz or so owing to its slower response. 

At very low frequencies, the overshoot is minimal, so the LED is barely tickling the LDR when using the oscillator of Figure 2. With a higher input from that or another source—beyond 10V pk-pk on test—the tri-wave level is still defined by VF: the AGC is just working harder. It is best to pot high levels down first, though.

We now have two options for faking a sine: one where we start with a level defined by the oscillator itself, and another where the level is arbitrary. 

Whatever the source, we now have a tri-wave whose amplitude is defined by D6’s VF but is that really the optimum level?

Intuitively, that would seem to be the same as the squashing diodes’ VF, assuming the series resistor to be ideal, and so it proved—with a pleasant and almost shocking surprise in store. With R6 and R7 finely adjusted, the third and fifth harmonics completely disappeared! Figure 5, explained below, shows this.

But with the slightest mismatch anywhere, one or both harmonics came back. The tri-wave’s level needed to be millivolt-accurate, and A5’s input offset meant that R6 had to be adjustable. The best and most consistent results came when R6 was replaced by a precision current source (not shown) delivering ~275µA into D6, which eliminated second-order power supply effects. (That’s a higher current than expected because of the offset.) The critical value of R7 was remarkably close to R1/2—close to 33k—so perhaps, with perfect components and no AGC necessary, R1, 2, 6, and 7 would all be identical, and with a critical value close to 30k. I leave this one for the theorists!

Removing the fundamental with the notch filter showed that the seventh and higher harmonics were now dominant and couldn’t be tuned out. (Kindly ignore the pesky, residual even ones.) The seventh was at around -50dB, or 0.3%; after that, the higher, the lower. Figure 5 is a composite of traces: at the top is the original triangle and the resulting sine, with the distortion products—the harmonics—at 100 times their scale; below that, their FFT. This implies that the distortion limit is about 0.4-0.5% in total.

Figure 5 Results from Figure 4’s circuit. The top shows the original triangle and the resulting sine, with harmonics at 100 times their scale; the bottom shows their FFT.

And the output level from the diodes? Intuition (and the waveforms’ geometries) said that the sine’s amplitude should be 1/√2 of the triangle’s, but now it’s wrong: all measurements homed in on 0.666… Presumably the residual harmonics account for the difference, though the numbers look wrong.  I expect that a mathematician familiar with the various series defining sines, and how those relate to Fourier analysis, would find the answer obvious.

A6 buffers and amplifies the newly generated sine wave. Note that we have added Th1—a standard 10k (at 25°C) thermistor—in the gain-defining network. While the amplitude variation with temperature was unimportant in practical use, it seemed only right to compensate for it. According to LTspice, this network will give the gain we need to raise the sine wave’s amplitude to ~2.2V pk-pk, or 0dBu, from 0 to 50°C. (And that’s the only bit of simulation used here. I hope their diode models are good.) Distortion still varies with temperature. Although D6 and D7/8 are matched in isolation, their drive currents are different, so their functioning VFs neither match nor quite track with temperature.  Perhaps mixing another NTC thermistor in with R7 would cure this…

Care needs to be taken to minimize second-harmonic distortion, or waveform asymmetry. Power rails must be well-matched or second-order effects creep in, though apart from the AGC, the circuit is symmetrical and inherently well-balanced. The diodes must be carefully matched in pairs for forward voltage. (Taping a strip of ~50 1N4148s to a sheet of paper, measuring and annotating each one, and then selecting pairs, worked well, for this and other projects.) Surprisingly, dual diodes, or those that I have checked, don’t match internally very well. Offsets within the op-amps cause slight asymmetry. I trimmed most of it out by connecting a 100k pot across the supplies with a 10M resistor from its slider to the junction of R3 and LDR1 (not shown): crude, but effective, if a little sensitive to supply variations. 

The harmonic content still rises with frequency, though much less than before, but in the real world, if the 3rd and the 5th are significantly lower than the 7th harmonic, we’re doing well. Above 3kHz, distortion starts to rise, but the harmonics are gradually being pushed beyond the notional top of the audio band at 20kHz. I estimate that ~1% THD (-40dB) is reached by ~8kHz, and ~3% (-30dB) by 20kHz. This circuit can run at way beyond 100kHz, but can’t then be recommended for waveform purity! (By about 25kHz, the tri-wave has turned into a pretty good sine, anyway.)

Calibration of a tuning scale at low frequencies will not be matched on higher ranges because of A1’s performance: the inherent delays affect the tuning law as well as the tri-wave’s amplitude. On my original build, I used a spare section of the range selector switch to vary RTb—the extra end resistance—which helped keep the ends of the scale within 5%.

Conclusion and discussion

Our quest is now at and end, and we have discovered several curious and useful things on the way. We have a novel oscillator which is inherently ideal for squashy sine wave generation, and we can precisely match other sources to that process. We have a better understanding of the limits to what is possible but have found some nice ways of optimizing the practical results. And there are still many unanswered questions, with much food for thought about the underlying math!

Our empirical conclusion: for optimum performance, the applied tri-wave must have exactly the amplitude that matches the VF the squashing diodes would have, if they were being driven in the same way as the reference for that tri-wave.

But the gold at the end of our rainbow is at best an alloy: our squashed triangle can never be a pure sine, for even when we have tamed the lowest harmonics, there will always be the small, sharp teeth of the upper ones to snap at us. By the time we have fixed all the other problems, we might as well have used all those devices in a “proper” sine-wave generator, using a two-integrator/bi-quad loop oscillator or even a Wien bridge, capable of much lower distortion and generally cleaner performance.  

For a simple, reliable sine wave generator, good for level-checking and lining up if rubbish for distortion checking, this solution has proved excellent, while optimizing it was most instructive.

—Nick Cornford built his first crystal set at 10, and since then has designed professional audio equipment, many datacomm products, and technical security kit. He has at last retired. Mostly. Sort of.

 Related Content

Laser simulator helps avoid destroyed diodes
Multi-decade current monitor the epitome of simplicity
Dual RRIO op amp makes buffered and adjustable triangles and square waves
Rectangle and triangle waveform function generator
Linear ramp generator uses one op-amp

<!–
googletag.cmd.push(function() { googletag.display(‘div-gpt-ad-native’); });
–>

The post Squashed triangles: sines, but with teeth? appeared first on EDN.

[ad_2]
Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Translate »