# Best tools to debug simple digital circuits?

I am a professional software developer who is used to the luxuries of integrated debuggers. For a while now, I have been experimenting with the Arduino platform. However, I find that attempting to interface with components like a Dallas DS1820 digital temperature sensor is like fumbling around in the dark.

Assuming a loose budget of \$200 or so, what kind of tools are there to help me visualize what's going on? I have looked at the Link Instruments MSO-19, but I honestly don't know a whole lot about the difference between an oscilloscope and a logic analyzer.

How do I know that the device I buy will be capable of measuring the types of (simple) components I am using?

essentially, an oscilloscope gives you a graded reading of the voltage on the line while a logic analyzer will only tell you if it is 0 or "high" (the value of "high" could potentially be 5V, 3.3V or 1.8V depending on your circuit). You will often see that logic analysers have many more channels (lines that can be read simultaneously) than oscilloscopes because of the lower resolution required.

As for a specific device, I have heard great things about the Saleae Logic. It samples at 24MHz; this means it checks if the voltage on a particular probe is high or low 24 million times a second. The software also appears to have some knowledge of the common embedded protocols to aid debugging. I would imagine that 24MHz would be enough for arduino work as the maximum clock speed of the Atmegaxx8 is 20MHz.

• After a half-day of more research, I can say that Saleae Logic should help me out with 90% of the ideas I have, for now. The software looks polished and intuitive for a hardware "outsider" such as myself. I can see how an oscilloscope would be immensely helpful, but for the types of simple projects, a USB logic analyzer seems like a good tradeoff. – Owen Thomas Jul 17 '10 at 16:55
• In The soul of a new machine Tracy Kidder says (paraphrasing) that cavemen used an oscilloscope to see why the fire wouldn't burn. :-) – stevenvh Dec 5 '10 at 10:26

this is just an addition to penjuin's answer as it didn't fit in a comment and his answer is generally correct. Just want to clarify an implication in his answer.

Be very careful choosing a measurement device based on its bandwidth/sampling rate. A device with a 25mhz sampling rate can not accurately sample a 25mhz digital clock signal, not even close.

If you take a digital clock signal at 25mhz and feed it into an o-scope with a bandwidth of 25mhz you will see something close to a sine wave. A scope with a 25mhz sampling rate would probably show a DC level since per Nyquist, the highest frequency signal such a scope could sample would be 12.5mhz.

A square wave contains is fundamental frequency which is its clock rate, for this example 25mhz. It also contains large odd harmonics which give its square shape, to look at a 25mhz digital clock signal with accuracy you would need to not only look at 25mhz but 75, 125, 175, 225, etc. How far you need to go is up to your desired accuracy or up to the slew rate of the transceiver.

While this is slightly less important for a logic analyzer is still very important. The logic analyzer is looking for a 'high' and a 'low' above or under some threshold. If what is sees coming in is a sine wave you will see artificially short high and low states and artificially long spaces between bits. This can be somewhat dependent on the architecture of the analyzer.

This can make diagnosing issues related to various transmit modes impossible. For instance SPI has 4 different modes based on data being valid on the rising or falling clock edges and also on data polarity (is high a 1 or a 0?). Other transmission protocols also have this issue (I2S and related audio formats for example). If you can't accurately identify when the edge transitions take place its nearly impossible to determine if the bus is acting within specification.

Generally you need bandwidth/sampling rates much higher than your intended target data rate. If you want to sample a 40khz I2C bus, a logic analyzer with a sampling rate of 100mhz is more than enough. If you need to sample a 25mhz SPI bus you need to have a scope/analyzer with a much higher bandwidth, something near 500mhz if you need real accuracy, as well as a sampling rate that allows measurement in that frequency range.

So the device penjuin recommended with a sampling rate of 24mhz can likely only provide accurate measurement of digital signals that are less than ~2mhz with a slew rate appreciable to that data rate.

