Ive done it with PWM before, it's actually easier to get high accuracy than with a DAC. You didnt say what frequency range you wanted, so no real answer is possible.
For audio, it's pretty straightforward. You can use a DSP, FPGA, or even a moderately fast microcontroller to generate the digital sine samples. With fast enough processing, you can generate the fundamental and the harmonics, or you can pre-store a cycle of the desired waveform (with the desired harmonic content) and use table lookup in that instead of the more usual sine table. You'd have to store a whole cycle, I guess, instead of using the tricks with a sinewave where you only need one quadrant stored. Also, interpolation will not be as easy as with a pure sine. There are actually quite a lot of ways of handling the details, and the "best" way will depend on just what matters to you the most and what you can not worry so much about.
Look up "phase accumulator sine generation" as a start. You can also do a recursive sine generation, but beware of roundoff errors slowly changing the magnitude. The phase accumulator can be used to generate harmonics: two times (a one bit shift of) the phase accumulator value is the second harmonic, add the original to the shifted and get the third, two bits shift is fourth, fourth plus original is fifth, third shifted one bit is sixth, ... (in case you don't have hardware multiplication available). Modern audio DACs are cheap, easy to use, and offer the possibility of good accuracy.
PWM and similar techniques are certainly possible, though I'd be inclined to just let a delta-sigma converter do the PWMing for me...
Some HP waveform generators used a classical square / triangle generator, and a diode function generator to turn the triangle to a sine wave. Very effective and decently low distortion; only the peak had a "problem". For a cleaner sinewave, one could use he classical analog computer solution to the second differential. Or use the classical wien bridge. These last two methods can be made to produce extremely low distortion.
What harmonics do you need? A plain square wave will have the odd harmonics with amplitudes that reduce as 1/n. (The fifth harmonic has an amplitude 1/5 of the fundamental, the seventh is 1/7, etc.)
I can guarantee that any method that you use to produce sine-like signals will have some harmonic content. (For a signal to only have energy at exactly one frequency the signal has to exist for all time. Any modulation of the signal, like turning it on or off, will cause some harmonics.) So, what is it that you actually want?
--
Many thanks,
Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: don@tinaja.com
Please visit my GURU\'s LAIR web site at http://www.tinaja.com
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.