Building a signal generator, DAC or filtering?

I want to build a signal generator that is controllable, accurate and will output a number of wave forms. I was thinking of using a bare bones 328P (I have plenty of these) to at least create the square wave for later shaping. Using the microcontroller means I can use an LCD screen to tell me what frequency my output is, and I can control the duty cycle accurately and even shape the wave if I use a resistor ladder as a rudimentary DAC.

If I use an I2C LCD display and two buttons, that leaves me with a 10 digital outputs for a 10 bit DAC, but am not sure if this is the best approach. I am concerned with the wave not being smooth, so would I be better off using a single digital output to give me a square wave and use analogue components to filter it into a triangle, sawtooth and sine?

An MCP4921 cost less than 2 euro from Farnell (not the cheapest, BTW) and will make the things lot more easy...

Cheers, Ale.

That looks interesting, from a quick look I will have four times the analogue resolution using only three pins. I might order one to play with :slight_smile:

I am concerned with the wave not being smooth, so would I be better off using a single digital output to give me a square wave and use analogue components to filter it into a triangle, sawtooth and sine?

You'll need a DAC and a variable filter. DACs put-out stair-stepped waveforms.

You can approximate a sine wave with a filtered sine wave (with a perfect filter you could make a perfect sine wave) but making a triangle wave is a bit trickier. It's generally going to require some amplification after approximating a triangle wave. A sawtooth wave would require a non-linear filter that filters positive-going voltages differently from negative-going voltages.

I'm not sure how "real" function generators are made... They might use "analog" oscillators, perhaps with a digitally-controlled master clock and a phase-locked-loop.

Or use Direct Digital Synthesis (DDS). Basically high speed DAC with low pass filter to take out any switching noise.