Go Down

Topic: PWM spikes - circuit or scope? (Read 335 times) previous topic - next topic

klover137006

Aug 25, 2019, 06:02 pm Last Edit: Aug 25, 2019, 06:06 pm by klover137006 Reason: Error when attaching images
Hi!

I'm experimenting with getting clean analog voltages using PWM with the goal of building a MIDI-to-CV converter for an analog synth.

With help from Secrets of Arduino PWM I managed to setup a ~63kHz phase correct PWM signal on pin 3.

(I want as high frequency as possible to easier achieve smooth signals with short setting time.)

While measuring with a scope I see spikes (as you can see on the first picture). That's ok since I'm going to filter the signal anyway.

But, the spikes won't completely go away even after filtering. (I experimented with an RC filter consisting of a 1Mohm resistor and 1uF capacitor and still the spikes were there.)

I've attached a picture of how it looks after filtering the signal with a Sallen Key filter (R-values 5.6k, C-values 0.01u). Sure, the spikes are smaller but I suspected them to be completely gone with this filter.


After googling, I learned that often these spikes are actually inside the scope but I didn't learn whether they should still be visible after filtering or not.

It would really help if someone here could take a look at the pictures and say what they think? Is it something with my circuit I need to fix or should I just ignore the spikes?

Thanks in advance!  :)

MarkT

The spikes are normal if you use standard scope probe with a trailing ground clip, the inductance of the ground clip's wire is significant and causes ringing with stray capacitance in the scope input and acts as a loop antenna too.  Using x10 probe mode will usually reduce this (and you should be using x10 mode unless there's a reason not to, it imposes much less capacitance on the circuit under scrutiny).

With a low inductance probe you'll normally see much better behaviour, but they are really cumbersome to use.

Setting the 'scope's input filter bandwidth lower will also usually deal with this.

Logic signals change at massive rates, 1000V/µs is common, and under load the rate of current change can be
measured in A/µs (say if an LED is switched by a microcontroller output).  This is why small stray capacitances and inductances can exhibit spikes with such signals - they have much larger rates of change than heavy duty mains equipment, for instance.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

klover137006

Yes, that's the kind of probe I'm using, and it's in the 10x mode. So it's normal to still see traces of these spikes even after I've filtered the signal?

MarkT

Yes, because you're seeing them!  Its likely coming in on the ground and supply traces, not the circuit node you are probing, and remember the stray inductance of that ground probe wire is a big deal at the speeds involved.

Opamp filter circuitry isn't going to be aware of the fast edges propagating through the PCB traces, much less stop them, these are a nano-second timescale events.

To filter high speed signals requires high speed techniques, not opamps.  Basically good shielding, ceramic
decoupling capacitors, groundplane, low-inductance traces.

By the way your logic circuitry is all well decoupled I suppose?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

klover137006

At the moment the circuitry consists of the Arduino hooked up to a breadboarded Sallen-Key filter, nothing else. The filter op-amp isn't decoupled actually, so I guess I should fix that.

What I'm trying to figure out is whether or not the spikes will still be there when the scope is removed. As I said, this circuit will be going into an analog synth which expects a nice clean analog signal and I don't want these inductive spikes affecting the VCO.

If this is an effect of the high-speed switching going on and not just the oscilloscope's reaction to it than I guess PWM is not the way to go and I might instead look at using a resistor ladder or maybe a discrete DAC chip.

manveen_singh



Pwm Before filter




PWM after filter

klover137006

Thanks for making the images visible!

I've now hooked up my circuit to my synth and measured the output using the scope. The frequency changes the way it's supposed to, i.e. 1 oct/V and the waveform doesn't look distorted or anything.

BUT

I've also measured the output with another high-precision instrument: my ears. The output is not as clean when my circuit is plugged in. Much more overtones and it sounds like frequency modulation to me.

If you look at image #2 you see that the overall signal looks like a noisy sinewave at 63kHz with an amplitude of roughly ±10mV. The spikes on the other hand make up a sort of pulsewave at the same frequency but with an amplitude of ±200mV.