• you are absolutely correct, this completely slipped my mind. To help illustrate this effect further, I fed a 1khz square wave into my oscilloscope and took a screen dump of the resulting Fourier transform (x axis is frequency basically): i.imgur.com/lJvtD.png . The harmonics are the repeating peaks. – jeremy Jul 16 '10 at 1:58
• @penjuin perfect illustration. Just to clarify my answer for the owen, the device penjuin recommended is likely very capable of dealing with an ardunio, as you will likely never need to deal with an interface running at >2mhz with that class of device. I just wanted to make sure he didn't take it as a rule of thumb and have it end up biting him if he moves on to higher speed devices/interfaces later on. – Mark Jul 16 '10 at 2:33
• A logic analyzer with variable threshold configured properly usually provides sufficient resolution for analyzing logic at only a few factors higher than the signal frequency. The problem exists in that the controller receiving the signal will switch to logic zero for anything below 1.2V (for example) and the the logic 1 for anything above 2.2V (for example) while the logic analyzer might switch over at 1.7V making the timing less precise. In many cases a sample rate of about 2-3 times faster in a digital circuit is sufficient to understand what is going on. – Wouter Simons Jul 16 '10 at 13:42
• @wouter simons careful not to confuse bandwidth and sampling rate (i actually cleaned up my word usage in the answer as well). A sampling rate of 2x the frequency of your signal is the bare minimum to detect that signal. In practices scopes and especially analyzers usually oversample a lot. For instance my tek scope has a 100mhz bandwidth but samples at 2.5ghz. – Mark Jul 16 '10 at 16:03
• Great answer. I followed your post just fine and can probably still measure what I want with one of the cheaper devices out there. I'll keep an eye out for limitations as I explore more complicated components. – Owen Thomas Jul 17 '10 at 16:51

If you plan to work mainly on digital circuits, the logic analyzer is what you want. Oscilloscopes excel at showing a relatively few (e.g., 2-4) analog signals in fine detail, whereas logic analyzers, since they are concerned mainly with high-vs-low usually have a great many more inputs.

You can certainly use an O-scope as a logic analyzer, but the advantage with the latter is that it's easier to get 'the big picture' by being able to watch dozens of signals simultaneously.

There are some good answers to this similar question: Beginner's logic analyzer?

As far as logic analyzers go, I wrote a basic comparison of (relatively) inexpensive ones:

Comparison of PC-based logic analyzers

One thing to note about sampling speed, a rule of thumb is you generally need at least 4x your data rate in order to get an accurate reading, and up to 10x is better. So if you want to monitor a 8MHz signal (which you can easily generate from an inexpensive AVR in SPI for example), you'd want a 32-80MHz sampling rate analyzer. This only applies when capturing in 'async' mode. If you are capturing in 'synchronous' mode (eg with a clock signal), then your sampling rate only needs to match the rate of the clock signal. So for example in that case, 8MHz synchronous sampling would be enough to capture a 8MHz SPI signal (since it has a dedicated clock signal).

I own an MSO-19 and like it a great deal. I wish it had more than one analog channel, but it does function as both an oscilloscope and a logic analyzer. For the price, I think it's a nice piece of equipment (and runs well in VMWare on OS X). The o'scope's helped me see what's really happening in a part of the circuit, and doesn't show you just the high/low state of a digital line, as a logic analyzer does. It's a far more accurate (and faster responding) volt meter than your standard multimeter. It would be really nice if it could decode serial data, however, instead of just I2C and SPI…

This answer probably isn't much use to you using ardunio but is an answer to the general question.

I use the logic analyser functions of my pickit2 a great deal. Clearly it's meant for programming PICs but it also has a 3 channel logic analyser mode which I use all the time for looking at digital signals. I still use it for that even though I'm using Cortex-M3 for my current projects. Clearly its an extremely primitive tool by the standard of proper gear but even so I find it incredibly useful

I've used it to debug I2C circuits and TV output signals too for example see my post here

This is pretty cool, and really cheap: http://www.seeedstudio.com/depot/preorder-open-workbench-logic-sniffer-p-612.html?cPath=75

It has decent sampling rate, and you can support a cool open HW project. It looks like it is still in a sort of beta stage, so it might not be the greatest thing if you just want to plug something in and have it work.

• I just bought this a month ago, since I was working with a netbook primarily, I had issues with the screen size of my computer to be able to click the "capture" button, but if you have a normal sized laptop or desktop computer you'll be fine. I haven't used it extensively, but I the little I have I like, and the price is nice too! – onaclov2000 Aug 20 '10 at 14:10
• I am using this LA quite a bit, and since this is my first LA, I am probably using less than 50% of power/functionality it provides. Comparing various other low cost LA's, I found it to be one of the best value-for-money LA's. The software isn't bad. In fact I found it to be fairly good for my purposes. If you want to see how I've used it, just click on my profile and see the questions I've asked. – icarus74 Dec 22 '11 at 11:58