Logic Analyzers in Practice (Extract)

Page 1

books books

books books

Logic Analyzers in Practice

Logic Analyzers in Practice Step-by-step instructions guide you through the analysis of modern protocols such as I2C, SPI, UART, RS-232, NeoPixel, WS28xx, HD44780 and 1-Wire protocols. With the help of numerous experimental circuits based on the Raspberry Pi Pico, Arduino Uno and the Bus Pirate, you will learn the practical application of popular USB logic analyzers. All the experimental circuits presented in this book have been fully tested and are fully functional. The necessary program listings are included — no special programming or electronics knowledge is required for these circuits. The programming languages used are MicroPython and C along with the development environments Thonny and Arduino IDE. This book uses several models of flexible and widely available USB logic analyzers and shows the strengths and weaknesses of each price range.

“I am an electronics technician and work intensively with electronics in my professional environment as well as privately, dealing with analog and digital robots, computers, amateur radio, circuit design and circuit board layouts, microcontrollers... Did a lot of soldering and troubleshooting and faultfinding, repaired many things conducting electricity, and often failed. But I have always enjoyed recording my experiences and passing on my knowledge.” Jörg Rippel

You will learn about the criteria that matter for your work and be able to find the right device for you. Whether Arduino, Raspberry Pi or Raspberry Pi Pico, the example circuits shown allow you to get started quickly with protocol analysis and can also serve as a basis for your own experiments.

Logic Analyzers in Practice • Jörg Rippel

PC USB Logic Analyzers with Arduino, Raspberry Pi, and Co.

PC USB Logic Analyzers with Arduino, Raspberry Pi, and Co.

After reading this book, you will be familiar with all the important terms and contexts, conduct your own experiments, analyze protocols independently, culminating in a comprehensive knowledge set of digital signals and protocols. Elektor International Media www.elektor.com

Jörg Rippel

SKU20780_COV_Logic Analyzers in Practice.indd All Pages

24/01/2024 14:49



Logic Analyzers in Practice PC USB Logic Analyzers with Arduino, Raspberry Pi and Co.

● Jörg Rippel

Logic Analyzers in Practice - UK.indd 3

23-01-2024 16:15


● This is an Elektor Publication. Elektor is the media brand of Elektor International Media B.V.

PO Box 11, NL-6114-ZG Susteren, The Netherlands Phone: +31 46 4389444

● All rights reserved. No part of this book may be reproduced in any material form, including photocopying, or

storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication, without the written permission of the copyright holder except in accordance with the provisions of the Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to reproduce any part of the publication should be addressed to the publishers.

● Declaration The author, editor, and publisher have used their best efforts in ensuring the correctness of the information contained in this book. They do not assume, and hereby disclaim, any liability to any party for any loss or damage caused by errors or omissions in this book, whether such errors or omissions result from negligence, accident or any other cause. All the programs given in the book are Copyright of the Author and Elektor International Media. These programs may only be used for educational purposes. Written permission from the Author or Elektor must be obtained before any of these programs can be used for commercial purposes.

● British Library Cataloguing in Publication Data

A catalogue record for this book is available from the British Library

● ISBN 978-3-89576-592-6 Print ISBN 978-3-89576-593-3

eBook

● © Copyright Elektor International Media www.elektor.com

Translator: Martin Cooke Prepress Production: D-Vision, Julian van den Berg Printed in the Netherlands

Elektor is the world's leading source of essential technical information and electronics products for pro engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops and delivers high-quality content - via a variety of media channels (including magazines, video, digital media, and social media) in several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

●4

Logic Analyzers in Practice - UK.indd 4

23-01-2024 16:15


Contents

Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Chapter 1 • What You Need to Know About Logic Analyzers . . . . . . . . . . . . . . . . . . 9 1.1 What is a Logic Analyzer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.1.1 What software can you use with a logic analyzer? . . . . . . . . . . . . . . . . . . . . . . 14 1.1.2 Will a basic logic analyzer do the job? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.2 Why do I need a logic analyzer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.3 What’s so special about a logic analyzer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.4 What a logic analyzer is not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.5 How do I connect a logic analyzer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.6 What should I pay for a logic analyzer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.6.1 The entry-level model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.6.2 The mid-range model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.6.3 High-end models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Chapter 2 • Choosing the Right Logic Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.1 Important criteria and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.2 Bandwidth and sampling rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.3 Logic levels and Threshold Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.3.1 What is a logic level? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.3.2 What is a threshold voltage? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.3.3 How does the logic analyzer interpret signals? . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.3.4 Check the threshold voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.4 Positive and negative logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.5 Analogue and digital inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.6 Synchronous and asynchronous sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.6.1 Synchronous sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.6.2 Asynchronous sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.6.3 When to choose synchronous or asynchronous sampling? . . . . . . . . . . . . . . . . . 43 2.7 Buffer and Stream modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.7.1 Buffer mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.7.2 Stream mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

●5

Logic Analyzers in Practice - UK.indd 5

23-01-2024 16:15


Logic Analyzers in Practice

