# Frequency, duty cycle and RC filter questions

#### jimmiegin

Joined Apr 4, 2014
49
Hello. I am designing/building a pwm using a 555 then taking the triangle wave ( 20KHz) from the cap in the RC filter to the inverting pin of an open loop op amp and varying the duty cycle by varying resistance from the non inverting pin to + and - of the dual rail supply. Then output to RC filter to give a dc out.
This is all well and good but.... I just don't get how Frequency remains at 20KHz if the on/off time is changing. How does the RC filter maintain roll of at a given frequency. If this is to much typing or theory to explain, might someone have a link that could enlighten me? I have the math, I can now put the circuits together but what good is running numbers and knowing targets if I don't really understand how it really works? Surely pretty soon I will come unstuck. Thanks for taking time to read my post.

#### crutschow

Joined Mar 14, 2008
25,259
The large Fourier fundamental frequency component remains at 20kHz since the switching frequency doesn't change but there are harmonics that vary from the duty-cycle of the PWM signal. You can do a Fourier analysis to see the harmonic changes, if you desire but that's way more math than I care to tackle.

The LP filter doesn't care about the particular frequency of the harmonics since every thing above its corner frequency (which is generally well below the fundamental) is rolled off including the fundamental and all the harmonics.

#### wmodavis

Joined Oct 23, 2010
739
The frequency is the number of repetitions of one complete cycle in one second of time. Does not matter what happens between the full cycle. The pulse width is however affected by that mid cycle transition.

#### jimmiegin

Joined Apr 4, 2014
49

#### MrAl

Joined Jun 17, 2014
7,756
Hi,

The fundamental is the lowest frequency of interest. If your RC filter can take care of that (smooth it enough) then it can certainly handle all of the harmonics that come out with the fundamental because they will be higher, and the filter works even better with the higher harmonics.

Worst case is the fundamental, and the more narrow the pulse width the less fundamental you get so it actually filters better once the pulse gets more narrow.

The shorter the pulse width, the more dominant the higher harmonics become and the less dominant the lowest frequency becomes, and the lowest frequency is the fundamental.

Some of the higher harmonics get cut by virtue of the ramping nature of the output of the op amp rather than a nice clean pulse. This will interfere with the calculated value of the output to a certain degree depending on the op amp. For a 1MHz op amp 20khz is significant for large output signals due to the slew rate.

#### jimmiegin

Joined Apr 4, 2014
49
Hello MrAl. Thank you for your reply, what would be called a "large" signal output....All being relative of course. What would be a best bet freq so as not to be badly affected by the op amp for 0-5V output after filtering?

#### MrAl

Joined Jun 17, 2014
7,756
Hello MrAl. Thank you for your reply, what would be called a "large" signal output....All being relative of course. What would be a best bet freq so as not to be badly affected by the op amp for 0-5V output after filtering?
Hi,

5v would be considered large here because it could take significant time for the output to ramp up (or down).

To give you an idea of how this works, the period of a 20kHz square wave is 1/20000=5e-5 and a low end op amp having a slew rate of 0.5v/us ramps up from 0 to 5v in 1e-5 seconds, and this is already 1/5 or 20 percent of the time of the total wave, or a whopping 40 percent of the half period of the 20Khz square wave. That would cause significant error.

Bringing the frequency down to 500Hz means the error goes down to around 1 percent, which isnt too bad. That's a much lower frequency but that is the way this works. To get better, go to a faster op amp. For example, if we find one with a slew rate of 5v/us (ten times better) then we can increase the frequency to 5kHz, which is probably good enough.