Need help cleaning up PWM signal with RC filter - Page 1
Forum section: electronics / beginners

author: Aeternam
author_rank: Unknown
timestamp: July 06, 2016, 05:55:23 pm
content: Hey all,I should be able to figure this out by myself but I'm afraid I'm drawing blanks at the moment.I have a PWM signal at 16 kHz and two PWM signals at 60 kHz. See attached screenshot. As you can see those signals are pretty noisy -- I'd like to clean them up a bit.So I figured, since the noise is at a higher frequency than my signal I'd need a low-pass RC filter. The signal I'd like to clean up (CH1 / yellow trace) is at 16 kHz, so let's put the -3dB point at around 2 times that. Fiddling with my calculator I came up with 50 ohms and 100nF. I wired up the filter and placed it between the Mosfet and its driver. Big disappointment, I now have a water wave like signal instead of a square signal and -- worse -- the parasitic injections are still there.Questions:- Why is my signal distorted? With the -3dB point at 2x the signal frequency the filter should leave the signal alone shouldn't it?- How do I determine (as a rule of thumb) the correct cutoff point in order to filter out noise like this? Clearly my assumption of taking 2 x the signal frequency is wrong. Why?Yes, the thing is on a breadboardBut even so I should see a cleaner signal with the correct filter...Much oblidged !

author: MosherIV
author_rank: Super Contributor
timestamp: July 06, 2016, 06:03:42 pm
content: HiFiltering may be wrong because it is trying to mask the problem not cure it.QuoteYes, this could cause capacitivly coupled noise.Take a look at where the noise spikes are in relation to what each signal is doing.What does this look like it is doing?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: July 06, 2016, 06:05:23 pm
content: Quote from: Aeternam on July 06, 2016, 05:55:23 pmBecause it's a square wave. A sine wave only has power at the fundamental frequency, a square wave has power at the fundamental plus every odd-ordered harmonic extending out infinitely. You need a pass band that extends WELL beyond the fundamental in order for the result to still look something like a square wave.https://en.wikipedia.org/wiki/Square_wave#/media/File:Spectrum_square_oscillation.jpg

author: Aeternam
author_rank: Unknown
timestamp: July 06, 2016, 06:28:43 pm
content: Quote from: MosherIV on July 06, 2016, 06:03:42 pmYes I guess it's pretty obvious. Frickin' breadboards, EVERY time.I'll leave the circuit as it is for now and measure again once I have it on a decent PCB.

author: Aeternam
author_rank: Unknown
timestamp: July 06, 2016, 06:36:19 pm
content: Quote from: suicidaleggroll on July 06, 2016, 06:05:23 pmSo -- in layman's terms -- when I put a square wave through a filter that is too narrow I cut out too many harmonics and the resulting waveform is anything BUT a square wave. Correct?

author: MosherIV
author_rank: Super Contributor
timestamp: July 06, 2016, 06:36:48 pm
content: QuoteDo not jump to conclusions so easily.Since, you did not answer my question (where I was trying to lead you somewhere)I will tell you where I was leading you.........Switching noise. This is more to do with disturbances to the supply rail.Try adding decoupling caps to near each switching transistor.Does the noise change in ANY way?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: July 06, 2016, 06:53:41 pm
content: Quote from: Aeternam on July 06, 2016, 06:36:19 pmYes. Perhaps an easier way to think of it is the sharp edges of the square wave require VERY high frequencies to reproduce. The sharper the corner and the faster the edge rises, the higher the frequency. When you start lowpassing the signal, the sharp edges and corners are reduced/disappear. Filter it enough and it'll turn into a sine wave.

author: danadak
author_rank: Super Contributor
timestamp: July 06, 2016, 09:24:02 pm
content: This will help with filter design, attached.Regards, Dana.

author: StillTrying
author_rank: Super Contributor
timestamp: July 07, 2016, 12:26:16 am
content: Quote from: danadak on July 06, 2016, 09:24:02 pmDid you go just by the Subject titleMuch of the 200nS pulses could be just the scope ground picking them up.

author: Ammar
author_rank: Regular Contributor
timestamp: July 07, 2016, 01:00:52 am
content: Two things:1. Breadboard, yeah maybe, but at 16KHz it really shouldn't be much of an issue.2. The thing with square waves is that they are actually made up of harmonics. The fundamental frequency might be 16KHz, but that sharp rise and fall could even have GHz harmonic content depending on the rise/fall time.Find the rise/fall time period and convert that into a frequency. See what you get.