2.7.3 The pros and cons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.8 The USB port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.9 Simple and complex triggering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.10 Checklist for choosing a logic analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.10.1 A checklist of your own needs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.10.2 What’s really important? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.10.3 Logic analyzers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.10.4 Mixed signal devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 2.10.5 Horses for courses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Chapter 3 • Protocols and Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 3.1 Experimental circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 3.1.1 What you will need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 3.1.2 Additional tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.2 The software user interface concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.3 The I²C bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.3.1 The I²C weather station . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.3.2 Analyzing the I²C protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.3.3 The weather station source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 3.4 The SPI bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3.4.1 Raspberry Pi Pico with SPI graphics display . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.4.2 SPI Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.4.3 SPI display source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 3.5 UART / RS-232 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.5.1 The Raspberry Pi Pico and serial data transfer . . . . . . . . . . . . . . . . . . . . . . . . 100 3.5.2 UART analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 3.5.3 Source code for the Pico UART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 3.6 NeoPixel and the WS281x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 3.6.1 The RGB-LED adapter board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 3.6.2 WS28xx analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 3.6.3 RGB-LED source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 3.7 The HD44780 LCD display controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

●6

Logic Analyzers in Practice - UK.indd 6

23-01-2024 16:15


Contents

3.7.1 Bus Pirate and LCD adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 3.7.2 HD44780 analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 3.8 The 1-Wire protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 3.8.1 Source code for the DS1820 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 3.9 Final thoughts on the protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Chapter 4 • Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.1 Errors and issues when measuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.2 The test probes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.3 The ideal test setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 4.4 Ground loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 4.5 Earthing considerations at high frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 4.6 Probe loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 4.7 Where to tap into the signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 4.8 Input voltage range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 4.9 Using a logic analyzer as a scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Post script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Appendix: Setting Up Your Work Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 A1.1 Raspberry Pi Pico and Thonny with MicroPython . . . . . . . . . . . . . . . . . . . . . . . 145 A1.2 Raspberry Pi Pico and Thonny with CircuitPython . . . . . . . . . . . . . . . . . . . . . . 151 A1.3 Arduino UNO and the Arduino IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 A1.4 The Raspberry Pi and Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Literature References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

●7

Logic Analyzers in Practice - UK.indd 7

23-01-2024 16:15


Logic Analyzers in Practice

Preface Digital signals and complex communication protocols can be found in almost every electronic circuit nowadays. It has become easy to connect sensors and displays to our microcontrollers with just a few lines of software and a Raspberry Pi or Arduino. We hope that everything works flawlessly, but sometimes it doesn’t, and it becomes necessary to examine the digital signals and the protocol used in detail. But how do you do that? Today’s protocols have become so complex that trying to verify and decode them can be quite puzzling. This is where a Logic Analyzer can come to your rescue. This book provides you with guidance for taking a leap into the digital world and demonstrates various methods to decode common protocols by working with a wide range of examples. It helps you navigate your first steps with a logic analyzer successfully and offers a structured approach with the most suitable tool for troubleshooting digital circuits; the logic analyzer. This book showcases multiple models of flexible and widely used USB logic analyzers in various price ranges, highlighting their strengths and weaknesses. You will learn about the important criteria necessary for various application fields so that you can choose the device that suits your needs. Whether you’re working with Arduino, Raspberry Pi, or Raspberry Pico, the illustrated example circuits enable a quick start in protocol analysis and can serve as a foundation for your own experiments. You will become familiar with all the essential terms and relationships, conduct your own experiments and analyze protocols independently. With this book by your side you will build a comprehensive knowledge in the realm of digital signals and protocols. I wish you a lot of fun along the way!

●8

Logic Analyzers in Practice - UK.indd 8

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

Chapter 1 • W hat You Need to Know About Logic Analyzers 1.1 What is a Logic Analyzer? A Logic Analyzer is designed to capture and record multiple digital signals simultaneously. Think of it like a video camera that can record a longer or shorter film depending on its resolution. If the video has an 8K resolution, the storage space on the SD card fills up quickly. If you record in VGA resolution, you might capture fewer details, but you can record a much longer video. A Logic Analyzer works on a similar principle. With a high sample rate, you capture more of what’s happening on the bus, but the recording duration is relatively short. What sets apart an Oscilloscope from a Logic Analyzer? A Logic Analyzer is similar to an oscilloscope, but it’s primarily used in digital hardware development and troubleshooting due to its specific functionality. It offers the advantage of having more channels and being designed specifically for this purpose. While an oscilloscope typically has 2 or 4 channels, a basic modern Logic Analyzer already comes with 8 or 16 channels, and more advanced models offer over 32 channels. In the professional realm, devices with 128 channels are not uncommon. Early on in the analysis of microprocessor circuits, the need for these numerous channels became evident. Protocols can run not only on many parallel lines but can also be quite complex. To manage this complexity, the Logic Analyzer must have additional capabilities in its toolkit. It measures the connected signals simultaneously on all channels and can capture specific protocol events using a trigger. This allows for the visualization of complex dependencies among parallel signals. Many aspects are reminiscent of an oscilloscope, and the parallels are undeniable. However, the creators of these two devices had different requirements in mind when building them. Unlike the oscilloscope, which was originally designed in the age of analog electronics, the Logic Analyzer has been developed and optimized in every aspect to work with digital signals. To fully understand the complexity of the protocols used in digital circuits, a Logic Analyzer has become indispensable for circuit protocol analysis. If a problem arises in a digital circuit, for example, if a display controlled by the I²C protocol is not functioning as expected, a developer can try various things in the source code and libraries to find the error, but what’s actually going on in the hardware remains elusive. Is the issue related to signal timing or clock problems, signal line interference, or bus collisions? A Logic Analyzer is often the only tool that can precisely pinpoint the problem. The Logic Analyzer is however not necessarily the ultimate tool for troubleshooting. Using a Logic Analyzer can sometimes be time-consuming and complicated. You might spend several days poring over datasheets, protocol descriptions, protocol analyzers, and setting up trigger events just to get close to identifying the problem. Only when you’ve exhausted all the software-based options for troubleshooting, you will need to dig deep with a Logic Analyzer and invest the necessary time.

