Microcontroller development engineers and electronics enthusiasts deal with various digital circuits daily. In addition to using multimeters and oscilloscopes for circuit debugging, a logic analyzer is also essential.
A logic analyzer is an instrument that collects and displays digital signals from a test device using a clock, primarily for timing analysis.
Unlike oscilloscopes, a logic analyzer cannot display continuous analog waveforms but only shows two levels of states (logic 1 and 0).
After setting the reference voltage, the logic analyzer compares the collected signals with a voltage comparator, where signals above the reference voltage are considered logic 1, and those below are logic 0.
This allows the measured signals to be displayed as continuous high and low level waveforms in chronological order, facilitating analysis and debugging for the user.
Using a logic analyzer, one can easily set signal trigger conditions to start sampling, analyze the timing of multiple signals, capture signal interference spikes, and decode level sequences according to rules to complete communication protocol analysis.
Logic analyzers are mainly divided into two categories based on their hardware functionality and complexity: standalone (single-unit) logic analyzers and PC-based virtual logic analyzers.
Standalone logic analyzers integrate all software and hardware into one instrument, making them user-friendly. Virtual logic analyzers require a computer to utilize its powerful computing and display capabilities for data processing and visualization.
Professional logic analyzers typically have numerous sampling channels, ultra-fast sampling speeds, and large storage depths, but their expensive prices are often unaffordable for individuals.
As a commonly used development tool for engineers, many entry-level logic analyzer designs are available. Although their overall functionality cannot compare with high-end professional instruments, achieving specific functions at a lower cost is also a very successful design.
The logic analyzers discussed in this article mainly refer to this type of entry-level design.
PC-based parallel port logic analyzers were once mainstream, but in recent years, computer systems have gradually stopped being equipped with parallel ports, making this design obsolete, only retaining educational value.
Another type of logic analyzer is based on low-speed microcontrollers. Many enthusiasts have designed their own devices using common microcontrollers like PIC and AVR. However, these microcontroller-based logic analyzers share a common weakness: their sampling speed is too slow, usually not exceeding 1MHz.
Entry-level logic analyzers based on USB IO chips are currently the most popular.
For example, Saleae Logic and similar products like USBee. These products mainly use a USB IO chip, such as Cypress’s CY7C68013A-56PVXC, where all signal triggering and processing tasks are completed by software on the computer, and the hardware part is merely a data logger.
The maximum sampling speed is 24MHz.They can sample an “unlimited number” of signals since all data is stored on the computer.
Currently, there are generally up to 8 channels, and increasing the number of channels proportionally reduces the maximum sampling speed.This type of product is simple in construction, easy to use, and inexpensive, making it a good tool for debugging microcontroller development work.
Its main drawbacks are a sampling speed of only 24MHz and 8 channels, which are insufficient for analyzing high-speed parallel buses.
Further designs require the addition of components like FPGA and SRAM to address speed and channel number limitations.
Next, we will take the Saleae logic analyzer as an example to briefly introduce its features and usage by sampling and analyzing the I2C bus waveform and PWM waveform.
First, we will introduce the process of using the logic analyzer to sample the data writing process of the I2C device AT24C16 by the microcontroller.
Hardware Connection
1. First, connect the GND of the logic analyzer to the GND of the target board to ensure a common ground.
2. Select the signals to be sampled, which are the SDA and SCL of the AT24C16, connecting SDA to channel 1 (Input 1) of the logic analyzer and SCL to channel 2 (Input 2).
3. Connect the logic analyzer to the USB port of the computer, and Windows will recognize the device, displaying the USB device identifier in the lower right corner of the screen.
Software Usage
1. Run the Saleae software; at this point, the hardware of the logic analyzer is connected to the computer, and the software will display [Connected].
2. Set the sampling quantity and speed; since I2C is a low-speed communication, the speed does not need to be too high, so we set it to 20M Samples @ 4M Hz, which allows continuous sampling for 5 seconds.
3. Set the protocol by clicking the “Options” button in the upper right corner, find analyzer1, and set it to the I2C protocol, as shown in Figure 1.
4. Press the “Start” button to begin sampling.
Figure 1
Data Analysis
After sampling is complete, the waveform can be seen, as shown in Figure 2. Since we set it to I2C analysis, it not only displays the waveform but also decodes and shows the byte content according to the I2C protocol.
The microcontroller performs a write operation to the AT24C16, writing the number 10000 at address 0x00. The waveform starts with a “start” signal, followed by the identifier 0xA2 for the AT24C16, the write address 0x00, and the data 0x10, 0x27, etc. Since writing is done byte by byte, 0x2710 = 10000, indicating successful sampling.
Hover the mouse over the waveform and click the left mouse button to zoom in. The result is shown in Figure 3, where after the “start” condition, at the high level of the 8 consecutive pulses of SCL, the corresponding signal of SDA is 10100010, which is 0xA2, and the high level of the 9th pulse is 0, indicating the ACK flag.
Figure 2
Figure 3
Figure 4
The above briefly introduces the process of using a logic analyzer for I2C analysis, demonstrating that the operation is very simple.
Next, we will introduce how to use the logic analyzer to sample the 6-channel PWM waveforms of a three-phase AC motor driver.
Hardware Connection
1. First, connect the GND of the logic analyzer to the GND of the target board to ensure a common ground, as shown in Figure 5.
2. Select the signals to be sampled, which are the output pins of the 6-channel PWM waveforms from the microcontroller, connecting them to channels 1 (Input 1) to 6 (Input 6) of the logic analyzer, and rename the channels to Utop, Ubottom, Vtop, Vbottom, Wtop, WBottom, representing the upper and lower arms of the three outputs.
3. Connect the logic analyzer to the USB port of the computer, and Windows will recognize the device, displaying the USB device identifier in the lower right corner of the screen.
Figure 5
Software Usage
1. Run the Saleae software; at this point, the hardware of the logic analyzer is connected to the computer, and the software will display [Connected].
2. Set the sampling quantity and speed; the frequency of the PWM is 15kHz, so we set it to 2M Samples @ 4MHz.
3. Set the trigger condition; the default “—-” is sufficient.
4. Press the “start” button to begin sampling.
Data Analysis
After sampling is complete, the waveform can be seen, as shown in Figure 6.
Figure 6
Typical three-phase motor drive PWM is complementary, meaning that the states of the upper and lower waveforms of a signal group are opposite, controlling the states of the upper and lower switches of the bridge arm to avoid short circuits caused by simultaneous conduction, as shown in Figure 7.
Figure 7 Typical three-phase motor drive circuit
Hover the mouse over the waveform and continuously click the left mouse button to zoom in. See Figure 8.
Figure 8
Mark lines at the falling edge of UBottom and the rising edge of UTop; in the display box at the bottom right, you can see T2-T1=2.25μs, which is the time difference between turning off and turning on, professionally known as “dead time”.
Additionally, you can see the PWM width of 45.5μs, period of 66.6μs, duty cycle of 31.6%, frequency of 15.0376kHz, and other information. This is a typical SVPWM waveform of a three-phase motor inverter.
The above two examples briefly introduce the use of logic analyzers, hoping to provide help and inspiration to developers.