Sunday, August 24, 2014

DIY-ing a function generator

It's holiday time! Irene is running with her friends, Elise is making things out of Fimo clay, Gijs is enjoying just pottering around, and me - I'm that old geezer who has found himself a hobby.  Electronics, in my case. This post is about me making a function generator out of a few electronic components and an old sweets box - something I'm insanely proud of despite the fact that (a) any reasonable DIY-er can do it, and (b) I'm sure there are many web pages that will tell you how to do it - and probably much better than I have done.

A function generator is a little device that generates square, triangle, and sinusoid waves, of 'arbitrary' frequency. The heart of this device is the Exar XR2206CP, a 16-pin IC that most sellers consider 'obsolete', but that one can still get on ebay and such. With this IC the actual production of the three different waves is done for you - you 'only' need to connect up the right collection of resistors, capacitors, and switches, as shown by this schematic:

(for some explanation, see below)
Part of the fun is the challenge to get it into a nice little box. Irene gave me a little box of Vermint's Organic Mints, and I decided to try and fit everything into it. In the end all did fit in, but only just. Here's the finished product:




After having worked out the schematic above, I ordered the missing components at farnell. I was a little taken aback that the two potentiometers - the big round things, like volume knobs - were so big that there was very little space left for the rest of the components.

The rest of the components all had to go on a piece of stripboard, which is a flat piece of fiberglass-epoxy with holes predrilled and one side covered with copper strips. I use the 'tripad' variety, with strips three holes long. Because of the little space left by the potentiometers I did my best to optimize for space, leading to the schematic below. You can recognize the 2206 chip in the middle, and the copper strips in groups of three (indicated by ovals). I managed to keep the whole thing no wider than 8 holes, which is the length of the IC. But that did mean that everything got bunched up, nothing like the clean spacious designs one finds on electronics websites :-)


Soldering is not my strong point, but in the end I managed to get everything in place. Then came the issue of assembling everything in the box. I found that one of the hardest parts was actually drilling nice round holes - for some reason, that I don't really understand, I often get asymmetric holes (like the last picture in this page; maybe one day I'll try that suggestion, to drill through some cloth). But finally everything was done, and the whole set fit into the box.

Here are some of the ouput plots, such as a sine wave,

a triangle wave,
and a square wave:
This all works as it should. (A big thanks to Merijn Wijnen for letting me use his oscilloscope!)

The frequency range is supposed to go up to 1MHz; I pushed things slightly further by using a smaller capacitor, and indeed the frequency can go up to 4MHz, but then the square wave does not look very square any more:
The sine wave is not too bad at 4MHz,
but the triangle wave doesn't look right either;


With this sub-spec capacitor it also turns out that the frequency is not exactly constant. Here you can see how the later waves come in at different times: while the lines are clean on the left-hand side, just after the trigger (as they are automatically since the scope triggers on them), towards the right one can see multiple versions of the waves, at slightly different times.
And to make things worse, if I touch the box somewhere, then this frequency shifting becomes much stronger:
I don't yet understand exactly what causes this phenomenon.

Concluding, this was a very nice little project with some good challenges (at least for me) along the way: designing, optimizing, soldering, drilling - and with a nice function generator as a tool at the end!


Comments on the circuit schematic:


The 2206 outputs a square wave on pin 11 (provided one adds a pull-up resistor) and a triangle or sine wave on pin 2; the choice between triangle and sine is made by the switch between pins 13 and 14 (the bottom switch in the box, with the blue body). The frequency is set by the components on pins 5, 6, and 8; the capacitor between 5 and 6 charges and discharges through the resistor at 8, and therefore the frequency of the output is roughly equal to RC. I put in three capacitors, of 100 pF, 10 nF, and 1 uF, which are switched through the top switch (with the red body); the resistor is variable (the right potentiometer). This gives me three ranges swept by the potentiometer, starting somewhere below 1 Hz, and ending at the 4 MHz that I showed above.

The funny arrangement at pin 3 determines the amplitude of the wave; when pin 3 is at exactly one-half Vcc the amplitude is zero; the variable resistor modifies the voltage at pin 3. 

There are two trimmer resistors (at pins 15-16 and 13-14) which can be used to slightly modify the form of the sine wave. I chose an intermediate frequency and twiddled them until the FFT of the sine wave had the least overtones. 

Finally there are a number of 1 uF capacitors sprinkled around to prevent cross-talk between different bits of the circuit.

1 Comments:

Blogger Bob Planque said...

Cool, Mark! Here at the VU, Joost and I are working on optimal control of biochemical pathways, catalyzed by enzymatic reactions. The idea being that by measuring intermediate concentrations in a pathway, some gene regulatory network is able to make the right amounts of enzymes to steer the dynamical system of metabolites + enzymes to a point of maximal flux. Total amount of enzyme is constrained, so you cannot just up all values. Anyway, in some easy cases it is possible to make a dynamical system that does this, where the steady state values for the enzymes are functions of given input and output concentrations. The question then arises, how does one make a gene regulatory network that implements such functions? Apparently, E coli does just this, and Frank Bruggeman is convinced that it is easy to come up with wiring diagrams for speficied functional forms. Made me think of this project of yours :-) .

cheers,
Bob

4:31 AM  

Post a Comment

<< Home