An arbitrary waveform generator (AWG) is a useful but often expensive piece of test equipment (ebay it for laughs). Use it to determine component frequency response, generate carrier signals, as an LCR meter if you have a scope, tune resonant circuits, play sounds, or just draw cool graphics on your scope. It has many other uses as well, both benign and sinister, use your imagination (at your own risk)!

This project will describe how to make an AWG that can produce decent sine waves up to about 2Mhz, and of course all kinds of other waveforms, for around 20$ (assuming you own an stk500 or equivalent programmer).

This project assumes the builder is familiar with assembly language, atmel microcontrollers and their programmers, oscilloscope use, and basic electronics. All novel ideas and schematics are released under the GPL, all non-schematic images are released under a Creative Commons license.

2x 10 pF capacitors
1x crystal, preferably 16Mhz, I used 14Mhz
1x 5v voltage regulator
2x 9v battery
7x 50kohm resistors, 1%
10x 100kohm resistors, 1%
2x 4.7kohm resistors
1x 100kohm potentiometer
1x 10kohm potentiometer
1x OPA2132 op-amp, or any op-amp you're familiar with
2x 220uF electrolytic capacitors, rated 18v or higher

Finally, you will need the datasheets for the atmega16-16pu, and your opamp of choice. In the amplifier circuit, I labeled the pins by function and not by number, the datasheet will show you which pins are which (I used the same naming scheme as the datasheet).

The original html version of this project is available at http://legionlabs.nullnode.com/

The photo demonstrates a 1Mhz sine wave generated by the device.

Step 1: First Circuit.

This circuit contains the microcontroller and the digital to analog converter (called an R/2R network) which generates the waveform. The waveform generated is between 0 and +0.2v, the 100kohm resistor and potentiometer act as a bias to make it between -0.1v and +0.1v.

VERY IMPORTANT: Unless you want to include switches that change the waveform type/frequency... I didn't because it involves a performance tradeoff... you will be reprogramming this microcontroller frequently. Either be fancy and include ISP, or do what I did: solder an IC socket to the circuit board, and also lodge the microcontroller into another IC socket... the electrical contact between the two IC sockets is just fine, and an IC removal tool lets you pull it out with minimum force.

Alternatively, spend an extra few dollars and get a ZIF socket. If I were to redo this project, this is what I would do.

When this stage is complete, you have a functioning waveform generator... which you should proceed to test with your scope (test the bias!). A later step will include a link to a useful site that has assembly code compatible with this microcontroller that will generate various waveforms.

