# Saleae Articles

Want to learn more about logic analyzers and oscilloscopes? Get started with our guides below or [explore our Logic Analyzers here!](https://www.saleae.com/)

### Logic Analyzers

{% content-ref url="/pages/-LM-P\_4M3e51q264d0Z4" %}
[What Is a Logic Analyzer?](/logic-analyzers/what-is-a-logic-analyzer)
{% endcontent-ref %}

### Oscilloscopes

{% content-ref url="/pages/-LNlnwgIjFV3i781jBZu" %}
[What is an Oscilloscope?](/oscilloscopes/what-is-an-oscilloscope)
{% endcontent-ref %}


# What Is a Logic Analyzer?

## What Is a Logic Analyzer?

A logic analyzer is an instrument for capturing, displaying, and measuring multiple electronic signals simultaneously in a digital circuit. Logic analyzers are capable of showing the relationship and timing among many different signals in a digital system and are often capable of analyzing digital communication protocols, such as I2C, SPI, and Serial. As a result, a logic analyzer is the best tool for debugging digital circuits and digital communication systems.

![Logic analyzer decoding I2C and serial data](/files/-LO4DsO9lp6qIhqCzIZy)

### Invention of the Logic Analyzer

The 1960s saw the rise of the integrated circuit (IC), which meant that circuits started to become smaller. In turn, thousands--eventually millions--of transistors could be packed into a single chip to perform complex digital logic operations, forming the basis for most microcontrollers, microprocessors, and field-programmable gate arrays (FPGAs) that we know today.

As transistor count and pin count grew on these ICs, testing and characterizing them became increasingly difficult. Oscilloscopes have been around since the 1930s, and while they are often considered the de facto test instrument for many electrical engineers, adding more than a handful of channels to an oscilloscope proved extremely costly.

In 1973, Hewlett Packard announced the invention of the first "Logic Analyzer" that could measure and display logic states across a set of LEDs. The HP 5000A was the first commercially available logic analyzer but was limited to only two channels. In the years to come, commercial logic analyzers began boasting dozens of channels that could read and display digital logic in parallel.

![Tektronix Logic Analyzer TLA5204](/files/-LN1SZIDK2XWBrvuOsT4)

*Image credits: "*[*Tektronix Logic Analyzer TLA5204*](https://commons.wikimedia.org/wiki/File:Tektronix_LogicAnalyzer_TLA5204.jpg)*" by* [*Vonvon*](https://commons.wikimedia.org/wiki/User:Vonvon) *is licensed under* [*CC BY 3.0*](https://creativecommons.org/licenses/by-sa/3.0/deed.en)

The oscilloscope is still the perfect tool for analyzing how analog voltages between two points varies over time on up to typically 4 channels. Even for digital systems, an oscilloscope can be great for inspecting analog properties of a signal such as rise and fall times, ringing, power consumption, jitter, and propagation delays. On the other hand, if you require a higher channel count to trace and correlate multiple digital lines simultaneously, a logic analyzer is the right tool for the job.

### What Makes a Logic Analyzer Unique?

#### Recording Several Input Channels

A significant advantage of a logic analyzer is its ability to record a large number of digital signals simultaneously, usually 8 to 100 channels. While oscilloscopes can also record digital data, they typically cannot match the number of channels and recording duration as a logic analyzer due to the memory requirements of storing analog data.

#### Complex Digital Triggering

Similar to oscilloscopes, logic analyzers can be configured to begin recording on a trigger event. Triggers can be as simple as a single rising or falling edge of a particular channel, or they can be a complicated set of conditions that include edges or states of multiple channels.

#### Mixed-Signal Capability

Many modern logic analyzers include some oscilloscope functionality and vice versa. These new tools, capable of recording and analyzing digital as well as analog waveforms, are known as *mixed-signal oscilloscopes*. Test equipment that serve multiple purposes can make characterizing complex circuits and systems easier.

![Analyzing digital and analog waveforms](/files/-LNlaFSDNTBPEOedRFg5)

#### Portability

Many standalone logic analyzers include screens capable of displaying the captured signal data. However, as personal computers become more powerful with faster peripheral ports (for example, USB 3.0), some logic analyzers forgo the screen and rely on computer software to perform the analysis. This saves on equipment size and costs.

![PC-based logic analyzers can be quite small](/files/-LNgNxKCUrJmFEIBSYz2)

#### Ease of Data Navigation

Most logic analyzers work by capturing digital data, storing it in a buffer, and then displaying it on a screen. Some are capable of showing signals in real-time, much like an oscilloscope. While this can be useful to look for trends while a system is running, it can be difficult to search through and look for details in the signals.

Logic analyzers, whether standalone or attached to a computer, usually include software or controls for navigating through large amounts of signal data. This can include zooming, panning, searching, etc.

![Panning and zooming digital data](/files/-LOTkeiCROPNqguRkVqr)

#### Quick Digital Measurements

Modern logic analyzers and logic analyzer software contain many advanced features that help users characterize signals. This includes measuring aspects of the signal, such as pulse width, frequency and period of periodic signals, as well as duty cycle.

![Measuring period, frequency, and duty cycle of a square wave](/files/-LNlcoSw4JvuRaovUaMb)

If you are analyzing transmission data between two systems, a logic analyzer can be an invaluable tool for timing analysis. For example, with I2C, the data line (SDA) needs to be held at its intended value for a particular amount of time (part dependent) before the rising edge of the clock line (SCL). This is known as *setup* time. For most implementations of I2C, SDA also needs to be held at its intended value until the subsequent falling edge of SCL. This is known as *hold* time.

A logic analyzer with a fast enough sample rate can help measure setup and hold times accurately. This can help ensure your digital messages are being read properly by the receiver.

#### Decode and Search Transmitted Data

Another unique feature of logic analyzers is the ability to decode signals. Most modern digital communication systems are implemented based on a set of protocols. Logic analyzers or their associated software can include these protocols, known as *protocol analyzers*, to help you make sense of the captured data.

With recorded data, many logic analyzers will allow you to search through the data looking for particular patterns. In I2C for instance, we can look for the device's bus address, as that will denote the beginning of a transmission. Some logic analyzers will let you set a search pattern as the trigger condition to begin recording.

### Form Factors

#### Portable Logic Analyzers

*Portable logic analyzers* have the more traditional "test equipment" form factor, often larger than most workbench oscilloscopes. They are considered "portable" as they include everything required to capture, view, and analyze digital signals such as probes, a screen, cursor controls, and sometimes a full keyboard.

![Example of a portable logic analyzer](/files/-LN6mberWZO4H_n0MBGS)

#### Modular Logic Analyzers

*Modular logic analyzers* are rack- or PC-mounted cards that slide into a mainframe or backplane. They are considered "modular" because the end user can purchase and swap out various acquisition and test modules on a single backplane depending on their needs.

#### PC-Based Logic Analyzers

*PC-based logic analyzers* rely on computers to perform the heavy lifting of displaying and analyzing the captured data. PC-based logic analyzers include a separate device that is plugged in to one of the computer's accessory ports. The device houses the necessary data acquisition circuitry for capturing multiple, high-speed digital signals. This information is sent to computer software over the connected port. Due to the speed requirements to transmit large amounts of captured data, most PC-based logic analyzers rely on high-speed, wired connections, such as USB or Ethernet.

![PC-based logic analyzer connected to a circuit](/files/-LN6v04WcOWRqNUQikVS)

### Why Would You Need a Logic Analyzer?

Oscilloscopes can measure digital signals in a similar fashion to logic analyzers but are limited by the number of channels available. An oscilloscope is the right tool for measuring how the voltage between two points in a circuit varies or fluctuates over time. However, logic analyzers can be extremely useful for testing, debugging, and characterizing digital circuits with several advantages over oscilloscopes:

* More channels than an oscilloscope
* Characterize the output of a digital circuit (e.g. FPGAs)
* Debug complex embedded firmware by toggling general purpose input/output (GPIO) pins
* Quickly measure and decode various digital protocols
* PC-based logic analyzers can be great for debugging in the field due to their small size and portability


# How to Use a Logic Analyzer

## How to Use a Logic Analyzer

A logic analyzer can help you visualize the transmission of data across data lines. It does this by converting the recorded voltages over time into a series of binary data (1s and 0s). At first glance, a logic analyzer might be intimidating to use, but this guide can help you. We will define a few key terms and give examples of decisions you must make at each step to help you analyze your system.

In the rest of this tutorial, we will look at the five main steps normally taken to capture and analyze data using a logic analyzer:

1. Connect probes to the system under test
2. Set your sampling mode
3. Configure the trigger conditions
4. Acquire signal data
5. Display and analyze waveforms

### Terminology

A few definitions might help you on your journey with logic analyzers:

**Channel:** A single signal line on the system under test. Logic analyzers are capable of monitoring anywhere from 4 to over 100 channels at the same time.

**Threshold:** A voltage level set by the logic analyzer or by the user. Voltages detected by the probe below the threshold are assigned a logic "0," and voltages above the threshold are assigned a logic "1."

**Sample:** A single data point that is captured by the logic analyzer at a particular moment in time. The logic analyzer simultaneously compares the voltages detected on all probes to the threshold, translates them to logic 1s and 0s, and stores that data in memory.

**Sample Rate:** How fast the logic analyzer records samples within a given time period. The maximum sample rate for a logic analyzer is often given in the units of megahertz (MHz) or mega-samples per second (Msps); in both cases, a single unit (1MHz or 1Msps) equates to recording one million consecutive samples per second.

**Memory Depth:** The amount of memory available to store the samples. The maximum memory depth for most logic analyzers is often presented as the number of samples which can be stored per channel.

**Trigger:** The condition(s) necessary that cause the logic analyzer to begin sampling and recording data. For example, a rising or falling voltage on a particular channel or a particular pattern of 1s and 0s across multiple channels can be used as triggers.

### Typical Controls

Logic analyzers often have a set of buttons and knobs that allow you to configure the capture parameters or navigate through the display as shown in the figure below. PC-based logic analyzers are normally controlled through virtual "knobs" located in the user interface of software on your computer.

![Typical Control Layout on an Iwatsu SL-4121 Logic Analyzer](/files/-LPWTUxRZiKY52E50vxL)

Most logic analyzers will have a way to set your sampling mode, sampling rate, and triggers through a set of onscreen menus. Triggers and patterns can be set or searched using a numerical keypad, often with hexadecimal (0-9, a-f) inputs, or with a full keyboard.

You can tell the logic analyzer to begin recording data with one of the "Execute" buttons. In the image above, the "Repeat" button will tell the analyzer to continue capturing whereas the "Single" button will only capture data until the memory is full. You can stop capturing with the "Stop" button.

Once data has been captured, you can navigate through it and search for patterns. Arrow keys or a cursor knob will let you scroll through the data or zoom in on certain parts.

### Probe Setup

Most logic analyzers come with a special wire harness that contains a number of probes, also known as "flying lead probes." To begin, connect the wire harness to the logic analyzer.

Next, ensure that the system or device you wish to test is powered off! We don't want to accidentally short something out in our circuit with a probe. Find the "ground" or "common" probe and attach it to the ground or common in your system. Ground will be used as a reference voltage when sampling signal lines.&#x20;

Note that for some logic analyzers, you will only need to attach one ground probe for the whole wire harness. With other analyzers, you will need to attach one ground probe for each signal probe. Please refer to your logic analyzer's user manual to understand its grounding requirements.

Finally, find the signal lines in your circuit that you wish to monitor. These could be GPIO lines or a communication bus, such as UART, SPI, or I2C. Attach one probe to each signal line. The logic analyzer will measure the difference between the reference voltage and signal voltage on each line.

![Example of where to attach logic analyzer probes to capture I2C data](/files/-LPWkFUbWRT3JquT01QF)

Most logic analyzers have clip-on probes that you can attach to headers, plated-through hole (PTH) parts, or even some larger surface-mount devices (SMD). If you are working with small SMD parts with no exposed leads, you can solder thin wire to an exposed printed circuit board (PCB) trace to give you access to the signal.

![Clip-on probe attached to an SMD part via soldered wire](/files/-LPh1zRjzB1WqO09KpqX)

![Clip-on probes attached directly to an SMD part](/files/-LPXgcaFVwwqshBRxG2E)

Some high-density or high-speed systems may require a specialized connector to reduce losses and radiated noise. Test PCBs can be made with these connectors, which mate to a wire harness connector from the logic analyzer. During development, this technique can save time from having to wire up dozens of probes to the circuit.&#x20;

### Sampling Modes

Most logic analyzers have two methods of capturing and displaying data: timing mode and state mode. Timing mode is useful to view data as a waveform that changes over time whereas state mode allows you to visualize data as a list synchronized to a clock. State mode can be helpful to view data in the same manner a receiver on a transmission bus might see it.

In timing mode, also known as "asynchronous mode," data is captured at precise intervals according to the logic analyzer's internal clock. The sample rate can often be set by the user. For example, if you set the sample rate to 1 khz, the logic analyzer will capture data 1000 times per second (in other words, sample the probed lines once every millisecond).

In the image below, we can see how a single logic analyzer channel will sample a sine wave at precise intervals. The voltage at each sample is compared to the threshold. A digital signal is reconstructed from the captured 1s and 0s to show a waveform to the user.

![Example of sampling a sine wave in timing mode](/files/-LPWwNPi2LC_XSRY1bUM)

State mode, also called "synchronous mode," requires one of the channels to be defined as a clock. Signals on the other data lines are sampled on the edge(s) of the clock signal. If a transmission bus relies on a clock line, this can be a useful way to visualize data in the same way your receiver sees it.

In the example below, we have two D flip-flops. Each has a "data in" line (labeled D0 or D1), a "data out" line (labeled Q0 or Q1), and a clock line (clk). On each rising edge of the clock signal, the logic level at the "data in" pin is latched and replicated on the "data out" pin.

If we attach 2 logic analyzer probes to the "data in" pins (D0-D1) and a third probe to the clk line, we can use state mode to see what the data should look like at the outputs (Q0-Q1). Note that state mode data is often presented in list format. If we are unable to probe the outputs (e.g. they are inside an IC), this method can help us see what could be happening inside the system.

![Example of sampling the inputs to D flip-flops in state mode](/files/-LPXB7z_A1hkLXVpAoJF)

### Configure Trigger

Before you begin sampling, you will need to configure your trigger conditions. There are a few options worth considering to help you capture the data you need.&#x20;

**No trigger:** With no trigger, the logic analyzer will begin sampling and recording data as soon as you press the "Start" or "Run" button.

**Edge Trigger:** You can set the logic analyzer to watch for a rising or falling edge on a single channel, which will begin the recording process.

**Pattern Trigger:** If you are capturing multiple channels, you can set the logic analyzer to start the capturing process when it sees a pattern of 1s and 0s across several channels. Pattern triggers can be useful if you are looking for start-of-frame transmissions on parallel buses.

**Complex Trigger:** Some advanced logic analyzers will let you set a series of if-then-else statements to create a trigger. These types of triggers can be helpful to look for transmissions to a particular address on a bus, for example.

Most logic analyzers will let you configure a trigger by selecting a channel with the onscreen menu and selecting from a number options, including rising edge, falling edge, pulse width, etc. A pattern trigger can be set by selecting multiple channels and setting channel state options, such as logic high or logic low.

### Acquire

For most logic analyzers, you push a button named "Start" or "Run." With no trigger set, the analyzer will begin sampling and storing data until memory is full.

On the other hand, if you configured a trigger, the analyzer will begin capturing data, but older samples will be thrown out to make room for new samples. When the trigger condition is met, the logic analyzer will continue capturing data until its memory is full. Some logic analyzers retain and display a portion of the data prior to the trigger point. Information shown before the trigger is known as "negative time."

![Example of a logic analyzer displaying data before the trigger point](/files/-LPXM89JIs0FDPDG4yk9)

Some analyzers have a "repeat" or "continuous" capture mode that will continually capture and display data in real-time without stopping. This mode can be helpful for looking for signals that you might not know exist yet.

### Display and Analyze

Most logic analyzers will display data as waveforms with time in the x-axis and logic state (1 or 0) in the y-axis. This type of display is useful for seeing correlation among multiple signals in the time domain.

![How a logic analyzer might display multiple signals](/files/-LPXQJ5ewGCEx2F_AC5j)

Some logic analyzers come with the ability to decode various communication protocols, such as UART, SPI, I2C, etc. Decoders might show the data as a waveform but will also present the data as decimal, hexadecimal, ASCII, and so on. Decoding protocols can be extremely helpful in troubleshooting problems on communication buses.

![Example of decoding the ASCII character 'a' on the Tx line of a UART transmission](/files/-LPXVF4KcWacWJHyy_G9)

Advanced logic analyzers can even be equipped with decoders capable of analyzing machine language and converting it to assembly code. This type of analysis requires software unique to each type of processor or instruction set.

To view the captured data in greater detail, most logic analyzers will let you scroll or zoom using buttons or knobs. Many analyzers will also let you search for patterns by entering numbers or ASCII characters. Setting decoders usually involves selecting from an available list in one of the analyzer's menus.

A logic analyzer is a powerful tool for analyzing digital systems, and understanding the different modes and triggers can help you capture data in the right way.&#x20;


# Logic Analyzer vs. Oscilloscope

## Logic Analyzer vs. Oscilloscope

In the real world, electrical signals are analog (including digital ones!). An [oscilloscope](/oscilloscopes/what-is-an-oscilloscope#what-is-an-oscilloscope) allows you to view analog voltages and how they change over time. Oscilloscopes are best used for evaluating signal integrity and measuring analog circuit performance.

On the other hand, [Logic analyzers](/logic-analyzers/what-is-a-logic-analyzer#what-is-a-logic-analyzer) represent signals in their digital form: a logic 0 or logic 1. This is similar to an oscilloscope with a 1-bit resolution. However, most logic analyzers have many more channels than oscilloscopes (8, 16, or even over 100 channels). Logic analyzers are great tools for viewing digital waveforms, debugging digital communication (e.g. Serial, I2C), and characterizing digital systems with many lines (e.g. FPGAs).

### Uses

Choosing the right tool for the job can be a crucial step when debugging circuits. At its core, an oscilloscope is useful for measuring and visualizing analog signals with 1-4 channels. A logic analyzer is best for digital systems with more than 4 channels.

An oscilloscope can help you visualize analog waveforms and measure various characteristics, such as amplitude, ringing, transient signals, phase, and unwanted pulses. Even when debugging digital systems, you can easily measure signal integrity with an oscilloscope.

![Example of an oscilloscope displaying a sine wave and overshoot on two channels](/files/-LQpK4CFMRgton-uqYWv)

However, if you need to monitor and debug the output of a digital system or capture digital communication, such as serial and I2C, a logic analyzer is often the better tool. Logic analyzers generally offer more channels than an oscilloscope and can display data in state mode, where one of the channels acts as a clock.

![Example of a logic analyzer displaying digital signals on six channels](/files/-LQpK6LVbkHVX32A9Dg8)

### Differences

The differences between oscilloscopes and logic analyzers can be summarized in the following table:

| Oscilloscope                                                            | Logic Analyzer                                                     |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------ |
| Measure and display analog signals on a few channels                    | Measure and display digital signals on many channels               |
| Repeatedly store and display small snapshots                            | Record data before displaying                                      |
| Displays signals in real time                                           | Allows users to navigate potentially long recordings               |
| Measure amplitude and timing of a waveform                              | Measure time between data capture points                           |
| Offers real-time features, like fast Fourier transform (FFT)            | Offers features unique to digital systems, like protocol analyzers |
| Simple threshold or pulse-width triggers used to show a steady waveform | Complex triggering system used to capture and filter data          |

### How Do Oscilloscopes Work?

The following diagram shows the basic functional blocks that can be found in a digital storage oscilloscope (DSO). Note that some blocks have been left out for the sake of simplicity.

![Block diagram of an oscilloscope](/files/-LQpli3BZL4xmzJJ9V7p)

**Probe:** The part that attaches to your circuit. Most probes have two tips, as an oscilloscope measures the voltage (electric potential difference) between two points.

**Amplifier/Attenuator:** Oscilloscopes often contain circuitry to amplify or attenuate electrical signals so they can be effectively displayed to the user. This circuitry can be in the probe or inside the oscilloscope chassis.

**Trigger Select:** Many oscilloscopes will let you chose between an internal signal or an external signal (on a separate probe) to trigger the sweep that displays the captured waveform.

**Control Logic:** Internal logic or software that allows you to configure how signals are captured and displayed.

**ADC:** Analog-to-Digital Converter. The ADC is in charge of sampling the electrical signal at regular intervals and converting the voltage to digital information that is stored in memory. ADCs for oscilloscopes often have 8, 12, or 16 bits of resolution.

**Memory:** Sampled data from the ADC is stored to memory. This information is used to reconstruct a close approximation of the electrical signal--a waveform--on the display.

**Time Base:** Used to control the horizontal (time) axis on the display. Triggering information can be used to adjust the time base so that a periodic signal, like a sine wave, appears stable in the display.

**Display:** On modern, digital oscilloscopes, the waveform is generated from information in the time base and data in memory. Most often, waveforms are shown with voltage as the Y-axis and time as the X-axis.

### How Do Logic Analyzers Work?

The following diagram shows the basic functional blocks found in most logic analyzers. Like in the oscilloscope example, the blocks have been simplified.

![Block diagram of a logic analyzer](/files/-LQpkf8Ayk07_gKViOb6)

**Probes:** If you are using a logic analyzer, you might need to fit many probes into a tight space. As a result, probes are often simple: a piece of wire with a clip and little or no circuitry. Some probes can have dozens of channels packed into a single, high-density connector that requires a specialized mounting point on your test system.

**Clock Select:** Some logic analyzers will allow you to choose which clock is used to sample the signals. An internal clock will sample at regular intervals (timing mode), or an input channel may be used as a clock source (state mode).

**Comparator:** Unlike an oscilloscope, the logic analyzer compares each input signal to a user-defined voltage threshold. If the voltage is higher than the threshold, it is stored as a logic high (1). Otherwise, it is stored as a logic low (0). Because logic analyzers do not require ADCs, they often have many more channels than oscilloscopes.

**Trigger Logic:** Logic analyzers frequently have more triggering features than oscilloscopes. Any or all of the probed channels can be used to trigger the start of a capture, and some advanced logic analyzers will let you construct a series of if-then-else statements to create complex triggers.

**Trigger Select:** Some logic analyzers will allow you to select between triggering from the captured channels or a separate "trigger" input. This specialized input can be used for synchronizing to other test equipment, such as an oscilloscope.

**Memory:** Much like many modern oscilloscopes, logic analyzers store the captured series of logic 1s and 0s in memory. Memory can be inside the logic analyzer's chassis or on a computer (as is the case for USB logic analyzers).

**Display:** Waveforms depicting the captured digital signals are drawn on a display for the user. Similar to oscilloscopes, the Y-axis for each waveform is voltage. However, the voltage is a 1-bit value: logic high just shows the voltage was over a threshold and logic low shows the voltage was under it. The X-axis is time.

### Mixed Signal Oscilloscope

Sometimes, you might find yourself in need of both a logic analyzer and an oscilloscope. Many electrical engineers will have both machines on their workbench. However, the combination of logic analyzer and oscilloscope can be found in a piece of equipment called the *Mixed Signal Oscilloscope* (MSO).

![Example of a Mixed Signal Oscilloscope](/files/-LQp3wceVjqQ2m0Cj2gy)

&#x20;*Image credits: "* 350 MHz Mixed Signal Oscilloscope HMO3524 by HAMEG Instrument&#x73;*" by Hameg* *is licensed under* [*CC BY SA 3.0*](https://creativecommons.org/licenses/by-sa/3.0/deed.en)*​*

MSOs can capture and display analog as well as digital signals. They often have several oscilloscope channels along with dozens of digital inputs. Additionally, they can be configured with complex triggers based on both analog and digital characteristics.


# SPI vs I2C Protocol Differences and Things to Consider

## SPI vs I2C Protocol Differences and Things to Consider

When it comes to communicating between chips on a printed circuit board, two protocols are extremely popular: Serial Peripheral Interface (SPI) and Inter-Integrated Circuit (IIC or I2C). These wired protocols are considered "little" or "low-end," as they do not have the speed, robustness, and distances boasted by other protocols, such as USB, Ethernet, SATA, etc.

However, SPI and I2C are extremely popular, as they are easy to implement, requiring few components and little code, over their heavyweight cousins. Both rely on serial communication to pass data and support multiple devices on one bus. Many microcontrollers, sensors, and peripherals (such as LCDs) rely on SPI and I2C to talk to each other.

If you are designing a product and need to choose between SPI and I2C, which one do you pick?

### SPI

SPI was developed in the 1980s by Motorola as a way to communicate between their early microcontrollers and onboard peripherals, such as EEPROM. Motorola, nor any other organization, maintains any sort of standardization of the SPI protocol. As a result of this "de facto" standard, implementations can vary from manufacturer to manufacturer. Make sure you read the datasheet for each SPI-enabled part very carefully!

SPI uses four active signal lines (which do not include power and ground lines) to communicate between parts. These lines include:

* SCLK: Serial Clock (controlled by master)
* MOSI: Master Out Slave In (controlled by master)
* MISO: Master In Slave Out (controlled by slave device)
* SS: Slave Select (controlled by master)

With these four lines, a controlling device (master) can communicate with another peripheral device (slave).

![SPI point-to-point connections](/files/-LS_vh8TNcTDJytT9iUO)

While you may have only one master on the SPI bus, you can add any number of peripherals. However, for each peripheral you add, you must add an additional SS line. In the example diagram, we must use three separate SS lines, each controlling a separate peripheral.

![SPI connections for 3 slave devices](/files/-LS_vnZfgdn58_uMjvXp)

When the master device wishes to send data to or receive date from a peripheral, it starts communication by pulling the corresponding SS line low. At the same time, it activates the clock line (toggling SCLK high and low at a given frequency). The master device sends out data on the MOSI line while simultaneously sampling the MISO line. As a result, data can be sent between a master and peripheral device at the same time (full-duplex).

Note that only one peripheral device may be communicating at a time with the master.

![Example timing diagram for mode 0 SPI: MOSI and MISO lines are sampled on rising SCLK edge](/files/-LS_vuDlS9yPvYZMDwtt)

SPI has four different modes that can be set, which determine how the clock operates. The master and peripheral devices must use the same mode. Mode 0 is by far the most common mode found among devices.

* Mode 0: data sampled on rising clock edge, clock idles low
* Mode 1: data sampled on falling clock edge, clock idles low
* Mode 2: data sampled on falling clock edge, clock idles high
* Mode 3: data sampled on rising clock edge, clock idles high

SPI does not specify any particular voltage levels, maximum speed rates, or addressing schemes. As a result, it is up to you to decide these factors. SPI speeds can easily exceed 10 Mbps, so make sure you read the datasheets for all your parts, as that will determine the acceptable voltages, speed limits, and supported modes.

Because of these speeds, SPI is useful for transferring large amounts of data. SPI is often found on sensors that require fast update rates, like accelerometers, display devices, LCDs, and flash memory devices.

### I2C

Philips Semiconductors (now known as NXP Semiconductors) created the I2C specification in 1982 to help standardize communication between chips on the same board. NXP does not charge anyone to use or implement I2C, but they do charge a fee if you would like to register a device address.

I2C uses 2 lines (not including power and ground) for communication:

* SDA: Serial Data
* SCL: Serial Clock

Any number of master devices and any number of slave devices can theoretically be attached to the same bus. Both SDA and SCL lines are required to be open-drain lines. As a result, devices can only pull each line low. A pull-up resistor is required on each line to pull the line back up to high.

![I2C connections for multiple master and multiple slave devices](/files/-LS_wHgqbb3qugMtRK30)

Because of the open-drain design, I2C supports multiple masters on the same bus. If two devices start transmitting at the same time, one of them will eventually back off in a process known as "arbitration." Devices monitor the SDA line while they communicate. If a device sees that the SDA line is low when it is trying to transmit a logic high, it knows that another device is trying to communicate, and it will stop transmitting.

To begin communication, a master device will issue a START condition, where the SDA line is pulled low while the SCL line is still high. The master then sends out the 7-bit address of the intended recipient on the bus, followed by a write bit (0) or read bit (1). If a device on the bus has that particular address, it will respond by pulling the SDA line low (ACK bit).

Data can then be sent by the master or peripheral device in packets of 1 byte at a time; each byte should be acknowledged by the recipient with an ACK bit. Once communication is complete, the master will issue a STOP condition by releasing the SDA line (which will be pulled high) while SCL is high.

![](/files/-LSaIuV5ZNGSWJoaAz9b)

Data rate was originally limited to 100 kbps (standard mode). In 1992, Philips raised the speed cap to 400 kbps (fast mode). A special 3.4 Mbps mode (high-speed mode) was added 6 years later. A special set of commands must be given at lower speeds between master and peripheral to set up a high-speed connection.

While any number of devices can be physically attached to an I2C bus, the 7-bit address limits the actual number of devices. Some of the addresses are reserved, and therefore, only 112 different devices can be present on the same bus. A special 10-bit addressing mode can be enabled to allow for more devices, if necessary.

I2C has a form of flow control known as "clock stretching." A peripheral device can hold the SCL line low, which tells the master device to slow the transmission rate. This technique allows the peripheral some time to process data before responding.

Due to the low pin count required by I2C, many sensor manufacturers use this protocol in their chips. For example, temperature sensors, accelerometers, analog-to-digital converters, etc. can be found with I2C.

### Comparison

|                    | SPI                                                             | I2C                                                               |
| ------------------ | --------------------------------------------------------------- | ----------------------------------------------------------------- |
| Pin drive          | Push-pull                                                       | Open drain                                                        |
| Signal lines       | 4 (plus 1 for each additional peripheral)                       | 2                                                                 |
| Max speed          | No limit (10-100 Mbps is common)                                | 400 kbps in fast mode (3.4 Mbps is possible with high-speed mode) |
| No. of peripherals | Only limited by number of pins available for SS lines on master | 112 with 7-bit addressing                                         |
| Multi-master       | No                                                              | Yes                                                               |
| Flow control       | No                                                              | Yes                                                               |

### Conclusion

Both protocols are suitable for many different applications. Most often, you are limited to whichever protocol is implemented by the manufacturer of a particular part. Some, like the Analog Devices ADXL345 accelerometer offer both I2C and SPI interfaces on the same chip.

If you have to choose between the two, SPI is generally the better tool if you need faster transfer speeds. I2C, on the other hand, is best if you have limited pins available on your microcontroller or microprocessor.


# Choosing a Logic Analyzer

If you are in the market for a logic analyzer, how do you know which one is right for you? There are many options to choose from, and looking at the various technical specifications can be intimidating. This article will give you some potential features to think about when considering your purchase.

## Form Factor

The first important decision to make is what kind of logic analyzer do you want? They come in three different forms: portable, modular, and PC-based. Each form factor has its own set of advantages and disadvantages worth considering.

### Portable

Portable logic analyzers are generally large boxes intended to sit on a workbench. Similar to an oscilloscope, they usually have a screen and a number of knobs and buttons to navigate the various menus. Many modern portable analyzers are simply cases wrapped around a computer that runs an operating system, such as Windows.

![](/files/-LTxUx-Z5V5l3BpR6T7d)

While some can have relatively large viewing areas, they often pale in comparison to the size and real estate you might get from a traditional desktop computer monitor. Staring at a small screen for long periods of time can be painful.

The name "portable" comes from the fact that the logic analyzer components are completely self-contained. Many have large handles that allow you to move the units, should the need arise. However, some are quite large and can weigh over 30 pounds, which can make it difficult to physically move such equipment.

Despite their bulkiness, portable logic analyzers can contain specialized hardware that allow you to measure signals at higher frequencies. As they do not require a separate computer, you are not limited by external connection speeds, such as USB and Ethernet.

### Modular

Modular logic analyzers can be rack-mounted or cards that slide into a backplane. You can swap out various modular units to create a unique set of test equipment for your specific needs.

![](/files/-LTxY2CUPSTPPYwZ0nHE)

Most often, modular analyzers require computer software to control collection and analyze data. Having a separate computer gives you a potentially larger screen and an easier path to upgrade the software. However, you are limited by the connection speeds (for example, USB or Ethernet) between the test equipment and computer.

While the individual modules might be small (able to fit in the palm of your hand), they cannot work without the proper backplane. These backplanes can be anywhere from the size of a shoe box to a small room.

### PC-Based

PC-based logic analyzers are similar to modular analyzers in that they require host computers to control the capture parameters and display waveforms. However, they do not require a backplane to operate.

![](/files/-LTyOur-FrDpGlkXxDmf)

Because of the reliance on a host computer for command and control, PC-based analyzers are limited by their connection speed. Be aware of the type of connection available. For example, USB 3.0 offers higher data rates than USB 2.0.

Thanks to needing a separate computer to operate, the software is easy to upgrade, and you have the option of using one or more larger screens to help you debug. Additionally, when paired with a laptop, small PC-based analyzers can be extremely portable, which can be advantageous if you are debugging a circuit in a car or at a conference.

## Technical Specifications

As you shop for logic analyzers, you will come across a plethora of technical specifications. It can be helpful to think about what kinds of circuits you wish to debug before looking at the various specs. For example, are you working with low speed protocols, such as UART and I2C? Do you require dozens of channels to characterize a complicated FPGA circuit? Or are you trying to debug high speed signals like Ethernet and HDMI?

In this section, we'll go over some of the important specifications that you might find. Note that portable-type logic analyzers will generally have the best specifications at the cost of portability and ease-of-use.

### Channel Count

The most obvious specification is the number of channels available on the logic analyzer. A channel is an input line with the ability to sample and measure a signal. It is not uncommon to find logic analyzers with 8, 16, 32, and more channels.

![Example of logic analyzer output with 14 channels](/files/-LU2fGETbSa_cfamZZ2m)

If you plan to examine protocols with few signal lines, such as I2C, SPI, Ethernet, USB, CAN, and HDMI, you will not need more than 8 or 16 channels. On the other hand, if you are planning to debug parallel communication buses, such as PCI, ATA, and SCSI, you will want at least 32 channels.

Performing a [state mode analysis](/logic-analyzers/how-to-use-a-logic-analyzer#sampling-modes) of digital components, like FPGAs, microcontrollers, and memory, may require many more channels. Some logic analyzers can contain more than 100 channels to assist with these complex circuits.

### Sample Rate

The sample rate determines the shortest interval in which your analyzer can take a measurement from each of the signals. For example, a sample rate of 100 MS/s (mega-samples per second) means that your analyzer can sample a signal 100,000,000 times per second.

The Nyquist-Shannon sampling theorem states that you must sample more than twice the frequency of your original signal to be able to reconstruct that signal. That being said, a good rule of thumb is that you need to sample a **digital signal at least 4 times faster** than its frequency, and you want to sample an **analog signal at least 10 times faster** than its frequency.

As an example, if you are planning to debug a SPI bus, which can reach up to speeds of 25 MHz, you would want an analyzer with a sampling rate of at least 100 MS/s.

### Bandwidth

Bandwidth describes the maximum frequency that the front end of the analyzer can handle. Unlike sample rate, the bandwidth is determined by the analog components used in the probes and buffers.

This video does a great job of describing the differences between bandwidth and sample rate. Even though it shows an oscilloscope, the same principles apply to logic analyzers.

{% embed url="<https://www.youtube.com/watch?v=VBJWkceO1OA>" %}

Note that bandwidth is given by the -3 dB point of signal attenuation. That means if you try to measure a signal with a frequency at your analyzer's bandwidth, the voltage of the signal will appear 0.707 times its actual level. You can measure signals with a higher frequency, but they will appear even more attenuated. With a logic analyzer, this might mean missing logic highs because the attenuation brings them below the threshold!

### Voltage

There are a few things to consider with voltage. First, what is the maximum safe input voltage range on each of your channels? Some analyzers can only handle 0 to 5 V. Others have protection circuitry that allow for higher voltages. As an example, say you have a logic analyzer that can safely handle +/- 25 V inputs. As a result, you can use the logic analyzer to debug RS-232 without any additional circuitry.

Second, you must think about the kinds of logic levels you will be working with. If your logic analyzer is only capable of sampling 5 V TTL levels, it might have 2 V as the logic high threshold. If you were to connect this analyzer to a 1.8 V logic circuit, it would not be able to detect any logic highs! As a result, you will want to pay attention to the voltage threshold(s) listed on your analyzer.

![](/files/-LU359AIrj8--xGGqEjn)

### Input Impedance

Most logic analyzers will have a pull-down resistor on each channel that connects the input signal to ground. This provides a level of safety for the analyzer so that the probe is not floating when disconnected from the circuit.

This resistor will often be in the 100 kΩ to 100 MΩ range. Make sure that your circuit is capable of driving enough current through the pull-down resistor! Many advanced chips, like microprocessors and FPGAs, are not capable of driving more than a few mA or μA. A pull-down, such as 100 kΩ, might cause the voltage to drop and provide inaccurate readings on some parts.

Probes also have some level of capacitance, whether through passive circuitry or through the nature of the connector and wire. At higher frequencies, the capacitor offers less impedance, which could be a problem for many digital circuits. For example, at 100 MHz a 10 pF capacitor has around 150 Ω of impedance. We recommend finding probes that have as little capacitance as possible.

## Other Features to Consider

While we gave you an overview of the important specifications to consider when shopping for a logic analyzer, you might want to consider a few other features as well:

* **Triggering:** Are you able to set up complex or nested triggers in your logic analyzer's software?
* **Protocol analyzers:** If you are working with communication buses, your logic analyzer should be able to decode such protocols (e.g. SPI, I2C, USB, Ethernet).
* **Analog input:** Some logic analyzers can measure and display analog signals similar to an oscilloscope. This can be a useful feature to help with setting up advanced triggers.
* **Over-voltage protection:** Some logic analyzers have buffers on each of their inputs. This can help prevent damage to the analyzer if you accidentally touch a probe to a higher voltage.
* **Differential signals:** Several protocols, like USB, use differential signaling. Analyzers with the ability to measure and decode differential signals can help you debug them.
* **Output capability:** A handful of protocol analyzers are capable of turning their input channels into outputs. This can save you from having to buy a separate frequency generator tool to test your digital circuits.
* **Ease-of-use:** If you do not plan to use your logic analyzer on a regular basis, having a tool that is easy to use can save you time (as you do not need to re-learn the basics each time you use it!).
* **Support:** Do you need help with your equipment when there is a problem? Companies offer varying levels of support, from in-person to phone chat to nothing at all.

## Conclusion

Shopping for a logic analyzer can be daunting, but hopefully this guide can help you navigate some of the technical jargon. As with most things, cost increases as you add features or increase specs. The important thing is to consider all of your likely use cases and carefully read the technical information before making your decision.


# Logic Analyzer Tutorial: Probe Setup

Capturing a clean signal with your logic analyzer is crucial to debugging your digital circuit. If you miss logic levels due to a poor probe setup, you might spend hours trying to find a bug that doesn't exist--the problem was in your test equipment all along! Or you might introduce a large enough load to your circuit that your system stops working altogether.

Selecting the proper probe and connecting it to your circuit correctly becomes increasingly important at higher frequencies. When you start working with signals over about 100 MHz, you need to consider grounding, probe impedance, and probe location.

In this tutorial, we will look at different probe options, various ways to connect them to your circuit, and some tips to consider when probing high speed circuits.

### Types of Probes

Most logic analyzer probes can be organized into two categories: built-in and after the fact.

#### Built-in Probes

If you are designing a printed circuit board (PCB) for the purposes of prototyping, you may consider adding a special footprint for hooking up a logic analyzer connector.&#x20;

By adding a spot for a logic analyzer connector, you can save yourself lots of time by not having to connect dozens of flying lead probes to individual pins on your board. On the down side, you will likely need to remove the connector footprint from the final design of your product.

One built-in option is to use a specialized connector that mates to a connector on the analyzer. This requires soldering a component to your board for the express purpose of debugging.

![](/files/-LU7UBntC5JfjBm7khxg)

Another option is to create a series of test points with mounting holes in a particular pattern. A compression-type connector will clip to the holes and have leads that touch the test points. This method does not require a separate component soldered to the board, but it still requires board space for the footprint.

#### After the Fact Probing

If you are debugging a PCB that does not have a built-in logic analyzer connector, you can use "flying lead" probes. These probes are simply wires that you connect to the circuit in any configuration. Often, you will find flying lead probes with attachment heads that have a hook or grabber. These grabbers allow you to connect to a variety of wires, pins, and test points.

![](/files/-LU7vDWAs8EWsQAdyhMF)

### Probing Methods

If you did not build a specialized logic analyzer connector into your PCB, finding a good spot to connect a probe might be tricky. Here are a few ideas to help you:

#### Directly to Header

Some flying lead probes are terminated with a 0.100-inch female or male header pin. In these cases, you can simply connect directly to the opposing header on your board.

![](/files/-LU7VjuxTXg4O_NHj8Sv)

#### Clip to Exposed Wire, Pin, or Header

Many flying lead probes have heads with hooks or grabbers that let you connect to any exposed conductor. For example, you can them to male headers on a board or to wire ends.

![](/files/-LU7SHYfMhZ8qjaxGuBn)

Some electrical components have leads large enough to grab with these probes. Many plated through-hole (PTH) parts and some surface mount devices (SMD) have leads with enough spacing to attach to. Examples include dual in-line packages (DIP) and small outline integrated circuit (SOIC) packages.

![](/files/-LU7UGzWAhvWpy5a1Ack)

#### Clip to Test Point

Some boards have built-in test points for attaching oscilloscope or logic analyzer probes. Test point components do not need to be populated until you need them, and they make connecting to a node much easier.

![](/files/-LU7VQbORyFrv9JRuTMs)

#### Solder Wire to Test Point, Pin, or Trace

Sometimes, you do not have an exposed wire or lead that you can connect to. In these cases, you will need to add a wire so that you can connect an analyzer probe. Unlike the test point components shown above, some boards have exposed pads for touching with test bed leads. You can solder a wire directly to these test points if you need to probe them.

Some fine-pitch SMD components are too small to grab with probes, but you can still solder 30 AWG wires to the leads.

![](/files/-LU7YtlaW90bQ_Wzl2Bp)

If no test points or exposed leads are available, you can manually scrape away solder mask to expose a trace and solder a thin wire to it.

![](/files/-LU7ZTw5UYuqp89yabHp)

### Troubleshooting

If you are experiencing problems capturing a good signal, we recommend using this section as a checklist to ensure you are employing good probing techniques.

#### Decrease Probe Loading

Whenever you attach a probe to a circuit, you are adding a load to that node (even if it is a very small load). Probe resistance, capacitance, and inductance make up the impedance of the probe, and at high frequencies, this impedance can cause problems. Some systems may not work under such loading, or you might get inaccurate readings.

Large surface areas on connectors can form capacitors, and long wires can add inductance. As a rule, you should use the shortest wires possible for your probes and use the smallest surface area possible to make contact with your circuit.

If are still having problems with loading, you might need to look into purchasing better probes that offer more impedance.

#### Probe the Correct Location

If you are probing cables or long stretches of traces, you might be working with transmission lines. Transmission lines do not behave like ideal wires in that they suffer from reflections, cross-talk, and interference.

As a result, if you probe in the middle of transmission wire with improper termination, you might pick up some of these reflections. On an oscilloscope, these reflections look like stair-steps. Your logic analyzer would have a hard time interpreting a voltage near its threshold, so you may get a false reading.

![Example of a transmission line reflection seen on an oscilloscope](/files/-LUBhEzS1Q6Ten0QCZ2s)

Try probing closer to your receiver to understand what the signal looks like from the receiver's perspective.

#### Watch for Ground Loops

Ground loops occur when you have two points of a circuit that are supposed to be at the same reference potential but have a voltage difference between them. This can happen if you have multiple return paths in your circuit back to a common point.

![Example of a ground loop](/files/-LUBlkRJioLYmQ5zHIuL)

These loops act like inductors, and at high frequencies, they start to impede the changing of current. As a result, you will see a decrease in your system bandwidth.

#### Use Multiple Ground Leads

At low frequencies and low channel counts (e.g. 8 or 16 channels), you can use one ground probe when connecting to your system. However, as frequencies and channel count increase, more current is returned through that one ground probe, and the self-inductance of the wire starts to impede the faster switching.

As a result, a voltage will develop across the ground wire, which can degrade your measurement quality. Therefore, we recommend using a ground wire for each signal wire when working with higher frequencies.

#### Avoid T-Junctions in Transmission Lines

On transmission lines, especially at high frequencies, attaching a branching wire that is not properly terminated can introduce reflections in the line and degrade signal integrity.&#x20;

![Example of T-junctions off a communication bus](/files/-LUBp59MVyTYZ3aCBwfi)

To combat reflections, avoid branching PCB traces that go to separate logic analyzer test points. Instead, consider placing the test points as close to the transmission lines as possible. If your logic analyzer uses flying lead probes, you may want to invest in specially terminated probes that attenuate signals or reduce loading.

### Conclusion

Using proper probing techniques can save you hours of headaches trying to track down false negatives. If you are using flying lead probes or tacking wires to leads, consider keeping wires as short as possible. Not only does this help with signal integrity, it can assist in keeping your work area neat when trying to figure out which wire goes where.


# What is an Oscilloscope?

## What is an Oscilloscope?

### Oscilloscope Fundamentals

Building or troubleshooting a circuit would be so much easier if you could actually see electrons flowing through the wires. Since that isn't possible, you need tools to show you what's happening.

The most basic tool is a meter, but that cannot display rapid fluctuations in voltage. At best, it can only give you an approximate average value.

If you want to see and measure a spike in voltage, or the shape of an audio waveform, or the tiny burst of electrical noise caused by the opening and closing of contacts in a switch, you need an oscilloscope. This is often referred to simply as a "scope".

An oscilloscope is equipped with a probe that you touch to a location of interest in a functioning circuit. The voltage detected by the probe is then shown graphically on a screen, in an image known as a trace. An example is shown in Figure 1, where the trace is of a sine wave derived from an audio signal. The grid superimposed on the trace helps you to make approximate measurements.

![Figure 1: Sine wave as measured by an oscilloscope](/files/-LNlsbSNx-pkbgDASFgk)

Suppose you have a chip such as a 555 timer, which creates square-wave oscillations. Ideally the output should be a nice, clean trace such as the one in Figure 2, but in the real world the output may be more like Figure 3. The transient voltage spikes can cause problems elsewhere in a circuit, especially if they enter the power bus. If you add a capacitor between the positive supply pin of the chip and negative ground, this may help to suppress transients. But which value of capacitor will do the job most effectively? An oscilloscope can answer that question.

![Figure 2: Ideal square-wave output](/files/-LNluqpPMLYkvL0CDr1t)

![Figure 3: Square-wave in the real world](/files/-LNlurM_fC5LUNximVg6)

### History

Old-school oscilloscopes displayed their output on a monochrome cathode-ray tube (CRT) in which an electron beam drew glowing images on the phosphor coating inside the screen. This was like a 1950s television set, except that the oscilloscope trace was usually green. An old scope such as the one shown in Figure 4 was large, heavy, and expensive. This type of unit is now referred to as an analog scope.

![Figure 4: An analog scope](/files/-LNlu1PFMUAJ-j149xBS)

When digital oscilloscopes were introduced, they became known as storage oscilloscopes because their internal memory could store the signal being displayed. This was facilitated using an internal analog-digital converter (ADC) which sampled the analog input voltage and converted it to a stream of digital values. Storage oscilloscopes are equipped with LCD screens instead of CRTs.

A handheld storage oscilloscope is shown in Figure 5. Some units have touch-screen controls instead of physical knobs and buttons.

![Figure 5: Handheld storage oscilloscope](/files/-LNlu9I3aT2Ay5jbBuAW)

*Image credits: Figure 5, Copyright-free,* [*Adafruit Industries*](https://www.adafruit.com)

A third generation of scopes was developed for use with desktop or laptop computers. Known as USB oscilloscopes, they consist of just a small box that digitizes signals from a circuit and outputs the data through a USB port to the computer. After software conversion, the trace is displayed on the computer screen.

A USB oscilloscope can be extremely affordable. It also enables very easy screen capture, as a trace may be copy-pasted straight into a document.

### Features

Any oscilloscope will have basic controls to adjust time/div (the time per horizontal division on the screen) and volts/div (the voltage per vertical division on the screen). Volts/div is a function of gain--the amplification of the input voltage. Additional controls allow you to adjust the horizontal and vertical position of the trace, to center it on the display.

Many oscilloscopes enable a split screen to display and compare two signals. Also, any oscilloscope that uses a backlit color LCD display, or can send its signal to your computer, will add color to make the data easier to read.

The specification for an oscilloscope should include terms such as the bandwidth (the range of frequencies that the oscilloscope can display), the rise time (the duration of the most rapid signal rise that can be resolved), and in a digital oscilloscope, the sampling rate (which should be about 10 times the maximum frequency to be measured).

### Do You Need an Oscilloscope?

If you only deal with steady DC voltages, and you never use components that are noise-sensitive or do rapid switching, you may not need to see small fluctuations in voltage. However, an oscilloscope can be indispensable if you want to build, repair, or investigate circuits such as:

* Any kind of amplifier, especially an audio amplifier, where the shape of the output waveform should match the shape of the input, and you may want to see the effect of tone controls or filters.
* Circuits that contain logic chips which switch rapidly and are susceptible to voltage spikes--or may create spikes of their own.
* An AC-DC converter where the DC output should be as smooth as possible.
* A DC-AC inverter where the AC output should be as close to a sinewave as possible.
* Switches or relays which you need to debounce, to clean the signal.
* Any type of analog sensor creating an output that you need to inspect.
* You may also use an oscilloscope to view rapid events in the real world such as sounds or mechanical vibrations, which you can convert into electronic signals for the scope to display.
* Since oscilloscopes have become so affordable, they can be standard equipment not only for engineers but for hobbyists who want to see exactly what's going on inside electronic circuits.


# How to Use an Oscilloscope

## How to Use an Oscilloscope

This tutorial explains how to set up an oscilloscope and then display a varying voltage as a trace that you scale to fit the screen.&#x20;

For details on what an oscilloscope is and the problems that it solves, please take a look at our previous article below.

{% content-ref url="/pages/-LNlnwgIjFV3i781jBZu" %}
[What is an Oscilloscope?](/oscilloscopes/what-is-an-oscilloscope)
{% endcontent-ref %}

### Oscilloscope Probes

Your oscilloscope detects voltage with a probe. When you retract the spring-loaded plastic collar at the end of the probe, as in Figure 1, it reveals a tiny metal hook that can grab the lead of a component on a circuit board. The probe also has a black wire terminating in an alligator clip that you attach to negative ground on the board. See Figure 2.

![Figure 1: Spring loaded metal hook at the end of a scope probe](/files/-LPmU7-oZxMkJpYHyI7G)

![Figure 2: Ground alligator clip for scope probe](/files/-LPmUOfiHhxlVzmONSCr)

The other end of the cable from the probe terminates in a BNC plug, shown in Figure 3. Insert it into the "A" socket on your oscilloscope, as in Figure 4, and rotate the metal ring on the plug to lock it into position. A and B sockets may alternatively be identified as CH1 and CH2, meaning channels 1 and 2.

![Figure 3: The probe terminates to a BNC plug](/files/-LPmUmXD_X3gaPKj_Vdd)

![Figure 4: One of the channel inputs to the scope](/files/-LPmV4PuUDSbcq9CSlm9)

Note that while some oscilloscopes can be used with input voltages as high as 300V, others impose a much lower limit. Check your documentation for details.

If you buy a new USB oscilloscope, you will have to install a driver on your computer and connect the oscilloscope to the computer with a USB cable. The oscilloscope may power itself through the cable, or may use an AC adapter.

When you use it in AUTO mode, your oscilloscope will try to create a display from the voltage detected by the probe. If you simply touch your finger to the tip of the probe, you should see a trace. This will reassure you that the oscilloscope is working, but you will have to adjust the display to obtain a stable view, as described below.

### Basic Adjustments

Different types of oscilloscopes have different user interfaces. A handheld model will allow adjustments with buttons, while a benchtop version usually has some physical knobs. A USB oscilloscope may show you little pictures of knobs that you can "turn" with a mouse pointer, or it may use drop-down menus. In all of these variants, the basic concepts remain the same.&#x20;

Once the trace has been adjusted to your liking, you can save the data that created the trace, reload it later, and adjust some of the attributes. Your oscilloscope may also be able to save a screen shot in a format such as bitmap or jpeg.

#### Gain Knob

Voltage is displayed on the vertical scale at the left side of the screen, also known as the "Y axis." A knob or menu will let you choose the number of volts or millivolts for each division on the scale. This value is often abbreviated as VOLTS/DIV or may be referred to as "gain."

#### Timebase Knob

Time is displayed on the horizontal line at the bottom of the screen, also known as the "X axis." A knob or menu will let you choose the number of seconds, milliseconds, microseconds, or nanoseconds for each division on the scale. This value is often abbreviated as TIME/DIV or may be referred to as the "timebase."

#### Trigger Level

While the oscilloscope will trigger itself in AUTO mode, you can choose to set a "trigger level" specifying when to start capturing and displaying data. Your oscilloscope may allow you to set the level as a percentage of the total voltage range, or as a specific voltage. You can choose to begin capturing either when the voltage sensed by the probe rises above the trigger level or falls below it.

#### Offset Position

After you obtain a useful trace, you can adjust its location, sometimes referred to as the "offset." Moving it may be done with arrow buttons or with knobs labelled Y-POS (vertical position) and X-POS (horizontal position). On a USB oscilloscope, you may be able to drag the trace using a mouse.

### Examples

#### One-Shot Triggering

To explore your options, you can use a simple test circuit in which a double-throw switch charges a capacitor from a battery and then discharges the capacitor through a resistor, as shown in Figure 5.

![Figure 5: A double-throw switch charges a capacitor](/files/-LPmW_2RaijN5MdnCdXl)

If you want to see the voltage on the capacitor when it discharges, you can try to capture it manually using RUN and STOP buttons on your oscilloscope, but you may not be able to do this quickly enough. A better option is to start capturing the data automatically by setting a trigger level.

Because the discharge of the capacitor in the circuit is a single event, you should select "one-shot" triggering in your oscilloscope. Then establish a level that is slightly below the voltage on the capacitor when it is fully charged, and set triggering to occur when the voltage falls below that level.

Ideally, you might prefer to start capturing the event a moment before the voltage drop occurs. This can be arranged quite easily, because a digital oscilloscope stores data in memory all the time. When the voltage drop begins, the scope has already stored the data that preceded it, and can generate a trace from that point onward. This is shown in Figure 6.

![Figure 6: Capturing the discharge of a capacitor ](/files/-LPmXCNp1Btbn1qXA1sP)

To make the trace fit neatly on the screen, you will have to set VOLTS/DIV to match the voltage range on the capacitor, then experiment with values for TIME/DIV. Each horizontal division in Figure 6 is 1 millisecond, but your ideal TIME/DIV will depend on the size of the capacitor, the value of the resistor, and the voltage of the power supply in your test circuit.

Note that all the screen shots in this tutorial have been cropped and relabelled for clarity, but each trace was saved without any editing. The small bumps in the trace in Figure 6 probably resulted from electrical noise.

#### Continuous Triggering

Now suppose you want to capture a signal that repeats continuously, such as the output from a timer chip that has been wired asynchronously. When the oscilloscope is operating in "normal" mode, the trace on the screen updates itself frequently while you adjust VOLTS/DIV and TIME/DIV. You can immediately see the result of modifying a circuit, and you can also detect very brief events.

Figure 7 shows the continuous square-wave output from a 7555 timer chip. In Figure 8, you see how the signal changes if a capacitor is placed between the output pin of the chip and ground. The output voltage now rises slowly as the chip charges the capacitor, then drops more sharply as the capacitor discharges into the chip. To avoid overheating the chip with too much current, this test should not continue over a long period.

![Figure 7: Continuous square-wave output from a 7555 timer](/files/-LPmhkQJQOhTSSMecMBt)

![Figure 8: Capacitor placed at the output of a 7555 timer](/files/-LPmhrYLaU17IRWMPXZr)

Disconnect the capacitor, remove the 7555, substitute a 555 timer wired asynchronously, and the result is shown in Figure 9. It looks almost identical to Figure 7 except that there is a short voltage spike at the beginning of each high segment of the trace. The 555 is a very old TTL design which is known to create a noisy output.

![Figure 9: The older 555 timer's output with a short voltage spike ](/files/-LPmhyII9tiWXSjba_dK)

Your oscilloscope can magnify an image to show you what's happening, but if you try to view the voltage spike this way, you probably won't see enough detail. You need to sample the voltage more frequently, which will happen automatically if you decrease the value of TIME/DIV to focus on a briefer window in time. In Figure 10, the X axis is now calibrated in microseconds instead of seconds.

![Figure 10: The 555 timer's voltage spike zoomed in](/files/-LPmi2sQEBOOd4pkzqQ_)

Figure 11 uses identical settings to reveal the output of a 7555 timer. You can see that the more modern CMOS design of the 7555 completely eliminates the transient spike of the 555, although the rise time of the output is a little slower.

![Figure 11: A cleaner output rising edge from the 7555 timer](/files/-LPmi5fwnl8nrOxcjVdD)

#### Recording a Non-Repeating Signal

What if you have a continuous signal that does not repeat, such as the output from a microphone? Begin with your oscilloscope in AUTO mode, then adjust TIME/DIV. Because every sample is now different, you may want to capture a rapid series of views. A typical digital oscilloscope can store 32 or more, allowing you to step through them after they have been saved to memory.

In the next tutorial we will share some more advanced features of oscilloscopes.


# Digital Oscilloscopes

This tutorial will explain some features that are slightly more advanced and may be available only on digital oscilloscopes (more properly known as digital storage oscilloscopes, or DSOs). Our two previous tutorials have described basic concepts and setup procedures, which will help build a solid foundation for the lessons in this tutorial.

![](/files/-LZlGNruBYcrrlv9T3Ig)

“[My Friend Oscilloscope](https://commons.wikimedia.org/wiki/File:My_friend_oscilloscope.jpg)” by Wild Pancake is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/deed.en).

{% content-ref url="/pages/-LNlnwgIjFV3i781jBZu" %}
[What is an Oscilloscope?](/oscilloscopes/what-is-an-oscilloscope)
{% endcontent-ref %}

{% content-ref url="/pages/-LPmTW2JR4qF1czmDgQA" %}
[How to Use an Oscilloscope](/oscilloscopes/how-to-use-an-oscilloscope)
{% endcontent-ref %}

## Digital Oscilloscopes Explained

Most oscilloscopes today are digital, meaning that they take rapid samples of an analog voltage and digitize the samples for manipulation and storage. This processing is done internally in benchtop and handheld oscilloscopes, while a USB oscilloscope typically offloads the task to a desktop or laptop computer.

## Bit Depth and Sampling Rate

The conversion of voltage samples into numbers that can be stored in memory is done by an analog-digital converter (ADC). This is comparable to the process of digitizing music for an MP3 file or a compact disc.

A typical moderately priced digital oscilloscope will use 8 bits (binary digits) to store 256 possible voltage values within the range selected by the user. Precision oscilloscopes may use 12 bits (4,096 values) or 16 bits (65,536 values) to store each voltage sample.

The speed of converting and storing samples will be limited by processing power. A digital oscilloscope may allow you to set the frequency and bit depth manually, but if the processor is unable to reach the frequency requested by the user, it may draw straight lines between points on the screen or may link them with little curves calculated with a trigonometry function.

This process of inferring missing data is known as interpolation. Figure 1 shows straight-line interpolation, beginning with an analog signal at the top, a rapidly sampled digital version with 20 voltage levels in the middle, and a slowly sampled version with only 5 voltage levels at the bottom.

![Figure 1: Straight-line interpolation](/files/-LQeYsmS1r18fvddKcsZ)

Sampling rate is measured as MS/s (megasamples per second) or GS/s (gigasamples per second). The peak sampling rate quoted by a manufacturer may be attainable only when a single channel is in use; a second channel will almost double the processing requirements, and the sampling rate may diminish accordingly.

Ideally the sampling rate of a digital oscilloscope should be about 10 times the highest signal frequency that you will be measuring.

## Probe Attenuation

The most common type of oscilloscope probe has a little slide switch on its body, as shown in Figure 2. 1X is the normal position. The 10X position engages a resistor-capacitor combination inside the body of the probe which attenuates the measured voltage by a factor of 10. This allows you to measure voltages that are up to 10 times the usual limit for the oscilloscope. The higher resistance of a probe in its 10X setting also imposes less load on the circuit that you are testing, but you will lose accuracy at low voltages.

![Figure 2: 1X and 10X probe attenuation switch](/files/-LQeZAo8PbUMLI5y5Li9)

The default for most oscilloscopes is 10X attenuation, as it offers a balance of bandwidth and amplitude. 1X should be reserved for signals with low frequency and low voltages. Additionally, your oscilloscope may have a setting that allows you to specify probes with different characteristics, such as 100X for dealing with very high voltages.

## Multiple Views

Almost all oscilloscopes have at least two channels, each of which can display a signal from a separate probe. This enables you to compare signals from more than one source.

For example, suppose you have two 7555 timer chips wired in astable mode, and one of them modulates the signal from the other. This can be done by taking the fluctuating voltage on the Threshold pin of the first chip and connecting it with the Control pin of the second chip. In Figure 3, the control voltage from the first chip is the blue triangular waveform while the square wave from the output of the second chip is red. You can see that when the control voltage increases, the frequency of the square wave decreases.

![Figure 3: The control voltage and output signal of a 7555 timer](/files/-LQeZQqE2sSznkRhvxA2)

The two traces may also be displayed in a split screen, as in Figure 4. The VOLTS/DIV of each view can be adjusted separately, so that each trace fills its window.

![Figure 4: The control voltage and output voltage displayed on a split screen](/files/-LQeaMsf99B2P-UY8W11)

## Advanced Triggering

On a digital oscilloscope, the basic triggering capability that I described in "How to Use An Oscilloscope" (link above this article) will have additional variations.

### Edge Trigger

A simple edge trigger tells the oscilloscope to start capturing data either when the voltage rises up through a trigger threshold or drops down through it. A digital oscilloscope can be set to respond if either of these events occurs.

### Pulse-width Trigger

Pulse-width triggering detects pulses that are either longer or shorter than specified. This is useful for sensing momentary timing inaccuracies in a repeating signal.

### Window Trigger

A window trigger detects voltage entering or leaving a window that may be defined visually on the screen.

### Trigger Hysteresis

Hysteresis can be specified to eliminate false positives caused by a noisy signal. This setting basically tells the oscilloscope, "When voltage rises through a lower threshold, wait until the voltage continues to rise through a higher threshold." In the hysteresis zone between these levels, the oscilloscope ignores small variations. If the voltage drops back below the lower threshold without ever reaching the higher threshold, the triggering operation is cancelled until the next rise through the lower threshold occurs.

A hysteresis setting can also be used to sense a falling voltage that drops through a higher threshold followed by a lower threshold.

### Trigger Delays

You may also set pre-trigger time or post-trigger delay to determine the moment when the signal will be displayed before or after the triggering event.

All of these trigger options may help to detect events such as voltage spikes that are brief, intermittent, and difficult to see.

## Measurements

Any digital oscilloscope should be able to derive immediate numeric measurements from a trace or a segment of a trace. These measurements will include the frequency of a signal, its minimum and maximum voltage, its average voltage, and its RMS value.

RMS is an acronym for root-mean-square, and is calculated by squaring each of a series of regularly spaced voltage measurements, finding the average of the squares, and then extracting the square root of the average. The result is equivalent in power to a DC voltage of the same value; thus 110V DC should cause an incandescent bulb to burn as brightly as 110V AC RMS, even though the AC signal will have higher peak values.

Other features may be available in oscilloscopes, but they are less commonly used or more technical than the ones listed here.


# How Does an Oscilloscope Work?

## How Does an Oscilloscope Work?

### Overview of Oscilloscopes

![Figure 1: Digital oscilloscope in action](/files/-LXHNfZJby7Tf640F9Su)

At its core, an oscilloscope allows you to watch how the voltage between two points in a circuit varies over time. For example, if you were to probe a sinusoidal voltage, your oscilloscope might display something similar to Figure 2.

![Figure 2: Sine wave as measured by an oscilloscope](/files/-LNlsbSNx-pkbgDASFgk)

By looking at such waveforms, you can get an idea of how a circuit is operating. This can help you identify potential problems with the circuit, characterize its operation, or view signal integrity over a transmission line. This article can help you understand more about the basics of an oscilloscope: [What is an Oscilloscope?](/oscilloscopes/what-is-an-oscilloscope)

The most popular modern oscilloscope is the digital storage oscilloscope (DSO). Before we examine how a DSO works, let's take a look at its humble beginnings.

### Analog Oscilloscope

One of the first attempts at automating the system of converting electrical signals to a display was the Hospitalier Ondograph in the early 1900s. This device, shown in Figure 3, relied on discharging a capacitor into a galvanometer, which had a pen attached to the end. As the voltage varied, the pen would move back and forth, drawing a waveform on a scrolling piece of paper.

![Figure 3: Hospitalier Ondograph](/files/-LXGREPPdOWjIN-aCRhf)

Unfortunately, most electrical signals varied too quickly for the ondograph's mechanical system. As a result, a signal needed to be sampled multiple times to be drawn on the paper accurately.

In the late 1800s, scientists discovered that subatomic particles (now known as electrons) would travel in straight lines from the cathode end of a [Crookes tube](https://en.wikipedia.org/wiki/Crookes_tube). As a result, scientists dubbed these particles "cathode rays." In the subsequent years, other scientists discovered that these rays could be bent by applying an electric field or a magnetic field.

In 1897, Karl Ferdinand Braun, German physicist and inventor, built the first oscilloscope cathode ray tube (CRT) by applying a voltage to vertical plates over and under the electron beam. The electron beam would strike a phosphor plate on the opposite end and paint a bright dot. As the voltage varied across the plates, the dot would dance up and down, as shown in Figure 4.

![Figure 4: Cathode ray tube with one set of plates](/files/-LXHT6HDxTUbKlYNhflx)

Jonathan Zenneck, physicist and electrical engineer from the Kingdom of Württemberg (now part of Germany), added a set of horizontal plates to the CRT in 1899, which allowed the electron beam to sweep back and forth across the screen. With the ability to control the vertical and horizontal motion, we can now construct a graph of an electrical signal on a screen in real time.

The following video shows how an analog oscilloscope can be used to measure voltages in a circuit:

{% embed url="<https://www.youtube.com/watch?v=6WFlbHi2xnE>" %}

Now that we've seen how analog oscilloscopes came into being, lets break down their operation. Figure 5 shows the internals of such a scope (in block diagram form) along with descriptions of each of the components.

![Figure 5: Block diagram of analog oscilloscope](/files/-LXHZRLBb4LTknqcO-1G)

**Probe:** The piece that connects to your circuit under test. Most probes have two tips, as oscilloscopes measure the electric potential difference (voltage) between two points.

**Amplifier/Attenuator:** Often, an electrical signal needs to be amplified (increased in amplitude) or attenuated (decreased in amplitude) to be effectively displayed to the user or to not damage the internal circuitry of the oscilloscope.

**Trigger System:** A trigger is a user-defined condition (such as a voltage threshold) that determines when the oscilloscope should begin drawing a waveform. This can be extremely helpful in finding sporadic pulses in a circuit or synchronizing the display to a repeating pattern, like a sine wave, so that it appears steady on the screen.

**Sweep Generator:** To control the horizontal plates in the CRT, the sweep generator creates a repeating sawtooth voltage pattern. This causes the beam to sweep from one side to the other in the CRT. The frequency and triggering of the sweep generator is set by the user.

**Horizontal Amplifier:** Much like the amplifier found after the probe, the horizontal amplifier increases the amplitude of the sawtooth wave from the sweep generator so that it can control the horizontal plates in the CRT.

**CRT:** An electron gun fires a steady stream of electrons onto a phosphor-coated screen, which produces a bright dot. Two sets of plates control the deflection of the beam. The vertical plates are directly controlled by the voltage seen on the probe, and the horizontal plates are controlled by the sweep generator. As the deflection of the beam changes rapidly, a solid line appears on the screen. This line on the display represents the voltage (as seen on the probe) as it varies over time.

### Digital Oscilloscope

In the 1980s, the company Nicolet Test Instrument created the first digital storage oscilloscope (DSO) using a relatively slow (1 MHz) analog-to-digital converter (ADC). As digital technology became more advanced, digital oscilloscopes became faster, smaller, and more popular.

Modern DSOs are essentially computers with high-end ADCs used to sample voltages. However, many of the functions and the interface are the same as those found on older analog oscilloscopes, as can be seen in figure 6.

![Figure 6: Using a modern digital storage oscilloscope](/files/-LXGl0o8eovXRfJVnl_y)

Figure 7 shows the internal workings of a digital storage oscilloscope.

![Figure 7: Block diagram of a digital storage oscilloscope](/files/-LQpli3BZL4xmzJJ9V7p)

**Probe:** The oscilloscope needs a way to measure the voltage between two points in your circuit under test. Most probes have two tips that you attach to different nodes in your circuit.

**Amplifier/Attenuator:** Most oscilloscopes have circuits that amplify or attenuate captured electrical signals so they can be effectively displayed to the user and to avoid damaging components inside the oscilloscope.

**Trigger Select:** Many modern oscilloscopes allow you to chose between an internal or external signal (from a separate source) to trigger the display of the waveform.

**Control Logic:** Logic or software that allows a user to configure how signals are captured and displayed. The control logic is similar to the horizontal controls found on the analog oscilloscope but often offers more options.

**ADC:** The analog-to-digital converter samples the electrical signal from the test circuit at regular intervals as set by the control logic. These samples are converted to binary numbers that are stored in memory.

**Memory:** Digital information representing the sampled signal is stored in memory. This information is used to reconstruct a close approximation to the original electrical signal on the display in graph format.

**Time Base:** As set by the control logic, the time base controls the horizontal axis on the display. The user can set one or more trigger points to adjust the time base to capture sporadic signals or hold periodic signals, like sine waves, steady in the display.

**Display:** The oscilloscope takes data from memory, combines it with information from the time base, and displays a waveform on the screen. Often, this waveform will be a close representation of the originally sampled signal with voltage as the Y-axis and time as the X-axis. Some older digital oscilloscopes use CRTs as displays whereas most modern DSOs rely on LCDs.

### The Evolution of Oscilloscopes

Ever since their invention, oscilloscopes have evolved into smarter and more powerful pieces of test equipment. PC-based oscilloscopes are highly portable and use a computer's processing power to analyze and display waveforms. Digital phosphor oscilloscopes (DPOs) add features that mimic analog oscilloscope's abilities to display a signal's frequency-of-occurrence.

Oscilloscopes paved the way for [logic analyzers](/logic-analyzers/what-is-a-logic-analyzer), which specialize in displaying digital signals. Eventually, these two powerful pieces of equipment would be combined into the mixed signals oscilloscope (MSO). MSOs are capable of displaying analog signals just as well as an oscilloscope while analyzing digital signals like a logic analyzer.


# How to Measure Current with an Oscilloscope

## How to Measure Current with an Oscilloscope

### The Problem with Oscilloscopes

An oscilloscope allows you to look at how the voltage between two points varies over time. By plotting this voltage with respect to time, you end up with a graphical representation of your signal. If you would like to learn more about how oscilloscopes perform this function, we recommend checking out this [article first](/oscilloscopes/what-is-an-oscilloscope).

An electrical engineer's first measurement tool is often a multimeter, which is capable of measuring several things, such as voltage, current, and resistance. A multimeter generally shows an average over time, and as a result, cannot display rapidly changing pulses or repeating signals. This is where an oscilloscope comes in handy.

On the other hand, many multimeters are capable of measuring current, which is something an oscilloscope cannot do. So, how do we measure current for a system that rapidly changes? First of all, why would we want to do this?

### Example Circuit

Let's say that you are building the next smartphone, and you want to figure out how long the battery will last. Smartphones are capable of turning on and off features only when needed, such as transmitting to a cell tower at specific intervals. If you were to measure the current flowing from the battery to the rest of the phone, you would see current that changes rapidly all the time. You would not be able to get a consistent reading!

![Figure 1: Measuring current consumption of a smartphone](/files/-LXQ25CEGU3L_DplekyL)

This is where an oscilloscope can help. If you were able to measure current consumption as it changes with time, you might get a graph like in figure 1. As a result, you could begin to calculate how long your battery would last.

Measuring current draw in real time (as opposed to an average) can help you characterize your device's power usage or debug potential problems. For example, your processor may draw a large amount of current at startup, and you would need an oscilloscope to see that surge.

### Measuring Current

The easiest and most common method of measuring total current flowing into a load is to use a shunt resistor. This is accomplished by placing a low-value resistor inline with the power (or return line).

![Figure 2: Shunt resistor circuit](/files/-LXQ4dgIha7nfmNapZ5z)

In this case, your load would be your circuit under test (such as your smartphone). The power supply would be something like your battery or wall adapter.

If you measure the voltage across the resistor, then you could use Ohm's Law to calculate the current flowing into your load:

$$
V=I\times R
$$

We simply rearrange the formula to solve for current:

$$
I= \frac{V}{R}
$$

If we know the resistance and measure the voltage drop across the resistor, we can calculate the current flowing through the resistor, which is the same as the current flowing into the rest of the circuit and that moment.

For example, let's say that we have a 0.1 Ω shunt resistor and we measure a 0.03 V drop across it using our multimeter:

$$
I= \frac{0.03 V}{0.1  \Omega } =0.3 A
$$

We would determine that at that particular moment, 0.3 A was flowing from our power supply into our load.

Shunt resistors (Rsh) are often kept to low resistance values so as not to induce a voltage drop in the circuit. Remember, as the current draw into your load increases, the voltage drop across the shunt resistor also increases. This could result in a voltage drop large enough to power down your whole system!

Common values for Rsh are in the 0.01 to 0.1 Ω range. Using higher values of Rsh offers more accuracy of your measurement but at the cost of increased voltage drop in the power rail to your load.

### Power Limitations

The other thing you must keep in mind is the power dissipation of your shunt resistor. For most low-power systems, a 1/4 W resistor will suffice. As you start drawing more current, the resistor will begin to dissipate more power as heat, which could damage the resistor (resulting in failure or worse, fire).

DC power is calculated as:

$$
P=V \times I
$$

This can be used as a worst-case calculation for how much power you expect Rsh to dissipate. Form our previous example, we can see that:

$$
P = 0.03 V \times 0.3 A = 0.009 W
$$

Even a tiny 1/10 W or 1/8 W resistor would be capable of acting as a shunt resistor in this case. However, let's say that our circuit suddenly turns on a DC motor, and the voltage drop across Rsh increases to 0.5 V. We would calculate the current as:

$$
I = \frac{0.5 V}{0.1 \Omega } = 5 A
$$

We now have 5 A flowing through our circuit! That's quite a large increase from before. Now we calculate the expected power dissipation through our resistor:

$$
P=0.5 V \times 5 A = 2.5 W
$$

We're now expecting the shunt resistor to dissipate 2.5 W of power. That would be far too much for most basic 1/4 W resistors. At this point, you should look at using a 3+ W power resistor or switching to a lower value for Rsh.

The lesson is this: choose the value of your shunt resistor based on the expected current draw of your circuit. It doesn't cost much to perform a few quick calculations to save the headache of damage to your circuit later!

### Oscilloscope Setup

Now that we've seen how to select a value of Rsh and measure current flowing through it, let's take a  look at how we might configure our oscilloscope to measure current. At first glance, our original schematic (Figure 2) might look like it would work well. Using the resistor on the positive rail is known as a *high-side* shunt resistor. There is a slight problem with that, however: the ground clip on most desktop oscilloscopes is directly connected to earth ground!&#x20;

This video provides a great overview of how an oscilloscope ground clip might short out a power supply on your circuit:

{% embed url="<https://www.youtube.com/watch?v=xaELqAo4kkQ>" %}

If we are working with a circuit that is grounded and a desktop oscilloscope (that is also properly grounded), then connecting the ground clip to either side of Rsh would result in a short. Not good.

One option is to move the resistor to the return path (known as a *low-side* shunt resistor) and connect the oscilloscope's ground clip to the circuit's ground.

![Figure 3: Measuring shunt resistor voltage with oscilloscope](/files/-LXQcvWQdNb-3xCt4RNB)

You will not have to worry about shorting out your power supply with this setup. However, you introduce a new problem: a ground loop. Current can circulate around the ground loop (from earth ground, through our circuit under test, through the oscilloscope ground clip, back to ground through the oscilloscope).

![Figure 4: Potential ground loop from measuring circuit with an oscilloscope](/files/-LXQd4YCDD07qhRxNckI)

Ground loops can cause unwanted interference or noise to appear on your measurements or in your circuit. [This article does a great job at explaining ground loops](https://hackaday.com/2017/03/09/wtf-are-ground-loops/). Note that this is only a real problem if both your oscilloscope and circuit under test are both connected to earth ground, as shown in figure 4.

If your oscilloscope or device under test is battery-powered or isolated from earth ground, you do not need to worry about this issue. However, to be extra safe, the best way to measure the voltage drop across a shunt resistor is to use a two-probe setup configured as a differential pair.

### Differential Probe Setup

You will need 2 channels on your oscilloscope to perform this measurement. Most oscilloscopes have their ground clips connected together (you can confirm this with a multimeter if you are unsure). As a result, we do not need to connect the ground clips to anything.

Connect your probe tips to either side of the shunt resistor. For this example, we assume that channel 1 is at a higher potential than channel 2. While Figure 5 shows a low-side shunt resistor, note that you can do this with a high-side resistor as well.

![Figure 5: Differential probe setup](/files/-LXQeeGGF07enElcFA4D)

On your oscilloscope, select the *Math* function (assuming your oscilloscope has such a function). From there, you should be able to plot the output of *Ch 1 - Ch 2*. By subtracting the channel 2 voltage from the channel 1 voltage, we can compute the voltage drop across the resistor without worrying about shorting our power supply or creating a ground loop!

Remember that for every point on this waveform, you will need to divide the voltage by the value of the shunt resistor to get the current flowing into your system. Some oscilloscopes allow you to divide the measured value by a constant to save you from needing to perform this step. Check the *Math* functions in your oscilloscope!

### Other Options for Measuring Current

If your oscilloscope is battery powered or your device under test is isolated from Earth ground (for example, it is also battery powered or you are using a two-pronged wall adapter), then you do not have to worry about shorting your power supply to ground. Feel free to attach that ground clip to either side of your shunt resistor!

You can also purchase a specialized *differential probe* for your oscilloscope that accomplishes the same differential setup we discussed above. However, a differential probe requires only 1 channel instead of 2. Additionally, differential probes can be quite pricey.

Another option is an oscilloscope current probe. Most current probes clamp around an exposed wire and measure the magnetic field generated by the current flowing through the wire. This requires an exposed wire in your circuit, and clamp-style probes are generally only accurate down to the milliamp level. A shunt resistor is generally needed to measure microamps and nanoamps

A fourth option is to use a specialized circuit or part for measuring voltage across a shunt resistor, such as an INA169. The INA169 essentially creates a differential probe around the shunt resistor and produces an output voltage that you can measure on a scope. However, note that the INA169 is only capable of measuring positive voltages (high-side shunt resistor). Make sure you fully read the datasheet to understand the part's limitations!

There are many options for measuring current flowing through your circuit. We recommend taking some time to understand how you can take such measurements and the limitations of each approach.


# Scope + Saleae

### Understanding the cause

Your **Scope** is great for **“what’s it look like?”**

Your **Saleae** is great for **“what’s the history?”**

### Searching for clues

Your **Scope** is great for **“is the I2C bus running?**”

Your **Saleae** is great for **“where’s my problem in these 10,000 transactions?”**

### Understanding the context

Your **Scope** is great for **“does that signal ever droop during our zero crossings?”**

Your **Saleae** is great for **“what’s the situation before, during, and after my failure? — on these 3 rails, 4 GPIOs, and two SPI buses?”**

### Validating the design

Your **Scope** is great for **“Is my rail too noisy?”**

Your **Saleae** is great for **“Are all 6 of my rails coming up and down in the right sequence?”**

### Extending the capabilities

Your **Scope** is great for **“how can I write Python to capture waveforms?”**

Your **Saleae** is great for **“how can I write Python to decode my proprietary BMS protocol?”**<br>

### Why the differences?

Scopes take individual “snapshots” of signals, typically up to 4, based on a trigger.  They’re great for seeing what’s happening right now, on up to few signals, especially when those signals continually repeat.  Scopes don’t require you to fire up your computer, so often they are the most convenient tool for the job.  Because they don’t need to record for long periods, that can be be very high bandwidth — critical for signal integrity, eye diagrams, etc. &#x20;

\
Saleae’s logic analyzers can also give you a live view of “what’s going on” — but they really shine when you need to recording lots of signals over fairly long time periods.   Once set up, you could plug in your DUT’s USB cord, type some things into the console,  and then unplug your DUT, maybe 60 seconds later — and have a record of everything that happened during that time —  perhaps several power rails, pwm signals, protocol busses, and GPIOs. &#x20;


