logo bass mannie



Valid HTML 4.01 Transitional


Signal Generator - Introduction



The following page details the construction of a budget sine wave generator, together with itís associated digital voltage and frequency meter.

For some years an aging Farnell LFM4 signal generator had been used, but when this expired recently there was a need to replace it cheaply. It wasnít used regularly enough to warrant spending lots of money, but at the same time something was needed that was more practical than a PC based generator, so this is where the project ventured....

finished sg



The generator


After searching round the web for some time it looked like the most respected sine wave generators were all based on a Wien Bridge topology. More modern generators such as DDS exist and their merits, such as cost and precision, are mentioned in the distortion section. The generator described on the 'bobsdata.com' web site particularly caught my eye, so thatís what was built.

cct circuit

The full description can be found here

The capability can be summarised as follows: 20mv Ė 1.70v RMS in two ranges 15hz Ė 20khz in two ranges

The circuit relies on a specific lamp for stability, but other than the lamp the circuit only requires a few resistors, capacitors, switches and an op amp. One, or two resistors have to be chosen to match the lamp characteristics but bobsdata site describes the calibration comprehensively.

The bobsdata page describes a US lamp of specific nature. This is available on the web but with exorbitant postal charges for the UK. A bulb with identical spec(T4.9 28V 1.1W INSTRUMENT BULB 515) was discovered here in the UK which proved perfect for the task. Rod Elliot also describes the technical aspects of this and other topologies in good detail on his esp website here. The power supply used here is a +-9v split supply, mainly because Bobsdata describes 2 x 9v batteries as a supply. It seemed straightforward to just go with the flow here.




The meter


The meter is based around an AVR attiny461 microcontroller with an output display to the ubiquitous HD44780 16x2 LCD. The following block diagram shows the layout.

block

The following discussion assumes a rudimentary knowledge of microprocessor/controllers. If not acquainted with microprocessors there are many primers and overviews on the web. This section can be skipped entirely if not interested in the microprocessor workings. Experts, I hope, will forgive the novice explanation.

The meter was checked at every stage by validating the output against a UNI-T digital oscilloscope. The results were generally in agreement so the meter was deemed to be adequate for purpose. A buffer was included after the generator to make the signal more robust and minimise any impedance matching problems between the generator and the monitor circuit. There was one anomoly however as the voltage measurement would tend to become less accurate when the frequency dropped below 100 hz. This is currently being investigated.

Frequency

The frequency counter is very basic, using the pin change interrupt to count the wave polarity change and then displaying this count every second. The arrival of each second is notified by the 16 bit timer overflow interrupt.

The only challenge to this philosophy is in discovering the point at which the wave changes from positive to negative. The native pin change threshold in the AVR chips is in the region of 2+ volts, presumably because they are aimed at logic level voltages. This is patently of no use if our signal is in the millivolt range as the detector would not see the polarity change. To address this situation a simple comparator circuit(LM339) has been employed to normalise the signal to a reasonable output level. In this case a square wave is produced with amplitude around 2.5v RMS, irrespective of the input level. The comparitor circuit does not function below 40mv signal level therefore the frequency counter will operate between 40mv and 1.7v RMS, counting from 15hz to 21khz.

Voltage

The voltage measurement is obtained using the onboard ADC which is capable of measuring any voltage between zero and the chip supply voltage(5v).

The first version of the program measured the AC voltage at every program iteration, and stored the measured voltage if it was greater than that last measured. At the end of each second this stored voltage was displayed, being assumed to be at, or close to, the peak voltage. This method worked but became increasingly inaccurate as the frequency increased.

It was decided to use a RMS to DC conversion chip(AD536) to convert the voltage before measurement. This has proved to be very accurate across the full range of frequencies and gives a true RMS result. The display on the generator shows a voltage to 3 decimal places, this is slightly tongue in cheek because the onboard ADC is only 10 bits resolution so the most precise voltage is only going to be to the nearest .005 volt. Academic at these levels, to say the least.

board top board top board bottom board bottom square wave square wave



Distortion


As the project progressed the thought of distortion became more important. The generator is only used for 2 reasons here, first to ascertain amplifier power, by identifying the clipping point and secondly to measure harmonic distortion. It would seem difficult to measure an amplifierís THD if the source of the original signal already contained high THD...ergo new requirement for low THD....

Looking at available units and methods showed that cheap function generator chips had inherent high distortion and affordable DDS chips also had sizeable distortion figures. The entry point for DDS chips with acceptable distortion figures was way out of range for this budget. Again, Rod Elliot has a comprehensive description of relative THD levels on his westhost site here. Using a rudimentary measurement system the figure for this generator measured at 0.025%-0.05%. Unfortunately no figures were taken for the original Farnell so no comparison can be made, but the manual states a figure of 0.2% - 0.02% for the frequency around the 1khz mark. Our figure of 0.05% therefore seems perfectly acceptable for the cost of the project.

thd graph thd graph



Conclusion


The whole project was undertaken with the idea of minimum cost, mainly because the signal generator isn't used very often. Much more accuracy can be obtained from bought units, particularly the modern DDS units, but this accuracy was found to be expensive. This is a budget solution. Considering :

There is strictly no need for 2 transformers as the whole thing could be supplied by the 12v transformer, there just happened to be a spare 9v Tx in the box. Also, the AD536 converter is a luxury as there is a much cheaper, though more limited version available. In summary it should be entirely possible to build the generator for around £10 and the whole thing including the meter for around £20.

The code for the meter is included for completeness. For anybody interested in the meter and unfamiliar with the AVR chips a compiler will be needed together with a hardware programmer. A free compiler is available from ATMEL here and there is a large choice of budget programmers which can be found by searching for 'attiny programmer' on any search engine.

sg circuit sg circuit power supply power supply meter code meter code