author: woodchips
author_rank: Frequent Contributor
timestamp: July 07, 2016, 05:45:19 pm
content: Isn't there something being forgotten here?The title and description describe this as a PWM signal, this is pulse width modulated. With the narrower than 50% pulse width then the frequencies contained in that waveform will be much higher than the basic 16kHz. The frequncy comb will cross through zero at the base frequency multiplied by the mark space ratio, why a square wave doesn't have any even harmonics.Any filtering on this type of signal does seem pretty futile.

author: rstofer
author_rank: Super Contributor
timestamp: July 07, 2016, 08:15:17 pm
content: That trash riding on the signal may be caused by switching power supplies. Either those serving the project or anywhere in the same building or neighborhood. Since it doesn't matter, why worry about it?I have exactly the same kind of thing on an analog computer where every single wire has the same trash. Still, it gets the right answer simply because the frequencies are too high to cause the integrators any issues.I doubt that these signals will have any measurable effect on a PWM driver.

author: MosherIV
author_rank: Super Contributor
timestamp: July 08, 2016, 06:43:34 am
content: QuoteI agree that the noise may be switching niose but as I pointed out before, since the disturbance is perfectly aligned with the pwm edges, it is linked to the pwm switching itself.Agreed, is it a problem?

author: danadak
author_rank: Super Contributor
timestamp: July 08, 2016, 09:38:23 am
content: Usually this is caused by L somewhere in circuit, high current path like ground,Vcc bypass caps with excessive lead dress.......Expand the transient error and compute the freq by measuring the time from the first- peak in the transient to the next. Use resonant LC tank freq calculation. This thencan be used to infer LC product, then guessing at stray C you can get an idea of Linvolved. This by no means an exact science as reflections could be involved, groundreturn paths, lead dress.....But it can sometimes give you clues.Not all bypass caps, for the same C value, are equal. For example in the scheme ofthings, bulk bypass, poor to best, electrolytics > Tantalum > Polymer Tanatalum.The latter is best. Same for ceramics, actually look at datasheet, their f vs z curveswill indicate quality of the cap and its construction.Regards, Dana.

author: oldway
author_rank: Super Contributor
timestamp: July 08, 2016, 10:19:32 am
content: I really don't see any harmful noise in this PWM signals....The amplitude of noise is far less than halve of the nominal value.But if you worry about this, use buffer stages with hysteresis and your signals will became fully clean.

author: Aeternam
author_rank: Unknown
timestamp: July 08, 2016, 01:37:37 pm
content: Thanks for all the input. Indeed the noise is not harmful, the circuit is working as intended. Still I'd like to understand what's going on here, this is more of a learning thing than anything else.I added a 100 ohm resistor to the signal source, this reduces ringing on the edges. This is a good thing, but noise is not really attenuated.I sprinkled caps around the circuit. This does 2 things:- I get less noise (which is good),- I get considerably larger rise and fall times (which is bad since the transistors will spend 2-300% more time in linear mode).After a bit of searching and reading up on things I've come to the conclusion that the switching of the transistors is probably the root of the problem: Visual inspection of scope traces shows that the noise is in sync with any one transistor switching. Disconnecting 2 of the 3 PWM signals eliminates the noise completely; and the power supply is reasonably clean. There is (a lot) less noise with lower switching frequencies. All this tells me that the noise is probably due to stray inductance, and the problem is amplified by the fact that the whole thing is currently mounted on a breadboard with cables crisscrossing willy-nilly.Filtering this thing is going to be hard because a) the duty cycle is not fixed (hence the baseline frequency is changing over time) and b) this is a square wave and the RLC calculations needed to do this properly are out of my leage. So filtering is not really an option, noise should be less once this thing is mounted on a proper PCB anyhow.Conclusions?I should reduce the switching frequency. A few Hz are sufficient for my needs, there's really no need to go to the kHz range. This is the most economic way to fix this.When assembling I should probably use a 4-layer PCB and sandwich the switching lines between 2 ground planes. I guess I'll try this, should be an interesting experiment.

author: StillTrying
author_rank: Super Contributor
timestamp: July 08, 2016, 10:22:22 pm
content: A few of us think you're trying to fix a problem that doesn't exist, those waveforms look fine for a switching circuit. And I hope you've tried 1 Channel and a short probe ground clip, instead of the 6 inch ground lead.