I wish to convert a PWM signal into voltage. I understand that the most straight forward approach is to create a low pass filter resistor capacitor circuit (RC). Probably the most helpful article I've found is Passive Low Pass Filter by Electronics Tutorials.

I'm confused however after crunching the numbers (see attached). The typical frequency of a Arduino PWM pin is 490Hz. If a create a RC circuit using a suggested 10µF capacitor and a 10kΩ resistor then according to my spreadsheet my Vout will be 0.16V which is obviously undesirable.

Could someone please tell me where I'm going wrong?

You calculate the passing of the 490Hz signal, not the DC you want to calculate So that's approximately the ripple. For the DC part, use 0Hz for the reactance

But normally we look at the cut off frequency of the filter and the attenuation at the input frequency.

And you can increase the PWM frequency very easily and get away with a smaller RC filter.

Also, you do know this will give you a voltage but you may not pull current?

ilovetoflyfpv:
Are you saying a PWM signal comprises of all frequencies up to 490Hz (see attached)

Right idea, wrong on the details.

One of the central mathematical principles behind circuit analysis is that any periodic function (read: waveform) can be represented by a sum of sine waves of various frequencies, amplitudes, and phases. If you are able to decompose a complex waveform into its individual frequency components, it's easy to calculate the effect a filter will have on the waveform since you apply the filter to each frequency component individually, then add them back up to get the result waveform.

So it's not "all frequencies up to 490 Hz". Most of the frequencies will actually be harmonics well above 490 Hz. You have the right idea though.

and the filter 'highlights' the frequency we're interested in?

Cheers

Jase

Not in the way you're expecting. The point of the low pass filter is to remove all off the frequency components as much as possible, leaving only the DC component behind.

But there's a tradeoff to this. Lowering the filter's critical frequency will reduce (but never eliminate) the effect of the higher frequency components, but it also means that the DC value will take longer to reach the intended level after it changes.

Depending on what you want to do with this signal, it might be better to get a DAC chip.

Wow! Thanks so much for the replies. So a wave is comprised of frequencies (harmonics) both above and below the fundamental frequency. A low pass filter attenuates frequencies above the cutoff frequency (in my case I want an analog voltage so I'm therefore interested in frequencies below 1Hz). Am I on the right track?

So aside from the cutoff frequency are there any other things to consider when making a RC circuit? I was thinking I need to be mindful of the overall impedance of the circuit so as not to overdrive the PWM pin. Is there a method to selecting the capacitor resistor combination?

By definition there is nothing below the fundamental frequency (other than a DC value). All harmonics
are integer multiples of the fundamental frequency.

Yes, you are on the right track, a LP filter with a corner frequency of a few Hz would be typical for this sort of thing.
Yes the overall impedance is the other variable, together with the corner frequency that defines the
value of both R and C.

You're indeed on the right track. And as Mark already stated, there is nothing under the fundamental besides DC. And if the wave is a pure sine there are even no fundamentals. A sine is the "most pure" form of a wave and every other wave can be composed out of multiple sines which is what gives you the harmonics.

And for now you're not interested in below 1Hz, you are interested at 0Hz exactly

And besides the corner frequency the PWM frequency is an important factor. As I said, it's easy to increase that if the timer is not used for other things. By default timer0 is used for millis() and other timing so better not to touch that. But timer1 and timer 2 (so pins 3, 9, 10 and 11) are free to increase up to 62500Hz.

And also don't forget this:

septillion:
Also, you do know this will give you a voltage but you may not pull current?

ilovetoflyfpv:
Wow! Thanks so much for the replies. So a wave is comprised of frequencies (harmonics) both above and below the fundamental frequency.

Not quite. A periodic waveform can 'hypothetically' (theoretically) be 'considered' as a SUM OF sinusoidal signals (comprising a fundamental sinusoidal signal and harmonics of it), plus maybe a constant value (if there is a DC offset). This is the Fourier Series concept. Note that it does NOT mean that the waveform IS physically a sum of these things. It's a hypothetical (mathematical model) equivalence...... that allows people to analyse a waveform in one way.

Southpark:
This is the Fourier Series concept. Note that it does NOT mean that the waveform IS physically a sum of these things.

I don't see why it isn't (assuming, of course, that the waveform is truly periodic and exists from time t = -infinity to time t = infinity). Either way, there's no need to confuse OP. For all intents and purposes, a truly periodic signal IS physically a sum of the harmonics found by computing the Fourier Series.

One thing to note is that if the PWM signal changes duty-cycle, the overall signal is no longer periodic from t = -infinity to t = infinity. Therefore, it is better to analyze the signal using the Fourier Transform instead of the Fourier Series. Not like this changes the filter circuit much, but it is something to keep in mind.

Power_Broker:
I don't see why it isn't (assuming, of course, that the waveform is truly periodic and exists from time t = -infinity to time t = infinity). Either way, there's no need to confuse OP. For all intents and purposes, a truly periodic signal IS physically a sum of the harmonics found by computing the Fourier Series.

It isn't 'physically' a sum of those things. Because.... physically, the physical signal in the time domain is 'The time domain Signal'.... which ...in this case.... is a periodic 2-level waveform (when the input is held at a constant value that is). Not 'physically' a bunch of sinusoids (plus a DC shift, if there is one).

Although, 'hypothetically'...... if we had the time to do it.... you could physically generate a bunch of sinusoids at the suitable frequencies (together with suitable amplitudes) ...... and add them up..... to come up with an "approximation" for the time waveform.

In the lab, you're not going to be able to generate an infinite number of harmonics. It's like e^(-t)..... it never goes to 'zero' until time reaches infinity.....and infinity means you'll never get there....because it keeps going ....forever.

It wasn't a case of confusing the O.P. It's a case of avoiding confusion right from the start.

Southpark:
Because.... physically, the physical signal in the time domain is 'The time domain Signal'.... which ...in this case.... is a periodic 2-level waveform (when the input is held at a constant value that is). Not a bunch of sinusoids (plus a DC shift, if there is one).

I'm not saying that the PWM signal is generated from the Arduino is an infinite number of sinusoidal voltage sources in series (quite absurd isn't it lol), but you can't deny that the physical signal can still be analyzed and broken down into an infinite sum of sinusoids. To say that a physical signal doesn't follow this property is to say that Fourier and his findings were wrong.

