Go Down

Topic: Square Wave from Arduino Due. Is it square enough? (Read 2616 times) previous topic - next topic

JoeN

With some code from "stimmer" I did the old standby of banging a square wave from an Arduino Due using digitalWrite and then doing it again using port manipulation.  Port manipulation accomplishes a 21 Mhz "square" wave, exactly 1/4 of the rated clock speed of 84 Mhz.  It's not that square, though I guess it would trigger a digital input fine. FWIW, the waveform it does make it certainly does reproduce the same way each time though.  Is that right, is this a clean enough square wave to use with most other digital ICs?

digitalWrite:



Port manipulation:



I have only come here seeking knowledge. Things they would not teach me of in college.

MarkT

Your scope is 70MHz I believe, so a 20MHz square wave will only show upto the third harmonic...
[ I won't respond to messages, use the forum please ]

JoeN


Your scope is 70MHz I believe, so a 20MHz square wave will only show upto the third harmonic...


Now I do not know a lot about scopes, I've got more scope here than knowledge for sure, but it's a digital scope with a 2GS/s sampling rate.  I'm pretty sure it uses all the sampling ability even though it (in software!) limits the maximum resolution to 70mhz (and they spec different probes for over 100Mhz too).  That is interesting, though, I am going to have to borrow a better scope and try it out on another one.
I have only come here seeking knowledge. Things they would not teach me of in college.

oric_dan

Hmmm, all that ringing on the signal leads me to believe you don't have the "ground" wire
on the scope probe positioned properly. It should be connected to the ground point nearest
the signal being measured, and not somewheres on the other side of the board, etc.

Plus you should darn well be using a 10X scope probe for high-frequency measurements.


JoeN

#4
Nov 24, 2012, 07:52 am Last Edit: Nov 24, 2012, 08:09 am by JoeN Reason: 1

Hmmm, all that ringing on the signal leads me to believe you don't have the "ground" wire
on the scope probe positioned properly. It should be connected to the ground point nearest
the signal being measured, and not somewheres on the other side of the board, etc.

Plus you should darn well be using a 10X scope probe for high-frequency measurements.


OK, I am willing to take instruction here for sure.  The way I have this set up I have, and maybe this is too long, a 3" jumper on the 2 pin on the Arduino board and a 2" jumper on GND nearest that pin and I have the probes attached with alligator clip (gnd) and hook clip (2 pin) the jumpers.  I calibrated the probes prior to taking the measurement.

Where the scope says "DC 10:1" I am pretty sure that means it is in the 10X mode - it said it was in another menu as well.  These probes are Agilent N2862B 10:1 150Mhz passive probes.  There is no 1:1 option.

What should I do differently?  Thanks for suggestions!
I have only come here seeking knowledge. Things they would not teach me of in college.

JoeN

#5
Nov 24, 2012, 07:59 am Last Edit: Nov 24, 2012, 08:06 am by JoeN Reason: 1
OK, I shoved a couple of 1 pin male headers in there to keep it as short as possible.  Much better now.  Anything else I can do to improve it?

I have only come here seeking knowledge. Things they would not teach me of in college.

oric_dan

Looks much better now, although the probe grounding could probably be improved
a bit. Most important is the total length of the probe ground wire, including extensions,
be the minimum possible. The longer wire produces a big inductive loop that rings and
propagates noise like a loop antenna.

Now, when feeding your 20-Mhz signal out to the rest of the world, you can try using a
small value R [ie, 22 or 47 ohms] in "series" in the "output" line, to limit ringing. Look up
something called "source series termination".

JoeN

#7
Nov 24, 2012, 08:58 am Last Edit: Nov 24, 2012, 09:00 am by JoeN Reason: 1

Looks much better now, although the probe grounding could probably be improved
a bit. Most important is the total length of the probe ground wire, including extensions,
be the minimum possible. The longer wire produces a big inductive loop that rings and
propagates noise like a loop antenna.

Now, when feeding your 20-Mhz signal out to the rest of the world, you can try using a
small value R [ie, 22 or 47 ohms] in "series" in the "output" line, to limit ringing. Look up
something called "source series termination".


So I have gotten the leds from the Arduino as short as possible to the probe and grounding clip.  The probe itself as provided by Agilent has a hook for the probe and a grouding clip that you hook onto the probe around the neck where the wire itself is 3.5" long and it is extended in length with a crescent clip on one end to attach to the probe and the alligator clip on the other.  The spec on the probe wire is 1.2 meters.  So I wonder, is the "problem" the Agilent ground wire?  It could be shorter but it's pretty darn short already and Agilent is clearly happy with it.  This is the probe with the grounding clip attached:

http://www.home.agilent.com/en/pd-1938439-pn-N2862B/passive-probe-101-150-mhz-12-m

Are there better choices?  Agilent seems to think this one is $110 worth of probe and they gave me two with the scope.
I have only come here seeking knowledge. Things they would not teach me of in college.

oric_dan

Critical thing is the loop at the tip of the probe, not the length of the coax. [time
for sleep now].

Grumpy_Mike

The scope probe is vital. You can pay more for a good scope probe than many scopes.
Your real wave shape is square, anything else is either an effect of the load or an artefact of the measurement. You learn to see the wave not what is shown on the screen. The bandwidth of the amplifier in the scope also has an effect. You can sample as fast as you like but you won't get over this. In general you will only see a squarish wave when your scope bandwidth is at least ten times the frequency you are looking at.

dhenry

Quote
I did the old standby of banging a square wave from an Arduino Due using digitalWrite


If you really want to know your Due's pin flipping capability, google "arm bit banding".


James C4S


but it's a digital scope with a 2GS/s sampling rate.

That just tells you how fast the A/D samples.  

In your case, you are using peak-detect which is throwing samples away.   Even though you are significantly oversampling, you should really turn that sampling mode off if you're trying to visualize what the waveform actually looks like.


limits the maximum resolution to 70mhz (and they spec different probes for over 100Mhz too)

That isn't quite right.  The bandwidth of the scope defines the analog bandwidth that gets sampled by the A/D.  So this tells you no matter how fast the A/D runs, the fastest signal your scope will accurately measure is 70MHz.  The analog bandwidth can also tell you the fastest rise time the scope will be able to reproduce/measure.  If your rise time matches the analog bandwidth, that's a good sign your signal contains content faster than your scope can reproduce. 

As Mark mentioned, this means with a 21MHz signal, you're only seeing the 3rd harmonic.  Without the 5th (and maybe 7th) you won't see much of a square wave.

Remember that square waves are actually multiple sine waves added together.  
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Grumpy_Mike

Quote
Remember that square waves are actually multiple sine waves added together. 

That applies for any wave shape that is not a sin wave.
Edges like you get in square waves have an infinite number of sin wave harmonics making up that vertical edge.

retrolefty

#13
Nov 24, 2012, 06:24 pm Last Edit: Nov 24, 2012, 06:59 pm by retrolefty Reason: 1
Quote
Remember that square waves are actually multiple sine waves added together.


To be more precise a square wave is made up of it's fundamental frequency plus all it's odd harmonics. So your scopes (and it's probe) ability to accurately display the real wave shape of the applied square wave is how many of those harmonics can the measurement instrument system accurately reproduce, which is related to the bandwidth specification of the measurement system. That is why GM stated that a good rule of thumb is that scope (and probe) should be rated at 10X the bandwidth of the frequency to be measured.

To put that into perspective that means to accurately display the true wave shape of a 10 Mhz square wave one should be using a measurement system (such as scope plus it's probe) rated to be flat out to 100 Mhz, or better yet higher then that. A scope rated at 10 Mhz will not be able to accurately display a 10 Mhz square wave.
So the ARM chip is developing true square waves (perhaps limited only by it's raising and falling transition specs, the tops and bottoms are 'flat' leaving the chip, so any variation (dips and peaks) in the wave shape is an artefact of your measurement system.

Lefty

oric_dan

Quote
It could be shorter but it's pretty darn short already and Agilent is clearly happy with it.  This is the probe with the grounding clip attached:

http://www.home.agilent.com/en/pd-1938439-pn-N2862B/passive-probe-101-150-mhz-12-m


I'm sure that probe is fine, and not the problem. Those things are made for much higher
frequencies than you're using. Just don't add any extra length in hooking up the ground lead.
One thing you might try is using an output pin of the DUE that is close to a ground pin on a
header. Also, you definitely should try source series terminaton, as I mentioned.

The Arduino board female headers are not very ideal for sending out high-frequency signals
either. Especially if you're tapping into them using those funny little wire leads with male pins.
Totally not optimal.

Go Up