So, the question is, does the output sound like it's modulated by a noisy low-amplitude sinewave or a steady higher-amplitude pulsewave. I'm leaning towards the former but I'm not sure. I'll have to try and simulate the two in the computer and see which it sounds like.

ReverseEMF

#7
Aug 26, 2019, 06:59 pm Last Edit: Aug 26, 2019, 07:03 pm by ReverseEMF
markT is far more knowledgeable on this subject than I am, so my $0.02 is merely to fill in the gaps:

  • As mark stated, the spikes are from high frequency events, and a 1uF cap is unlikely to behave like a capacitor at those frequencies.  Here's a YouTube video that discusses this: https://youtu.be/BcJ6UdDx1vg  --  and he has several other videos on similar topic.
  • All traces, wires, leads behave as inductors.  The longer they are, the more inductance.  The more "bendy" they are, the more inductance.  And inductance causes spikes, and deteriorates filtering.
  • Surface mount components, placed as close to the thing to be decoupled, or as close to other filtering components as possible will limit these inductive effects. 
"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

klover137006

Thanks!

It seems that the higher the frequency, the more difficult it becomes to just breadboard a circuit and expect it to run flawlessly, when you have such limited knowledge and experience as I.

So, I borrowed some books from the library and decided to improve my basic understanding of electronics. And probably, I'll skip the PWM for now and go with the R-2R approach instead. Me trying to calculate how much of a non-linearity I can expect with the resistor values I have at hand has proven to be a useful exercise in circuit analysis.

TomGeorge

#9
Aug 28, 2019, 02:30 pm Last Edit: Aug 28, 2019, 02:31 pm by TomGeorge
Hi,
Does your x10 probe have a hole in the side with a screw head in it?
Does your scope have a squarewave output teminal?
It is usually a small terminal that you ca clip the probe to, sometimes it has "cal" or  a squarewave icon on it, 1Vp-p or 5Vp-p.

If you are experiencing spikes on the squarewave or rounded edges, check the waveform on that terminal, if needed adjust the screw head to compensate for the spikes or rounding.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

wvmarle

I'm experimenting with getting clean analog voltages using PWM with the goal of building a MIDI-to-CV converter for an analog synth.
Just wondering, why don't you use a DAC? Much easier to work with, and quite likely much better output.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

klover137006

If you are experiencing spikes on the squarewave or rounded edges, check the waveform on that terminal, if needed adjust the screw head to compensate for the spikes or rounding.
Thanks, Tom! :) I've already calibrated the probe so unfortunately that is not it.

Just wondering, why don't you use a DAC? Much easier to work with, and quite likely much better output.
No reason, really. Don't have any lying around and instead of ordering some I thought I could achieve a good analog signal using PWM, but it proved to be quite the challenge to get it both straight and fast enough for audio use, so I'm rethinking this. :)

wvmarle

The folk behind the TMRpcm library do a pretty good job without the use of any filters.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

klover137006

Interesting! Well, I listened to one of the samples and it suffers from a lot of artifacts. And that is not due to it being 8-bit because 8-bit audio mostly raises the noise level.

But, just to clarify, when I said audio I didn't mean generating audio signals from PWM, but generating a Control Voltage to control the audio coming from my synth.

The voltage raises or lowers the frequency, and 1V corresponds to an octave. So, the voltage needs to be a very steady DC signal, or it will generate a lot of overtones. At the same time, it needs to change very fast (is it called settling time?), otherwise the tones will glide from one to another, and that is not always desirable.

JohnRob

Regarding your scope probe.

I don't know what probe you have or much about the Siglent.

All the x10 probes I've ever used required high frequency compensation with the scope you are using.

There is usually a small screw on the probe or the connector housing to compensate for high frequency performance.  If it is set incorrectly it could cause spikes like the thin ones in you photo.   My Tec scope has a 1V square wave output for probe calibration.

In the Siglent I just googled there is a "calib and gnd" right in the middle for this purpose.  Connect both the probe and ground to these two points.

John


Please do not PM me with thread based messages.  If your thoughts are worth responding,  the group should benefit from your insight.

Go Up