Instructables
Picture of Arbitrary waveform generator, for ~20$
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.

Parts:
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.

 
Remove these adsRemove these ads by Signing Up
aafram4 years ago
you can use the arduino IDE to program the AVR easily. Also you can use the PWM to replace the R-2R DAC.
legionlabs (author)  aafram4 years ago
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!

PWM also normally gives you a square wave, but you could filter it.

You could also do all of this with opamps, which would be a lot of un!
hi legion!
how can this be done with a opamp?
legionlabs (author)  akinich1 year ago
Well, there are several ways. Let's discuss 2: the simplest and most reasonable, and the most absurd.

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 "Bubba oscillator" 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.

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.

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 ,
i just need a sine wave , the frequency does not matter
its more of the output voltage and current ,
thanks
akinich
legionlabs (author)  akinich1 year ago
I guess the most logical questions are "what voltage/current", and "how accurate of a sine wave does it have to be"?

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).
Blackice5045 years ago
love it thats all a Dlink is good for a case lol.
insmac5 years ago
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).
legionlabs (author)  insmac5 years ago
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 $$. ;-)
nickbuls6 years ago
can you hack up an AM transmitter to it and put it on the frequency your transmitter is so your transmitter can send further?
legionlabs (author)  nickbuls6 years ago
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?
legionlabs (author)  Unit0425 years ago
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?)
legionlabs (author)  Unit0425 years ago
This is a nice guide for cantennas: http://www.turnpoint.net/wireless/cantennahowto.html

It will only work well for microwave frequencies (hundreds to thousands of Mhz).

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.
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....
drj1135 years ago
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!
legionlabs (author)  drj1135 years ago
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.
junits155 years ago
what is that white goop u used to glue down the wires?
legionlabs (author)  junits155 years ago
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
PKM6 years ago
Does insulting DLink with a high-frequency pulse generator make it an RF burn?

I apologise profusely.

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?
legionlabs (author)  PKM6 years ago
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.
legionlabs (author)  legionlabs6 years ago
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.
PKM legionlabs6 years ago
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...
legionlabs (author)  PKM6 years ago
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.
burzvingion6 years ago
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?
legionlabs (author)  burzvingion6 years ago
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 is a "false" or "virtual" ground.

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.)

You knew that already, of course....

Did I miss the Atmega source code, or is that on an outside link?
legionlabs (author)  gmoon6 years ago
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 why it works, that's enough.

Thanks, I'll check out the source when you post it...
Heh, heh, heh. Knock the "L" out of Dlink...
jdege6 years ago
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.
legionlabs (author)  jdege6 years ago
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.
Wasagi6 years ago
Wow! Great instructable! I'll try to do this sometime!