Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM to sine AC

Status
Not open for further replies.

wip

Member
Hi,
I am generating a Pulse Width Modulation with my microcontroller (fix at 329hz). I am trying to transform, as much as possible, this PWM square signal to a sine AC signal. I am using a passive low pass filter and a electrolytic capacitor for AC coupling. My problem is the AC coupled signal is offset towards the positive side of the DC:

pwmoffset.jpg


It is not that much, but it bothers me. Should I use a bigger capacitor or a lower? Right now, it's a 1uf. As for the sine, as you can see I am not there yet, it's more like a triangle. But I guess with the right combination of resistor and capacitor (and the fact that my frequency is fixed) I should be able to get a decent sine?

Finally, I am feeding the output of the AC coupled signal in a LM386, I must use an op-amp in voltage follower mode to avoid affecting my low pass or maybe I can choose the resistor and capacitor when the signal is connected to the LM386 (taking in consideration the resistance of the input pin of the amplifier)?

Thanks
 
The PWM is running at 329hz.
You want a sign wave at what frequency? 329hz?
Why do you want to AC couple?

I don't know what you want to do so this is hard to know how to fix this.
 
Yes, I want to feed an audio amplifier @ 329hz.
Since audio is AC, I want to transform the square DC signal to sine AC.

But it looks like the AC coupling is not fully putting the 0-5V DC square to -2.5V / 2.5V.

Also when finding the right values for the RC low pass filter, I am wondering if I should use an op-amp voltage follower or maybe even better, it's possible to save the op-amp by connecting the signal to the amplifier and works the value in consideration of it.

Sorry, English is not my mother tongue.
 
If you are trying to generate a 329Hz sine wave your PWM frequency should be much higher, e.g. ten to twenty times higher. The filter corner frequency could then be, perhaps, ~500Hz.
 
A squarewave has equal times for its positive and its negative. When you filter it with an RC the positive part will have the same duration as the negative part. But PWM is not always a symmetrical squarewave, sometimes its positive part has less or more duration than its negative duration causing a normal change in the capacitor-coupled DC output level.

A sinewave has no harmonics. Your PWM waveform is 329Hz and has harmonics at 658Hz, 987Hz, 1316Hz, 1645Hz, 1974Hz, 2303Hz, 2632Hz, 2961Hz, 3290Hz etc. If you calculate the RC filter to reduce 329Hz to half its level then most of these harmonics will still be there but with reduced levels so the output will not be a sinewave.
 
You want 329hz. Can you get the micro to also output 100x or 50x the frequency you want.
I have a low pass filter (digital) that can turn a 329hz square wave into a sign wave. But it needs a 32900hz square wave as a clock.
LTC1062.
 

Attachments

  • UAF42 square wave to sinusoid.pdf
    52.2 KB · Views: 236
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top