Tuesday, July 17, 2007

8 stage sinewave approximation

Introduction
I have been looking around for a simple sinewave circuit that provides a sweepable frequency with a stable amplitude for little cost.

Analog circuits that offer a stable, easily sweepable frequency with a stable amplitude output appear to be relatively complex but not too expensive. An integrated circuit such as an XR2206 is quite expensive, costing between $6.50 and $14.00 depending on where you go (this is just for the chip).

Luckily, the sinewave i need doesn't actually have to be very sinusoidal at all. I just want it to have less prominent harmonics than, say, a square wave. Which brings me to a low-cost, very low-fi digital logic approach.


Low-fi Digital Approach
The concept is actually quite simple. By using a 4051 multiplexer, it is possible to generate custom waveforms with eight stages. By choosing the correct resistors for the voltage division
that feeds the eight channels on the 4051, it is possible to get a very compromised approximation of a sinewave. This technique would also rely on a 4040 binary counter or similar and a squarewave clock input for the counter. Below you can see an ideal representation of this situation of power supply voltage versus step.


Resistor Choice

The main issue is that real-world, locally available resistor only come in the E24 series as a maximum 'resolution' of resistance. What is the E24 series? Well, its pretty much a number series of 24 unique values between 10 and 100 in which resistors are available in various magnitudes. In other words, although it may be possible to get the resistance ratio (and thereby voltage output) of the eight voltage dividers close to the above diagram, it will not be possible to get those exact ratios.

Since the resistors that are available locally only have a maximum precision of 1%, the aim of balancing the resistance values is to be within this margin of error when compared to the 'ideal' values that should be used to produce the shape shown on the graph.

The following table shows the relationship between degrees, the sine function and the equivalent ratio for eight steps. It is then possible to reconcile the ratio value with a voltage value and also a resistance value. 112KΩ has been chosen to represent a resistance ratio of 1. Ra and Rb implies the following voltage divider circuit:

             Out
|
Vcc --- Rb ---| --- Ra --- Gnd


So, the choice for which resistors to choose becomes quite simple. No resistors are required for a ratio of 1 or a ratio of 0, because vcc or ground can be connected to the channels / steps in question. Which leaves only three values left to approximate - 560.00k, 955.98k and 164.02k

56 is in the E24 series, so 560kΩ is a real world value. Neither of the other two values are available, so they have to be approximated by putting two resistors in series. For 164.02k, a 120k plus a 43k are enough, producing a precision that is approx. -0.62% below the ideal value. For 955.98k, a 910k plus a 47k are enough, producing a precision that is approx. +0.11% above the ideal value.



Yep.

Results coming very soon. Like, tomorrow. Or even today. Although i am a bit sick : (

6 comments:

Anonymous said...

Cool post man.

I've been looking into creating sine waves for some time. I've come across some reasonably easy-looking schematics, with quite inexpensive parts. Most of the sine schematics I've found, however, need rails - either +15,0,-15 or +12,0,-12 volts. This isn't too much of an issue though - just an added pain. You can find basic examples of sine oscillators on a lot of op-amp datasheets.

I follow too many tangents, so havent yet actually built a sine gen... maybe when my office is clean again.

Sebastian Tomczak said...

thanks, j.

anything outside of the 4.5V to 5V with a 0V negative rail is outside of the question for this application.

also have to take into consideration more wide band noise - perhaps not an issues with a digital approach?

for this, the main thing is to get a wave whose output is less harmonically rich than a square wave.

man, i wish building sinewabes was easy, easy, easy.

Anonymous said...

Haha I more than wish Sine waves were easy. I suppose the difficulty is the price to pay for such awesomeness.

Tristan Louth-Robins said...

Purity is the key. I know that Alvin Lucier had dozens of sine wave oscillators built for him in the 1960's and 70's by his friend David Berhman, who knew a thing or two about homemade electronics. I have read that they were an absolute terror to build as the elimination of noise was of paramount importance - especially in the work of Lucier. And this was 30-40 years ago. I'm very keen to start building pure wave oscillators for research purposes soon. Perhaps I could ask Berhman how he did it, I don't have his email though I'm sure I could get it off Alvin. ;)

Sebastian Tomczak said...

tristan,
i found a good primer by national semiconductr:
http://www.national.com/ms/LB/LB-16.pdf

Tristan Louth-Robins said...

gracias senor.