Testing your digital circuit using logic analyzer

A logic analyzer is an electronics measuring device that used to measure digital signal such as clock SPI, I2C, and UART. In this tutorial we are going to build two digital circuits and measure their digital signals. In this tutorial we are going to use a cheap logic analyzer from Amazon that can handle frequencies up to 24MHz, Which means that if you have a digital signal with a frequency higher than 24MHz the logic analyzer might not be able to capture the signal. We are going two make two circuits, one circuit based on the famous NE555 timer integrated circuit, and another circuit based on Arduino Nano board.

 Circuit Example 1

In this circuit we are going to build Astable Mutivibrator based on the NE555 timer chip, and measure the output signal using the logic analyzer. This items list below shows the required components to make the project

  1. NE555 timer.
  2. two 10k ohm resistors.
  3. LED any color.
  4. Logic analyzer.
  5. Bread board.
  6. Jumper wires.

Besides the hard component we need a logic analyzer software to view the signals, there are two famous logic analyzer software that's compatible with our logic analyzer device Saleae Logic 2 and Pulse view . If you are in Linux i recommend using Saleae software since it worked for me. In this tutorial we will skip explaining how the 555 timer works, rather we are going to focus on how we can measure the signal using logic analyzer. This diagram below show a schematic of the 555 timer circuit  used in example 1.

 

555 Timer LED Blink Circuit
555 Timer LED Blink Circuit

 

Basically, the circuit will toggle the led on PIN3, the toggling frequency can be calculated by the following formula :

 

555 Timer Frequency Equation

In our circuit R3 is equals to R2 which is equal to 10k ohm, and C is 100uF therefore, the LED toggle frequency should be around 0.5Hz or 500mHzt to calculate the ON/OFF period  we can follow the following equations:

Ton equation

Toff equation

 The Ton the period which the signal stays at high level and the Toff is the period where the signal stays at the low level. Based on the Ton and Toff equations the led should be ON for 1.386 sec and OFF for 0.693 sec. Now lets us build the circuit and verify the calculations. 

 



As we can see from the video the LED is taking more time on the ON state compare with the off state. The ground pin of the logic analyzer connected to the circuit ground and the CH1 pin connected to PIN3 of the 555 timer. No let us check the signal on Saleae Logic 2 software

Timing diagram on time
ON Time


Timing diagram off time
OFF Time



 

From the timing diagram we observe that the signal frequency is 640mHz, the ON time is 1.004 sec and the off time is 0.560 sec.

Circuit Example 2

In this example we are going to use Arduino nano to generate a clock signal, so we can try different frequencies with out modifying the circuit. In this example you need the following:

  1. Arduino (any type) or any microcontroller you familiar with.
  2. Logic analyzer. 
Arduino Nano connected to logic analyzer
Arduino Nano connected to logic analyzer

As we can see from the image above pin5 is connected to CH1 and the ground to the logic analyzer ground. In the first try we are going to toggle pin5 on and off with 500ms delay so we should have a frequency of 1Hz,  Ton should be 500ms and Toff 500ms. here is the Arduino code.

 

Toggling pin5 every 500ms code
Toggling pin5 every 500ms

 

 

 Basically pin5 has been mapped as output in the setup function. Inside the loop function we are reading the value of pin5 if pin5 is high we are going to write low and vise versa if the pin is low we are going to write high, after that there is a delay of 500ms for every toggle, since this loop will never end we should have a periodic signal with 500ms on and 500 ms off.

Timing diagram (2Hz)
Timing diagram (2Hz)


 As expected, the logic analyzer timing diagram shows a signal with a frequency of 1Hz. The duty cycle of the signal is 50% which means that Ton is equals to Toff which is 499.9 ms. Now lets decrease the delay to 10 ms so the frequency will be 50Hz.


Timing diagram (50Hz)
Timing diagram (50Hz)

 

Now we can observe that the frequency is 50Hz and Ton and Toff period is 10ms. So you can keep checking different delay values and check if the logic analyzer can detected the signal correctly. Now let us try a signal with a frequency of 1MHz, so we need a 1 us delay the normal Arduino delay function can only prevent  a minimum delay of 1 millisecond, so we are going to use  the delayMicroseconds() function.

 

Toggling with a delay of 1us Arduino code
Toggling with a delay of 1us


 

Timing diagram (134KHz)
Timing diagram (134KHz)

 

The microsecond delay function should  provide a delay of 1us but as we can see from the timing diagram the delay is 7.45 us, so the frequency is 134KHz.


Circuit Simulation


If you don't have the component to build circuit 1 or 2, or if you don't have the logic analyzer device you can use the Saleae Logic software to simulate a circuit like I2C, SPI .. etc

Saleae Logic Software
Saleae Logic Software

Basically, open the Saleae Logic software and disconnect the logic analyzer if you have one, then press Try a demo Logic device. After that select the device type you can select any demo device, in my case Logic 8. Go to the navigation panel and select analyzer, chose any of the communication protocol you need to simulate, select the correspond virtual channels and press run. You should be able to see a simulated timing diagram of the selected protocol.

Logic 8 demo device
Logic 8 demo device












SPI Simulation with Logic Analyzer
SPI Simulation with Logic Analyzer