●9

Logic Analyzers in Practice - UK.indd 9

23-01-2024 16:15


Logic Analyzers in Practice At first during troubleshooting, you might feel overwhelmed by the abundance of information available from the Logic Analyzer. Don’t let this put you off! It gets better every time you use it. Over time you’ll become skilled and adept at handling the controls and interpreting the display. You’ll find efficient ways to systematically narrow down and locate the problem, even with new protocols and issues. To better understand a Logic Analyzer, you need to grasp some basics of how it functions. A Logic Analyzer not only visualizes the timing of the digital signals it captures but can also interpret them if desired. This is done using special protocol analyzers that analyze and decode the specific protocol into a visually understandable format. Each protocol requires its own protocol analyzer. Sometimes an oscilloscope can complement a logic analyzer in troubleshooting. It excels in accurately displaying analog signals due to its significantly higher sampling rate and signal bandwidth compared to a logic analyzer. An oscilloscope (scope) is the go-to choice when examining analog signals. While it can also view the same digital signals as a Logic Analyzer, it’s typically not optimized for this purpose and is limited to measuring up to four signals by using a 4-channel scope. It’s therefore of little use when dealing with a digital circuit featuring a 32-bit data bus and a 64-bit address bus. What is a scope good for? The scope is designed to provide a highly precise representation of an electrical signal. It excels at showing small irregularities, spikes, or signal overshoots. For instance, it’s particularly useful for investigating signal integrity. This is not a strength of most Logic Analyzers. A Logic Analyzer doesn’t display these irregularities because its main function lies elsewhere. It represents an idealized form of signals by categorizing them as either high or low signals based on their logic levels. The Logic Analyzer has a different perspective on signals, as its signal capture and measurement are structured differently to a scope. Its primary concern is capturing all the 0s and 1s, not the precise signal waveform. As an extreme example, a sinusoidal waveform will be represented as a square wave by a Logic Analyzer.

Figure 1.1: Comparison of a waveform displayed on a scope and a logic analyzer.

● 10

Logic Analyzers in Practice - UK.indd 10

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

Keep this difference in mind: when troubleshooting digital signals, an Oscilloscope can sometimes come to your aid because some signal issues might go unnoticed by a Logic Analyzer. As you can see in Figure 1.1, a relatively weak signal in the middle of the sequence is not recognized as “High” by the Logic Analyzer, and its interpretation of the signal sequence remains “Low” at that point. But what about this potential signal? Was it too weak? Could it have been a noise signal that, if slightly stronger, would have been interpreted as “High” and disrupted the logic? Is this signal attenuated because it’s being loaded by the Logic Analyzer probe impedance? (The connection of a Logic Analyzer can have effects on the circuit, which we will look at later). This puzzle needs to be solved, and that’s where a scope can come in handy since it’s designed for analyzing individual signals. In certain types of errors, an Oscilloscope can also assist with digital circuits. However, errors and issues related to messaging protocols are the strengths of a Logic Analyzer. Structure and History of an MSO In the past, oscilloscopes or just plain ‘scopes’ used to be analog in their construction. These devices directly displayed the signal applied to the input on the screen. The signal received at the input jack was processed and directed onto the inner surface of the cathode-ray tube as an electron beam. This process excited the phosphor layer on the inside of the screen, making a bright line visible on the display. Today, these devices have all but disappeared from the market. In some workshops, you might be lucky enough to spot the once very popular Hameg 203 scope. Today’s oscilloscopes on the market are known as DSOs, short for Digital Storage Oscilloscopes. They operate digitally, transforming the analog input signal into a digital signal stored in a data memory. From there, the signal information is further processed using an FPGA and a lot of software before it’s displayed on a screen. The construction and operation of modern oscilloscopes are entirely different from earlier analog oscilloscopes. Consequently, the most significant technical difference between an oscilloscope and a Logic Analyzer has disappeared. The result of this evolution is the MSO, the Mixed Signal Oscilloscope. The digital architecture of today’s oscilloscopes allows for the combination of both functions. Since the signal at the input jack is already converted into a digital signal, the transition to a Logic Analyzer is no longer a long journey. The Logic Analyzer and the Oscilloscope merge together. For this reason, some manufacturers offer their MSO as two devices in one, an oscilloscope with an integrated Logic Analyzer.

