Squashed triangles: sines, but with teeth? Part 1

Texas Instruments LM393 TL081 TLV237x

A while ago, I needed (or wanted) a pocket-sized audio sine-wave generator: simple, stable, repeatable, single-gang control pot, 9 V 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?

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 (Ref. 1) and (Ref. 2). 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.

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, the Wikipedia article (Ref. 3) 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).

A basic oscillator that effectively combines an integrator with a Schmitt trigger.
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 9 V – or ±4.5 V – 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.

Simple, novel tri-wave generator and sine converter.
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 (Ref. 4) 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 15 V 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 ~1 kHz.

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

Diodes are inherently temperature-sensitive, their forward voltage dropping by about 2 mV/°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 canceling 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 (Ref. 3) 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.2 V pk-pk – 0.775 V RMS, or 0 dBu. (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, 1 kHz, distortion is much worse at other frequencies, especially beyond 8 kHz. 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 1 kHz 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 1 kHz, RT measured 22.8k with CT = 10n, rather than 25k; 1M0+10n gave 24.5 Hz; 10k+10n, 2.12 kHz; 10k+1n0, 15.1 kHz.

A1 is a TLV237x op-amp (3 MHz, 16 V, RRIO). Its internal signal delay and finite slew rate mean that the triangle amplitude rises steadily with frequency – doubling by about 25 kHz – 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 5 V 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.

References

  1. Woodward. Stephen. “Dual RRIO op amp makes buffered and adjustable triangles and square waves.”
  2. Michael A. Shustov. “Rectangle and triangle waveform function generator.”
  3. “Diode modelling”
  4. Abell, Einar. “Linear ramp generator uses one op-amp.”

Materials on the topic

  1. Datasheet Texas Instruments LM393
  2. Datasheet Texas Instruments TL081
  3. Datasheet Texas Instruments TLV237x
  4. Datasheet Silonex NSL-19M5

EDN

Series content «Squashed triangles: sines, but with teeth?»

  1. Part 1
  2. Part 2
EMS supplier