Electronic – Generating a sine wave from a square wave, for a large frequency range

frequencypwm

I have a PWM output from a micro controller. I want to turn this into a sine wave.

The typical way to do this is a low pass filter. Unfortunately, I want to change the PWM frequency, and the corresponding sine wave frequency, over more than a couple decades (say, 10Hz to 100kHz). Are there any simple ways to do this?

Best Answer

Depends on what hardware you have available and how deep into software you want to go.

If you have the processing power and GPIO pins available, you can get away with a very cheap and simple R-2R ladder as your DAC (ditch the PWM). You can then use a sinewave LUT in your MCU's memory + a software defined Low Pass Filter. You can store multiple LPFs in memory/change the characteristics of it on the fly to get your desired frequency response. The output of the LPF can then be fed right to the R-2R ladder to generate your sinewave. This approach is a tradeoff between software complexity/processor power and flexibility/external component size and cost.

If you only have a few frequencies you want or creating a perfect sine-wave is not that important you could toggle between a few different external LPFs.