● 11

Logic Analyzers in Practice - UK.indd 11

23-01-2024 16:15


Logic Analyzers in Practice

Figure 1.2: Beneath the display on an MSO you will usually f ind the logic analyzer input pod connector. Back to the Logic Analyzer. So, the Logic Analyzer is a measuring instrument that can simultaneously capture, record, display, measure, and decode digital signals across all its channels. When analyzing the recorded signal waveforms, it allows you to examine the temporal correlation and dependencies between the signals. Protocols can be deciphered and visualized using protocol analyzers, making the control and data signals visible to the human eye.

Figure 1.3: The DSLogic Plus logic analyzer — up to date and powerful. Designed for both hobbyists and professionals, modern Logic Analyzers that connect to a computer via USB offer a wide range of possibilities. When used in conjunction with the accompanying software, they enable the analysis of digital signals, a capability that used to be found only in professional devices at a multiple of the price just a few years ago. The

● 12

Logic Analyzers in Practice - UK.indd 12

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

constant development of plug-ins for this software provides a continuous expansion of features required for decoding ever-evolving protocols. This is a significant advantage compared to earlier devices that had static capabilities. Decoding new digital protocols remains possible long after the purchase of the Logic Analyzer, simply by updating the software. The Purpose of a Protocol Analyzer Regarding protocol analyzers, there’s an important point to consider in understanding their purpose: A protocol analyzer makes the content of the protocol visible and comprehensible. It doesn’t necessarily mean that it’s easy to understand what this protocol does and transmits. For instance, often, the contents of registers from a sensor are transmitted, where a numerical value is encoded in hexadecimal. This introduces another layer where you need to decode the received content, for example, by converting that numerical value to obtain the temperature in Celsius or Fahrenheit. This final step happens in the device’s software. You won’t see this part in the communication between the sensor and the microcontroller. The sensor’s manufacturer provides the necessary steps in the accompanying datasheet, which must then be implemented in the firmware to reach the value eventually displayed on the screen. This is often where many users face difficulty, leading them to give up after their first attempt at using a Logic Analyzer and then feel deflated. A protocol analyzer is useful here to make information readable and comprehensible. It still doesn’t do all the work for you; it just makes it all a bit easier. As mentioned earlier, Logic Analyzers are also available as part of an oscilloscope. As an additional module, alongside the regular analog inputs of the oscilloscope, the user can access another 16 or 32 digital channels. In such a Mixed Signal Oscilloscope (MSO), you have the opportunity to evaluate both analog and digital signals within a circuit at the same time and in relation to each other. When conducting the same analysis with two separate devices, a USB Logic Analyzer and an oscilloscope, this isn’t as straightforward. Analyzing analog and digital signals in relation to each other with two separate devices often requires synchronization of the triggers between both devices. Although simultaneous capture and analysis are technically possible, the results still need to be merged across the device boundary, either visually or by transferring the collected samples to another system for further error analysis. Sounds difficult, error-prone, and complicated, doesn’t it?

● 13

Logic Analyzers in Practice - UK.indd 13

23-01-2024 16:15


Logic Analyzers in Practice

Figure 1.4: Analysis of the I²C-Protocol using a Rigol MSO. To be fair, it’s worth mentioning that the need for such a complex troubleshooting is quite rare. In most cases, a trained eye is sufficient, and more complex situations can usually be resolved using a degree of creativity. A more significant drawback is the behavior of some MSOs. When using the integrated Logic Analyzer, they may deactivate one or two of the analog inputs or only decode the digital signals that are visible on the display, rather than decoding the complete signal history stored in memory. In this regard, a USB Logic Analyzer is much more flexible and powerful than the Logic Analyzers included in entry-level MSOs. However, don’t dismiss the idea of using an MSO for your purposes just yet. These devices have their strengths, which I’ll discuss later. There’s a right tool for every troubleshooting task, and in some cases, an MSO might be the best choice. Now, you already have some knowledge about the hardware of a Logic Analyzer. Let’s move on to the software.

1.1.1 What software can you use with a logic analyzer? Every USB Logic Analyzer comes with software that is essential to complement the hardware of the Logic Analyzer. This software should be capable of controlling individual channels, enabling signal recording, and facilitating the analysis of the recorded signals. The analysis part is often achieved with the help of protocol analyzers, which are usually provided as plug-ins within the software. One well-known piece of software for this purpose is the open-source software Sigrok. It supports a wide range of Logic Analyzers. In many cases, the software that comes with the Logic Analyzer from the manufacturer can be replaced with Sigrok. This is useful if you want

● 14

Logic Analyzers in Practice - UK.indd 14

23-01-2024 16:15


to continue using an old Logic Analyzer that is no longer supported or if your Logic Analyzer is based on a design from the open-hardware community. Sigrok is a command-line program running in the background, while the display and user interface are provided by the Pulseview program.

Figure 1.5: The Sigrok Pulseview Analyzer window — clear and straightforward. The approach in this book is to provide the simplest possible introduction to working with a Logic Analyzer. One of the devices used in this book is a straightforward and budget-friendly model, stocked in the online Elektor Store at an affordable price. The cost-effectiveness of this basic, no-name USB Logic Analyzer is unmatched. With its 8 channels and up to 25 MHz bandwidth, it’s well-suited for most tasks.

Figure 1.6: An affordable 8-channel Logic Analyzer for getting started with protocol analysis.

● 15

Logic Analyzers in Practice - UK.indd 15

23-01-2024 16:15


Logic Analyzers in Practice

To use this Logic Analyzer, you’ll need Sigrok and Pulseview. You can download the latest versions of this open-source software from the internet at http://sigrok.org. This makes it easy to dive into the world of decoding digital signals.

1.1.2 Will a basic logic analyzer do the job? Modern microcontrollers often feature an I²C or SPI interface. The simplicity of the SPI and I²C protocols, their wide support for microcontroller peripheral communications, cost-effectiveness, and ease of implementation on circuit board designs has made these protocols ubiquitous. The serial interface RS-232 is still commonly used as well. This means that a simple low-cost 8-channel Logic Analyzer with a bandwidth up to 20 MHz will be sufficient for the majority of home lab setups. The need for a Logic Analyzer with significantly more channels, for analyzing wide data or address buses like those used in a memory modules, is quite rare for a hobbyist. The clock frequencies on such buses are often so high that much more expensive and professional equipment would be required to carry out an analysis. In these early stages, save the money you would invest in a Logic Analyzer to enter this professional league. As you progress through the book, you will learn about the key points that matter. By the end of the book, you will know precisely which Logic Analyzer could be your next step after this simple 8-channel 24 MHz model. I promise! The principles are essentially the same: If you can handle one Logic Analyzer well, you’ll quickly adapt to operating a different model. How many channels will I need? The peripheral interface protocols used by modern microcontrollers require fewer signals. When connecting a Logic Analyzer, in addition to a GND (ground) connection, you only need channels to connect to each of the following signals: SPI = 4 signals (SDO/MOSI, SDI/MISO, SCK, SS) I²C = 2 signals (SCL, SDA) 1-Wire = 1 signal (DQ) RS-232 = 2 signals (TX, RX) (+ CTS, RTS i.e., 4 signals when using data flow control) HD44780 = 7 or 11 signals (4 or 8-bit data transfers, RW, RS, E)

1.2 Why do I need a logic analyzer? You need a Logic Analyzer because digital circuits are no longer built with logic gates where the signal’s path and states can be easily traced. In the past, you could verify the correct operation of a digital circuit using a logic tester, known as a “Logic Probe”. At various test points within a circuit or at the pins of the ICs (Integrated Circuits), you could check for a high or low signal and follow the signal path through the sequences of ICs until you find the error. You would then repair the faulty area, replace the affected IC, and with any luck the circuit would work again. The logic was “hardwired” within the ICs. Today, logic is defined by software. Some Logic Probes could also count in binary, these high-end versions were called “logic scopes”.

● 16

Logic Analyzers in Practice - UK.indd 16

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

Figure 1.7: A logic scope from the 1980s which can also count in binary. Apart from repairing old circuits from the 1970s and 1980s, you won’t come across such devices these days. Modern digital technology operates using communication protocols with far more complex sequences than the old logic circuits. Due to the wide variety of modern microcontrollers and microprocessors, a multitude of protocols are in use within circuits. Overall, the density of circuits has significantly increased due to the much higher level of integration.

Figure 1.8: Logic chips on the first Apple motherboard were so widely spaced… ‘you could drive a bus through there.’ While hobbyists these days primarily work with digital technology — almost everyone uses an Arduino, Raspberry Pi, or Pico in their projects — very few use a Logic Analyzer for troubleshooting.

● 17

Logic Analyzers in Practice - UK.indd 17

23-01-2024 16:15


Logic Analyzers in Practice

These devices are rarely found in amateur workshops because they used to be rare and expensive. Although Logic Analyzers have become affordable in recent years, they haven’t spread widely beyond professional electronics development. Given that even hobbyists nowadays read their temperature sensors using digital protocols and seemingly simple devices use their own protocols, a basic Logic Analyzer has become an essential tool in an electronics workshop. This is because even colored LEDs are now controlled using digital communication protocols. Various manufacturers have developed affordable Logic Analyzers that connect to a PC via a USB port and operate together with accompanying software. As the digital world and its peripheral communication protocols constantly and rapidly evolve, the software is kept relevant by integrating protocol analyzers as plug-ins which provides a good level of “future proofing” to the hardware. Don’t Forget! Logic analyzer = A device for capturing and analyzing digital signals. Protocol analyzer = A function of the Logic Analyzer software that decodes and makes sense of peripheral communication protocols. Once you become experienced in using a Logic Analyzer, you’ll save a lot of time troubleshooting, and your understanding of all the digital messaging protocols and their various idiosyncrasies will greatly increase.