Next, we will ad an amplifier stage to increase the signal voltage to useful levels.
you can use the arduino IDE to program the AVR easily. Also you can use the PWM to replace the R-2R DAC.
Yes, that would work too, but my personal preference is assembly language. Also, avoiding the arduino means I can intergrate this into more permanent projects at a lower cost. To each their own!<br><br>PWM also normally gives you a square wave, but you could filter it. <br><br>You could also do all of this with opamps, which would be a lot of un!
hi legion! <br>how can this be done with a opamp? <br>
Well, there are several ways. Let's discuss 2: the simplest and most reasonable, and the most absurd. <br> <br>First (and most reasonably), you could build various tunable oscillators using 1-4 opamps. A Wein Bridge circuit would be simplest (http://en.wikipedia.org/wiki/Wien_bridge_oscillator), but the awesomely named &quot;Bubba oscillator&quot; is more precise. You *could* tune with a variable cap, but a trimpot or potentiometer is a better choice. Amplify the output via LM386 to provide relatively low impedance compatible output. <br> <br>The most absurd method would be to build a CPU and RAM entirely out of opamps, and emulate the AVR chip I used... if you do this, my hat is off to you. <br> <br>If I were to redo this project, I'd use magnetoresistive memory and a counter to generate waveforms through an R/2R. You could reach higher frequencies (maybe 5x)!
thanks legion , <br>i just need a sine wave , the frequency does not matter <br>its more of the output voltage and current , <br>thanks <br>akinich
I guess the most logical questions are &quot;what voltage/current&quot;, and &quot;how accurate of a sine wave does it have to be&quot;?<br><br>Heck, if up to 20khz, ~2v, and 15-25mA is fine, then just use an MP3 player and make your sine wave in Audacity (open source sound editor).
love it thats all a Dlink is good for a case lol.
This illustration shows (or implies) that there are two 9 volt batteries or voltage sources. The common terminal as shown would be the ground (or more appropriately called circuit common). If you used a single 18V source and the circuit shown, then the common terminal created by the voltage divider would be referred to as a virtual ground (or circuit common).
Indeed, there were two 9v batteries in this design. You've got a good eye, my friend! These days I try to save batteries by using an 18v wall adapter, but many of these use switching voltage regulators and I've had some problems with power supply noise in very sensitive designs (for example, circuits with gain over 15 million). For this design, an 18v wall adapter source would work just fine. Makes the device less mobile though, that's for sure.
Switchers in sensitive circuits are always an issue. Special filtering is required, or a switcher designed for noise free DC (which just means the filtering is in the switcher)...read more $$. ;-)
can you hack up an AM transmitter to it and put it on the frequency your transmitter is so your transmitter can send further?
I should warn you that being caught transmitting on most radio frequencies without a license means an eventual visit from secret services in my country. If you push your existing transmitter past the FCC regulations (or the regulations in your area), you're asking for trouble. The answer to your question is twofold. Firstly, what you describe is possible. Secondly, for what you are describing, it may not be the most "useful" approach. It is possible in the sense that you could use this device to generate a carrier frequency for AM or FM transmission. You could even set the frequency output quite accurately if you choose the correct crystal. However, there are important limitations. If you tear up an AM transmitter, you may find that there is some "fancy" part of the device that makes it hard to shove a different carrier frequency in there. It would be easier to just build the amplitude modulation yourself, as a simple implementation would require about 2 pieces... a transistor, and a resistor resistant enough to put your transistor into linear mode. Secondly, making a signal go "further" in radio is not a simple matter. Different frequencies are absorbed differently by the environment. Furthermore, range does not increase as drastically as you might think by using more power: a better antenna often produces better results, and is much more energy efficient. A simple dipole shouldn't require frightening amounts of math... the other types sometimes can however. Lastly, it sounds like what you want to do (more or less) is increase the strength of the existing carrier signal. The simplest way to do this is to use an operational amplifier designed to work at that frequency (expect a cost of less than 10$ for the amp circuit I used, it is OK up to a few Mhz)... or possibly just a transistor in linear mode (cost: ~0.07$ for an N2222). Overall I think it would be simpler to increase the amplitude of the existing carrier frequency rather than build a device to generate a new one. In summary, if you absolutely want to accomplish this using microcontrollers, with sufficient patience it should work. I encourage you to use whatever design that you consider the most beautiful (and within radio transmission regulations). If you have any specific questions, feel free to send me them as private messages to avoid clutter.
Forgive my ignorance, but what about an amplifier where the antenna was, then a different antenna on the ouput of that?
Should work. The difficult question is: What type of amplifier and what type of antenna? Worse: How do you debug it if it doesn't work? Op-amps have rather limited power output (unless you have lots of $$$), and cost also increases with frequency. You will need a nice oscilloscope for testing/debugging the amplifier, these are expensive at high frequencies. For the antenna, you'll either have to get a pre-built one, or carefully design one (a yagi is a nice design). If you want to test it, you need a spectrum analyzer, and this is very expensive. To summarize: You're right, but the devil's in the details. Analog amps and homebrew antennas are not too complex but do require tuning, and this is difficult without a little knowledge and access to equipment. It is still possible without equipment... just difficult. Of course if it's for wifi @2.4Ghz, just build yourself a cantenna or yagi using a guide and you're set. I know it worked for me ;)
Yes, devils in the details.... A guide as in, a how-to manual, or a radio lingo guide? Would the aforementioned circuit work for 1MHz? (or close thereto?)
This is a nice guide for cantennas: <a rel="nofollow" href="http://www.turnpoint.net/wireless/cantennahowto.html">http://www.turnpoint.net/wireless/cantennahowto.html</a><br/><br/>It will only work well for microwave frequencies (hundreds to thousands of Mhz).<br/><br/>For 1Mhz, nice antennas tend to be large-ish. Antenna designs have dimensions based on how far a photon can travel in once cycle, so when you use lower frequencies, even a 1/2 dipole can be an inconvenient size. It may be possible to make a decent antenna anyway, however my limited knowledge of antenna design is not sufficient to help you out.<br/>
I don't like super-high frequency stuff that requires waveguides... the physics makes my head hurt! But I respect those who understand stuff like this....
Are you sure that the dip is caused by the loop function I would have expected the dip to occur every cycle, not every 10 cycles. Is there a watchdog that has to be reset? This is a great, simple project - well done!
Pretty certain. If the RJMP statement was used every cycle there would be a dip each cycle... but if I recall correctly I stuck enough instructions in there to do several repetitions without needing to loop. It's a memory-time tradeoff. I used no watchdog timer.
what is that white goop u used to glue down the wires?
A type of tack. It goes by the brand names BluTack, Ticky Tack, and others. The generic dollar store version around here is white instead of blue. None of the above make particularly good adhesives. I should have used velcro tape instead!
oh because it looks very similar to the white goop that i found inside a computer PSU, it made it really hadr to take apart
Does insulting DLink with a high-frequency pulse generator make it an RF burn?<br/><br/><sub>I apologise profusely.</sub><br/><br/>This is a neat demonstration of just how much you can do with simple microcontrollers. My only reservation is that fine control of the frequency appears to be impossible- can you replace the crystal with an adjustable frequency clock? Also, I'm not quite sure I understand how your circuit is generating the signal voltages- does it provide analog outputs or is the ladder of resistors on the first circuit diagram used as a potential divider somehow?<br/>
Frequency resolution is a problem at high frequencies. I've tried to describe these problems in more detail in the new programming guide. As it turns out, I thought of a swappable clock too! Alternatively but less simply, you could use one AWG output as a clock source for another. At lower frequencies, frequency resolution is pretty good. Maybe someday I'll rebuild this with a 100Mhz microcontroller, and laugh at the resolution of this design. The signal is produced as follows: The microcontroller outputs a number between 0 and 255 out a parallel port. The pins of this port are connected like you would connect eight 1.5 volt batteries to create a 12v supply... except that here you can connect and disconnect combinations of batteries very fast, allowing you to produce various voltage levels. The ability to output any one of 256 voltage levels in rapid succession allows us to synthesize approximate analog waveforms. The R/2R resistor network does the magic. It connects the pins such that each pin's output affects the output voltage twice and much as the pin before it. The resistors need to be a reasonably high value of course, so you don't sink too much current from the microcontroller.
Hm, I wonder how an atmega would respond if I told it to use an external clock for which I could vary the frequency... You see, if you take a hex inverter and connect the inputs to the outputs with a variable delay in between, you can make a variable clock generator. With this technique, you could get high frequency resolution even with high frequencies... I will research this further over the next few days, and publish what I find in a new "future improvements" section of the instructable.
So.. you output the value in 8-bit binary and the resistor network acts as a DAC to turn it into a voltage level? That's really clever- is it an established technique? My GCSE electronics (last time I did stuff like that) is fading into the mists of time...
It's a well established technique. There are other ways to do it, but this way is good... just be sure to use 1% or better resistors because error on the most significant bit can be problematic. I originally bought an IC to do this (a DAC08) , but then realized the R/2R network is better and cheaper. Google "R/2R" for more info, there's some good stuff on it, there's even proof demonstrating exactly how it works somewhere.
Nice instructable, very thorough. I think you've misused the term virtual ground however. In my experience, virtual grounding refers to using a +Vcc/2 bias on the signal so that a single-ended supply can be used. In your schematic, you're using a double-ended supply (presumably two 9-volt batteries), meaning it's not really a virtual ground. Someone else wanna confirm me on this?
I think you're right. The "virtual ground" circuit was recycled from an earlier design that split one battery to +/- 4.5v... I added the -9v later to improve performance, but didn't give the circuit a new name. I think I should rename it the "amplifier power supply". I'm not sure, strictly speaking, that the amp needs this circuit if it has access to two 9v batteries. However it was already built, and gave me all the proper voltages, so I decided to keep it because I thought it would counteract any negative effects of the batteries having different charges.
As it's pictured, it <em>i</em>s a &quot;false&quot; or &quot;virtual&quot; ground. <br/><br/>But as pointed out, with two batteries you've got a bipolar supply with the ground being the connection between the two batteries (wired in series.)<br/><br/>You knew that already, of course....<br/><br/>Did I miss the Atmega source code, or is that on an outside link?<br/>
Eh, not having a formal background in engineering, I expect to get the names of things wrong often enough :D I have not yet posted the source code for those waveforms, except on a conceptual basis. I'll try to get to that tomorrow, for now feel free to check out the link I posted as a reference... that person's code is compatible with this device and is rather elegant, although perhaps not suited for generating high frequency waveforms.
Hey, not an engineer here, either. The way I figure--if it works, and you know <em>why</em> it works, that's enough.<br/><br/>Thanks, I'll check out the source when you post it...<br/>
Heh, heh, heh. Knock the "L" out of Dlink...
I've an old analog oscilloscope I never use anymore, that I keep around solely for setting providing atmosphere for my Mad Scientist's Lab on Halloween. I wired together a simple sine-wave generator, just to give it something to display. Your's sounds much more capable.
Oddly enough, I bought my scope third hand from someone who was also using it for special effects. It's not exactly in mint condition... but then again there's something to be said for high-voltage equipment that's held together by duct tape and dreams. If you wanted one of these just to generate special effects, you could skip the amplifier, virtual ground, and bias stages... just run the microcontroller and R/2R DAC off a +5v supply... or nix all that and just attach the oscilloscope to the output of your sound card, there are free programs to generate some nice low-frequency waveforms with that setup.
Wow! Great instructable! I'll try to do this sometime!

About This Instructable



Bio: I publish my failures and my successes, as my teachers have done before me. I am a member of Foulab, an independent, nonprofit research and ... More »
More by legionlabs:Poor man's AVR music box Building a Copenhagen Interpreter Etching and Working with Meteoric Iron 
Add instructable to: