Function generators are a handy bench tool to have around, and while you can usually cobble something together that works, it is much more handy to grab a device when you need it. Thats where this function generator sent to us by [Mohonri]comes in. Based around a ATTiny25 and a rail to rail op amp which is able to replicate frequencies from 1Hz to about 40KHz, in square, triangle, and sinewaves simultaneously.
The function generator also features independent amplitude control on each output. And it’s all on one palm-sized, single-sided PCB. The main part of the code is split into two parts: the main loop gets the inputs and constructs a waveform table in SRAM, and then an ISR reads that table and outputs it to one of the timers, which produces a PWM output, which is low-pass-filtered and then passes through a potentiometer (for amplitude control) and then to an op-amp before landing on a set of terminals.
Though its not 100% perfect, trading speed for a 6 bit resolution, it should be more than enough for most electronic projects. You can pick it up in kit form from the on-line shop, but schematics, software and PCB layouts are also available for download.
11 thoughts on “Attiny25 Based Function Generator Causes A Wave”
Gotta love some 8 pin ATtiny action. They have more power than you might think, and work so nicely with AVR-GCC.
I need something like this. But the waveforms in the images don’t look clean enough. I need really clean waveforms to see and measure distortion.
The other thing missing is an LCD display option to tell me the freq, amplitude, etc. What’s the point of the processor if you don’t have that feature available?
I see lots of these types of boards on ebay and have seen mixed reviews.. Hmpf.
You’re right, at 6 bits it’s only about -36dB perfect – look at those ragged waveforms!
For the level of complexity (PCB size, chip, component, and joint count) you can build a real analogue function generator with specs that would eat this for breakfast, 0.1Hz to 100kHz, equiv 8-10 bit resolution, no need for anti-alias filters, &c&c.
PIC’s are great, but sadly this is an example of a digital infatuates idea of an analogue signal generator, and in the analogue world only 6 bit resolution is nearly useless.
How about something hardware simpler (but harder in software) like a white and pink noise generator good to 100kHz?
You’re absolutely right–an analog function generator will give you a much cleaner signal. But I did this to do something cheap and simple.
An XR2206 will give you up to 1MHz of nice analog sine-wavy goodness. It’s also $6 just for the chip, and only does sine or triangle at one time. Sparkfun actually sell a kit based on it.
Yup, I agree Mate… An AVR with more pins running at 20MHz plus an 8-bit R2R DAC running DDS code hand optimized in assembler will get you a taste above 100kHz with an arbitrary waveform. It’s been done many times before. The RISC AVR’s are nice for the DDS application because they’re generally one clock per instruction.
In some cases a computer sound card can be useful as a function generator for frequencies in the audible range.
an old vga graphics card contains sram and a ramdac… it can output some MHz and you get 3 outputs (R,G,B).
Totally agree angus, I bought a function generator kit (admittedly it was cheap) and it didn’t do nearly as well as a sketch I knocked up in Max/MSP.
Hes out of stock…
A marked trick or just plain popular ?
I would buy it, I know pure analog or bit more money makes a better one, but its small, looking nice and its a cheap kit. Make me a beter small kit and maybe ill buy our’s to. Also, I will do my research to build my own beter version, but have to start soomewhere.
Post your schematics of beter versions :D
Not that complicated. You can write sine values into an EPROM then read them into a R-2R resistive network and a buffer. Here’s an example, no mcu needed.
This solution is much better than any mcu based one (except dedicated DDS chips + filters) because there’s no firmware related delay: every step requires exactly one clock cycle, therefore waveforms are much cleaner.
Sawtooth/triangle waves are even easier to get so that the EPROM can be replaced by a synchronous binary counter or just use appropriately the 4040 in the above schematic.
Anyone know which rail-to-rail op amp he uses?
I couldn’t open the schematic with ExpressSCH. I wonder which program it’s made with. A picture of it would be great!
Please be kind and respectful to help make the comments section excellent. (Comment Policy)