1.3 What’s so special about a logic analyzer? A Logic Analyzer has multiple inputs, called channels, for simultaneously capturing digital signals. While the more basic models offer 8 to 16 channels, high-end ones can provide up to 80 channels. We’ve already discussed the general differences between a logic analyzer and a scope, but what sets the logic analyzer apart? Digital triggers are a crucial feature of a logic analyzer. Unlike scopes that can use simple trigger events to view the behavior of an analog signal, Logic Analyzers can trigger on complex digital signals, such as rising or falling edges on a single channel or across multiple channels. In some Logic Analyzers, you can define the occurrence of a specific trigger event based on a known time sequence across multiple channels, allowing for multiple triggers on events that are related to each other. Complex triggers also enable the search for specific patterns in the digital signal by defining a trigger pattern. Well-implemented software on the logic analyzer allows you not only to capture the signal’s behavior after a trigger event but also the period leading up to it. This powerful feature is often overlooked during troubleshooting. Not all logic analyzers support these complex triggers, it will depend on the accompanying software. For many of the more popular devices this software is often extendable through community-provided plug-ins, it’s worth checking the manufacturer’s support websites.

● 18

Logic Analyzers in Practice - UK.indd 18

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

The software used with USB-connected logic analyzers is generally more user-friendly than the user interface of earlier standalone devices. Most users today prefer the intuitive interaction provided by a computer mouse which simplifies tasks like searching, zooming in, and conducting measurements like duty cycle, pulse width, frequency, etc., and viewing using a large display monitor. The possibilities and available protocols for decoding digital signals in the accompanying software are almost always more extensive than those in a standalone device. It’s worth noting a particular feature of USB Logic Analyzers: real-time analysis of digital signals has limitations. The data generated can quickly exceed what a USB 2.0 interface can handle, with a limit around 100 MHz when directly transferring the captured signals to the PC. Some logic analyzers can use an internal buffer memory to analyze signals up to 400 MHz, but space is often limited, which restricts the maximum recording time. With a Logic Analyzer featuring a USB 3.0 interface, analyzing signals of up to 1 GHz is possible through direct transfer of captured signals to the PC. This is where the transition to professional-level equipment occurs. Capturing very fast digital signals beyond the 1 GHz mark is reserved for expensive standalone devices that can work at speeds of up to 12.5 GHz, enabling them to verify whether components like DDR4 memory modules meet the necessary specifications. It’s a highly specialized use case. There is still a place in the world for high-end standalone Logic Analyzers.

1.4 What a logic analyzer is not Let’s take a step back to make something clear: No matter how similar these two devices may seem, a Logic Analyzer is not an Oscilloscope! If you don’t keep this in mind, sooner or later, during protocol analysis and error troubleshooting, you’ll run into a trap. Here’s an example to illustrate this: the Run/Stop/Auto-Trigger on an oscilloscope. In this setting, activated by a predefined button on the oscilloscope, a slowly occurring signal is triggered, and the signal display is updated on the oscilloscope screen with every triggered event. This makes any signal changes quickly visible to the eye. Experienced oscilloscope users would love to have such a feature on their Logic Analyzer as well. However, it doesn’t work the same way. The Logic Analyzer is not an oscilloscope. With a Logic Analyzer, the approach is different: Capture – Store – Analyze. Capture: First, with a Logic Analyzer, you capture something called a “sample,” a recording of the protocol over a specific period. This sample can contain one or more events that you want to inspect.

● 19

Logic Analyzers in Practice - UK.indd 19

23-01-2024 16:15


Logic Analyzers in Practice

Store: In a Logic Analyzer, what matters is the protocol or data stream’s details, individual bits in the recording. The sample should be kept as small as possible and as large as necessary for analysis to fit into the provided memory or be transferred to the computer via the USB interface. The sample is stored in the computer, ready for further analysis using software. Analyze Now comes the software-based analysis. It’s all about finding the needle in the haystack. Which events in the captured data are relevant for troubleshooting? Usually, the sought-after events related to the problem you’re looking for are captured using a trigger. How is the trigger defined? You might not know what the problem is, but you know where it is. You extract that location from the haystack using the trigger. The captured data is then structured and grouped using a protocol analyzer. The processed events are displayed in a table, making them understandable, and allowing you to select individual time points row by row for a detailed examination. During this detailed review, you should be able to narrow down or find the problem. So, the difference from an oscilloscope is that the human eye doesn’t need to spot changes. The person operating the Logic Analyzer can work thoughtfully and systematically, analyzing the protocol in detail to find the problem. Results of Protocol Analysis In the Logic Analyzer’s user interface, you’ll usually find the results table of the protocol analyzer, typically in the lower right. You can now use a search filter to specifically look for events in the sample. When you select a row in the table with the mouse, the software zooms in the main window to that point, and the signal display jumps to the relevant spot in the recorded signal.

