1
\$\begingroup\$

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?

\$\endgroup\$
10
  • \$\begingroup\$ No, there's not a simple filtering technique. For your application, you should look up Direct Digital Synthesis. \$\endgroup\$ Commented Aug 14, 2016 at 16:27
  • \$\begingroup\$ Thanks. I figured that was the case, but wasn't sure if there was some kind of "square wave to sine wave" IC. \$\endgroup\$ Commented Aug 14, 2016 at 16:41
  • \$\begingroup\$ You could use a bank of digitally controlled filters, possibly. \$\endgroup\$
    – user57037
    Commented Aug 14, 2016 at 16:50
  • \$\begingroup\$ @mkeith: that seems... much more complicated than other options. :) wouldn't I need a (sharp) filter approximately every octave? \$\endgroup\$ Commented Aug 14, 2016 at 16:51
  • 1
    \$\begingroup\$ Are you sure you couldn't just use the fastest PWM frequency at all times, and just vary the sine wave frequency instead of varying both PWM and sine frequencies? It is relevant in the sense that we often encounter people trying to do things they THINK they need to do, because of their flawed understanding of some other aspect of their problem (which they think is irrelevant). Not saying that is happening now. Just explaining why people ask. \$\endgroup\$
    – user57037
    Commented Aug 14, 2016 at 19:14

2 Answers 2

3
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

If you really want , it can be done with a rather complex solution.

PWM to DC then DC controlled Sine VCO.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ I was looking at VCOs, This is an interesting option. \$\endgroup\$ Commented Aug 14, 2016 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.