Also, if you look at a PWM signal specifically, even though it is a "2-level waveform", it still is comprised of sinusoids. Take a look at this.

Power_Broker:
Also, if you look at a PWM signal specifically, even though it is a "2-level waveform", it still is comprised of sinusoids.

NOPE.... it is NOT physically comprised of sinusoids. The waveform can mathematically be 'expressed' as a bunch of sinusoidal waveforms. It does NOT mean that the physical waveform itself (in this case, the PWM waveform coming out of an arduino) IS a bunch of physical sinusoidal signals (plus a DC value). The sinusoids you're talking about come from the realms of mathematical modelling.

Southpark:
NOPE.... it is NOT physically comprised of sinusoids. The waveform can mathematically be 'expressed' as a bunch of sinusoidal waveforms. It does NOT mean that the physical waveform itself (in this case, the PWM waveform coming out of an arduino) IS a bunch of physical sinusoidal signals (plus a DC value). The sinusoids you're talking about come from the realms of mathematical modelling.

If you were correct, wouldn't you expect the FFT functions on an oscilliscope to either not work or not be trusted when used on physical signals, assuming the signals couldn't be broken down into a sum of sinusoids? I'm still not sure where the "Fourier Series/Transform is only purely conceptual" rationale is coming from. Do you have any sources to support your claim? I'm truly curious - maybe I'm misunderstanding what you're saying.

Southpark:
NOPE.... it is NOT physically comprised of sinusoids. The waveform can mathematically be 'expressed' as a bunch of sinusoidal waveforms. It does NOT mean that the physical waveform itself (in this case, the PWM waveform coming out of an arduino) IS a bunch of physical sinusoidal signals (plus a DC value). The sinusoids you're talking about come from the realms of mathematical modelling.

Is there a point to being that anal about it?

Although, 'hypothetically'...... if we had the time to do it.... you could physically generate a bunch of sinusoids at the suitable frequencies (together with suitable amplitudes) ...... and add them up..... to come up with an "approximation" for the time waveform.

In the lab, you're not going to be able to generate an infinite number of harmonics. It's like e^(-t)..... it never goes to 'zero' until time reaches infinity.....and infinity means you'll never get there....because it keeps going ....forever.

So? Everything in every engineering discipline involves approximate mathematical models. There is nothing special about Fourier in this regard. You will never be able to generate a perfect square or sine wave with any physical circuit. You won't even be able to generate the exact same signal twice with the same circuit. Noise and other imperfections will always distort it.

Fourier works. There's no point to arguing if it's "really real" when it's a distinction without a difference.

but you can't deny that the physical signal can still be analyzed and broken down into an infinite sum of sinusoids

I agree 100% with Southpark. Making the statement above only confuses people who do not have a full understanding of why harmonics exist. IMO, saying that harmonics have a "physical" property really distorts the issue to the non-EE - as physical things are those things that you can measure like volts, amps and frequency.

It's like saying a certain device "generates harmonics" - rather than saying "the device uses current in a nonlinear fashion and we can describe that current mathematically using a concept called harmonics". Given the first statement and the second, it is easy to see why the first statement is the norm within engineering circles. Unfortunately, it confuses those who don't speak the same shorthand language.

I'm not saying that the PWM signal is generated from the Arduino is an infinite number of sinusoidal voltage sources in series (quite absurd isn't it lol)

If I understand your argument, you just invalided it, all in the same sentence. Yes, it's absurd but that is how a square wave is described, the only problem is you need infinity in order to get there...

Fourier works. There's no point to arguing if it's "really real" when it's a distinction without a difference.

Bingo. Winner winner chicken dinner. As Einstein said, "You truly understand something when you can explain it to your Grandmother".

Jiggy-Ninja:
Fourier works. There's no point to arguing if it's "really real" when it's a distinction without a difference.

Exactly. Spot on.

avr_fred:
IMO, saying that harmonics have a "physical" property really distorts the issue to the non-EE

Valid point, it does take a while to get comfortable thinking in the frequency domain vs the time domain.

avr_fred:
If I understand your argument, you just invalided it, all in the same sentence.

Maybe you misunderstood me. I was trying to say that any physical signal can be broken into a set of sinusuids no matter where it originated from. It could be an infinite number of sinusuidal voltage sources in series or it could be a flip-flop - both give the same output.

Power_Broker:
Valid point, it does take a while to get comfortable thinking in the frequency domain vs the time domain.

However, a PWM waveform is a waveform. And waveform implies time-domain. The voltage waveform at the PWM output pin is the PWM signal. Better not tell anybody that the square/rectangular raw waveform is a bunch of individual sinusoids, all individually summing together (at any particular moment) to produce this square/rectangular waveform.

If I put a hot soldering iron tip on a circuit board, and the temperature on that part of the circuit (where the hot iron tip is touching) abruptly rises from 25 degrees C to some relatively high temperature value. Yep...assuming this is happening in the real world, in the time domain. Better not tell anybody that the temperature rise at that part of the circuit is physically (actually) a bunch of sinusoids all individually ganging together at the same time.

I do have a very big appreciation for frequency domain concepts, frequency domain theory etc. The application of that theory is tremendous.

Also, I agree absolutely about what AVR_fred wrote.