PWM Spike - What am I seeing? - Page 1
Forum section: electronics / beginners

author: bitshift
author_rank: Regular Contributor
timestamp: March 10, 2015, 03:38:30 pm
content: Hello everyone,I'm new to the forum but I've been watching Dave's videos for a while though. Great stuff!So I'm a programmer by profession but I've been dabbling in basic electronics projects in my spare time for a while. I recently purchased a Rigol DS1054Z. It's my first scope and needless to say I'm basically a complete noob.So to my problem....I've hooked up my scope directly to one of the digital pins on an Arduino board. I've programmed the Arduino to output a 50% duty cycle PWM wave at 62500Hz.When poking around with the scope, I noticed a massive spike of about 1V from the expected 5V level when the pulse rises. A similar pulse is there on the fall but, according to the scope, drops below 0V.From a bit of googling, I've learnt that this could be a result of using an uncompensated probe so I made sure to compensate my probe.I've attached screenshots of me compensating the probe, the spike on the pulses and the setup.What could be causing this spike? Is it the Arduino or the scope?TL;DRWheres the spike in the PWM signal coming from and what can I do about it?

author: Electr0nicus
author_rank: Regular Contributor
timestamp: March 10, 2015, 03:54:47 pm
content: There are a few things:1. Thats because you have a signal with a very short rise and fall time. Remember not the frequency is important (it is actually relatively low in your case), it's the rise time. Every signal, even a square wave, is composed only of sinusodial signals (fourier series) with different frequencies. You have the main signal with 62,5kHz and then signals at the harmonic frequencies 3*62,5kHz 5*62.5kHz and so on. The more harmonic frequencies are present the faster the signal rises and falls. So in your case you have a very fast rise and fall time, so there are harmonics present at much higher frequencies than 62.5kHz. Those high frequencies are likely to create ringing with the parasitic L's and C's. If you add a series resistor in your signal path (eg. 33Ohm) the spikes should be smaller.2. Probe setup. If you really want to know whats going on, you need to omitt the ground clip on your probe. You need to use a thing called "probe spring" which directly attaches to the tip of your probe and lets you measure your signal more accurately. The ground clip acts as a antenna and you pick up all sorts of interference.

author: katzohki
author_rank: Frequent Contributor
timestamp: March 10, 2015, 04:44:34 pm
content: Others have explained the reason behind the phenomenon and will probably continue to do so. My advice about what to do about it is ignore it.

author: bitshift
author_rank: Regular Contributor
timestamp: March 10, 2015, 05:09:38 pm
content: Quote from: PA0PBZ on March 10, 2015, 03:48:26 pmThanks for the video, using the ground spring definitely reduces the overshoot.Quote from: Electr0nicus on March 10, 2015, 03:54:47 pmI've added a 330ohm resistor and it completely removes the overshoot. What I don't understand is why this works? In my mind all the resistor does is reduce the current flowing out the Arduino?Also when measuring with the resistor connected to a breadboard the result is actually worse? Is this because of stray capacitance in the breadboard?Quote from: Electr0nicus on March 10, 2015, 03:54:47 pmAs a said above, using the ground spring helped to reduce the overshoot significantly.I've attached images of a couple scenarios I've tested.Just to make sure I've got this right, the issue is with the method I'm using to take the measurement and not with the circuit itself?

author: katzohki
author_rank: Frequent Contributor
timestamp: March 10, 2015, 05:20:10 pm
content: Going into a (solderless) breadboard you're going to have ringing from the capacitance in the board. Even though it's not a particularly high frequency signal, the high rise time has high frequency components so that rings with the capacitance. Here's a video:

author: Phaedrus
author_rank: Frequent Contributor
timestamp: March 10, 2015, 05:25:55 pm
content: Quote from: bitshift on March 10, 2015, 05:09:38 pmNo, it is with the circuit, at least partially. Here's a way to think of it: your resistor works with the parasitic capacitance of the board to create an RC low pass filter, which filters out the high frequency signals causing your overshoot.It's abitmore complicated than that when you get into the details, but that's the simplest explanation.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 10, 2015, 05:37:25 pm
content: Conclusion: your probe sucks.It's loading the circuit capacitively, causing the ground clip lead inductance (and probably some length inside the probe body itself) to resonate or overshoot. The series resistor dampens this.A good probe is not supposed to require the resistor, and is also supposed to have a cutoff frequency (due to these characteristic or equivalent reactances) at or above the scope bandwidth, not right in the middle (i.e., it should be difficult or impossible to tell that this is happening!).Tim

author: bitshift
author_rank: Regular Contributor
timestamp: March 10, 2015, 05:41:10 pm
content: Quote from: katzohki on March 10, 2015, 05:20:10 pmAwesome video thanks!Quote from: Phaedrus on March 10, 2015, 05:25:55 pmAh that helps a lot thanks! So I'm going to guess that 330ohms was chosen specifically to attenuate the harmonics of the 62.5khz PWM signal. What assumptions was the 330ohm resistor chosen under?

author: bitshift
author_rank: Regular Contributor
timestamp: March 10, 2015, 05:43:14 pm
content: Quote from: T3sl4co1l on March 10, 2015, 05:37:25 pmWell my scope is a cheapie DS1054Z so I can understand that. Should I do anything about it (buy new probes)? Or should I just carry on with life being aware that it happens?

author: Phaedrus
author_rank: Frequent Contributor
timestamp: March 10, 2015, 05:46:22 pm
content: Low pass filters don't always have to be precise. 330 ohms is a ballpark value. It could be 450 ohms or 220 ohms or maybe even 100 ohms and it would still work.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 10, 2015, 05:53:33 pm
content: You'd have to know the probe capacitance (you could estimate it), and the ground clip inductance (varies with position and length, but maybe 0.2uH?), but the result is a resonant impedance Z = sqrt(L/C). When this is matched with a resistor of the same value, the RLC circuit is critically damped, and overshoot or ringing goes away (depending on which side of the resistor you're measuring from).In defense of the probe, it looks more or less critically damped already (the overshoot is a simple exponential spike, not a ringing oscillation), which suggests it already has resistance inside which is damping it. You're just on the wrong side of it, because of how the circuit is arranged (in particular, with the ground clip as it is).It's also probable that the probe is designed to work optimally with a 50 ohm source, with little regard for how much energy reflects off the probe's impedance itself. So that the source of 50 ohms provides optimal damping, and more (100 ohms, 330 ohms..) merely slows the probe down excessively.The Arduino board layout or wiring seems to be pretty atrocious in the first place: look at how much ripple is on the "logic high" value!Tim

author: bitshift
author_rank: Regular Contributor
timestamp: March 10, 2015, 06:41:17 pm
content: Thanks for the good explanation.In terms of the logic high ripple on the Arduino, I've tested two different boards using USB power and power from a transformer through a bridge rectifier and a 7805. In both cases the ripple on the logic high is about 100 - 150mV peak to peak.Just out of curiosity, can anyone else reproduce this? I just want to make sure my new scope is functioning properly I guess.

author: katzohki
author_rank: Frequent Contributor
timestamp: March 10, 2015, 08:10:09 pm
content: Talking about the ripple on the Arduino, I have heard that the layout isn't great so that could just sort of be a limitation of the board.