Attiny25 Based Function Generator Causes A Wave

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

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

  2. 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?

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

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

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

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

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.