Figure 1.9: Results table of the I²C protocol analyzer with conditional search capability. With the right trigger settings and a filter applied to the table, you can now sift through the individual trigger points one by one until you’ve found the desired spot in the signal.

● 20

Logic Analyzers in Practice - UK.indd 20

23-01-2024 16:15


Chapter 1 • What You Need to Know About Logic Analyzers

So, this is similar to the Run/Stop/Auto-Trigger method in an oscilloscope. You can cycle through events as if in a flipbook. By jumping back and forth in the table, it becomes more obvious where the differences occur in sequence of events. For simple bit patterns, this can be a useful method for identifying errors in the signals. Electronics experts who are comfortable using an oscilloscope often intuitively apply this approach when working with a Logic Analyzer. Such troubleshooting methods will only help with simple signals. Using a Logic Analyzer much like an oscilloscope overlooks its strengths and severely limits its capabilities. You won’t be able to track down every error that way. The philosophy of a Logic Analyzer is different from that of an oscilloscope. It’s not about the shape of a signal, as it often is with signal representation on an oscilloscope. With a Logic Analyzer, it’s all about the details in the protocol or data stream, the individual bits in the recording. The needle in the haystack is often so small that it remains invisible; no matter how many times your eye scans over it. A single flipped bit is usually not visible to the eye in a digital protocol, no matter how good your flipbook skills are. The detail is too small amidst the multitude of signal waveforms and level changes that fill the screen. A glitch, due to the peculiar way signals are captured by the Logic Analyzer, may appear as a valid bit. It might look like a bit to the eye, but it’s a misinterpretation. For the circuit, it’s still a glitch. (How to deal with this is discussed in the chapter on logic levels and threshold voltages). You’ll never find such an error in the flipbook. That’s exactly why the Run/Stop/Auto mode of the oscilloscope wouldn’t be effective. You have to work with filters, triggers, and a detailed inspection of the signal sequence to find such a small detail What is a Glitch? A glitch refers to a transient and unintended change in a signal level. It is a brief unexpected pulse or spike that occurs in the voltage or current levels of a signal. Glitches are typically much narrower than a clock signal and can be a result of various influences such as signal reflections, crosstalk, or other forms of interference in the circuit. A Logic Analyzer is not intended to be a real-time tool for slow signals. Instead, it’s great for finding sporadic individual events or sifting through many rapidly occurring signals to find specific occurrences. The captured digital protocols are much more complex than analog signal waveforms, which are clearly visible on an oscilloscope screen. Digital protocols are larger, more intricate, and make little sense to the naked eye for visual analysis. At a certain point, you need to start leveraging the numerous capabilities and features of a Logic Analyzer’s software to locate the needle in the haystack, presented on a platter. The phrase “presented on a platter” is the right way to describe how you must make the Logic Analyzer’s software your own to find a challenging error in a complex protocol. While in an oscilloscope, the analog signal often represents the information itself, this is usually not the case with a digital signal. In digital signals, the information lies in the protocol de-

● 21

Logic Analyzers in Practice - UK.indd 21

23-01-2024 16:15


Logic Analyzers in Practice

coded alongside the signal waveform. The individual highs and lows, representing individual signals, are just the threads that collectively form the protocol. When the information is spread across multiple signals in a bus, visual inspection of signals, as commonly made using an oscilloscope, is no longer effective. The eye might sometimes decipher meaning from a single signal, but when dealing with 8 or 16 parallel signals that together constitute a protocol, this doesn’t work anymore. This is where the Logic Analyzer excels; it’s its strength, what sets it apart from all the other instruments on the test bench. It first captures the signal waveforms and then analyzes them. The Logic Analyzer’s software, aided by a protocol analyzer, takes care of interpreting the data. The result is a clear table, where the user can take their time to analyze the results using a search filter and a mouse. Embrace the software’s strengths, consider the specific characteristics of a Logic Analyzer, and you won’t encounter any issues. Working with a Logic Analyzer can be a lot of fun!

1.5 How do I connect a logic analyzer? A typical Logic Analyzer will have two sets of connections. One set consists of a USB port for connection to a PC while the other set is the channel inputs which connect to the target hardware. You connect the probes provided in the Logic Analyzer kit to these channel inputs. Keep in mind that each Logic Analyzer is somewhat different in its setup, so the probes for each channel and their respective ground connections may have a unique arrangement.

Figure 1.10: Differences in the cable hook-up of various logic analyzers. The channel inputs to the target system are typically arranged as a row of pins or a socket/pin header strip along the case edge. In most Logic Analyzers, this connection for the probes has a keyway so that the connector cannot be plugged in the wrong way round. Mixing up the signal and ground connections to the target system could have a serious impact on its longevity.

● 22

Logic Analyzers in Practice - UK.indd 22

23-01-2024 16:15


Index

Index 1-Wire 1-Wire Protocol 5 V tolerant

16,118 125,126,129 73

Digital trigger Dot matrix display DS1820 Dupont cables

18 123 125,128,166 60

A ADC E 38 Earth 24,110,140 A/D converter 49 Earth point 140 Analog 7,11,18,40 Edge rise/fall time 98 Analog input 11,13,52 Error detection 99 Asynchronous sampling 41, Even parity 99 Atmel 64 AVR microcontroller 95 F Falling edge 85 B FastLED 107 Banana plug 60, Fast-mode 64 Bandwidth 10,26,46,53 FFT 27 Baud rate 100,105 FIFO 45 Baud rate mismatch 105 Flying lead 59 BitBang 118 Frame rate 108 Bit pattern 21,48 Full duplex 99 BME280 69 Future proofing 18,46, BMP280 69,166 Brownout 68 G Bubble stream 75,127 GitHub 118 Buffer-Mode 32,45 Grabber probes 60 Buffer and Stream mode 46 Ground 22,24,90,140 Bugs 93,113 Ground loop 139 Bus Pirate 166 Bus termination 74 H HD44780 118 C High speed mode 64 Channel 9,15,18,24 Hold time 42 Circuit Pyrate 118 Clock 16,30,41,43,67,84 I Clock phase 84 I2C 67,79 Clock polarity 84 Idle state 104 CMOS logic 35 Complex triggering 47 J Jitter 27 D JTAG 118 Data transfer rate 43,67,82,90 Jumper 86,136 Digital input 33,40

● 167

Logic Analyzers in Practice - UK.indd 167

23-01-2024 16:16


Logic Analyzers in Practice

K Kingst L Level shifter Logic level Low voltage logic Logic probe Logic scope LSB M MIDI MISO MSO MSPS Multi-Domain debugging Multimaster

25,26,51

98 10,25,33,35,73,84 24,33,166 17 17 75,99,122

118 83 27,52,63 30 52 65,95

N NeoPixel Nyquist-Shannon

107 31

O Odd parity Oversampling Over-voltage protection

99 31 49

P PCBite Philips PicoScope Pico technology Pin header strip Pinout Plausibility Pogo pins Positive Logic Potential difference Probe impedance Probe loading Push button Pulseview Python PWM output

58 64 60 27 59 88 73 58,94,137 39,104 24 11,141 140 151 15,61,95 163 50,

Q Quantify

40

R Radix RB-RGLED01 Real-Time eye Reflections Rising edge RGB LED Ring buffer RLE RS232

105 109 27,28 21,141 85 107,115 45,83 43 166

S Sample rate Selection criteria Setup time Shielded cable Sigrok Simple triggering SISO Slew rate SMD SPI bus ST7735 Standard mode Start condition State analysis State capture Stop condition Stream mode System under test

111 50 42 50 14,16,61 47 83 24 57 67,82,85 86,97 64 66 41 41 67,79 32,45 25

T Target system Thonny Timing analysis Transmission line

22,36,42,60,91 147 42 141

U Undersampling Uno USB2.0 USB3.0

31 157 46 46

● 168

Logic Analyzers in Practice - UK.indd 168

23-01-2024 16:16


Index

V Video W Weather station WKS sample theorem WS2811 WS2812B WX28xx protocol

9

68,71,125 115 115 51

● 169

Logic Analyzers in Practice - UK.indd 169

23-01-2024 16:16


books books

books books

Logic Analyzers in Practice

Logic Analyzers in Practice Step-by-step instructions guide you through the analysis of modern protocols such as I2C, SPI, UART, RS-232, NeoPixel, WS28xx, HD44780 and 1-Wire protocols. With the help of numerous experimental circuits based on the Raspberry Pi Pico, Arduino Uno and the Bus Pirate, you will learn the practical application of popular USB logic analyzers. All the experimental circuits presented in this book have been fully tested and are fully functional. The necessary program listings are included — no special programming or electronics knowledge is required for these circuits. The programming languages used are MicroPython and C along with the development environments Thonny and Arduino IDE. This book uses several models of flexible and widely available USB logic analyzers and shows the strengths and weaknesses of each price range.

“I am an electronics technician and work intensively with electronics in my professional environment as well as privately, dealing with analog and digital robots, computers, amateur radio, circuit design and circuit board layouts, microcontrollers... Did a lot of soldering and troubleshooting and faultfinding, repaired many things conducting electricity, and often failed. But I have always enjoyed recording my experiences and passing on my knowledge.” Jörg Rippel

You will learn about the criteria that matter for your work and be able to find the right device for you. Whether Arduino, Raspberry Pi or Raspberry Pi Pico, the example circuits shown allow you to get started quickly with protocol analysis and can also serve as a basis for your own experiments.

Logic Analyzers in Practice • Jörg Rippel

PC USB Logic Analyzers with Arduino, Raspberry Pi, and Co.

PC USB Logic Analyzers with Arduino, Raspberry Pi, and Co.

After reading this book, you will be familiar with all the important terms and contexts, conduct your own experiments, analyze protocols independently, culminating in a comprehensive knowledge set of digital signals and protocols. Elektor International Media www.elektor.com

Jörg Rippel

SKU20780_COV_Logic Analyzers in Practice.indd All Pages

24/01/2024 14:49


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.