Friday, March 31, 2023

Observing Digital Signals using Logic Analysers

While working with embedded systems, we come across various moments where it is needed to observe a digital signal produced by a device. Some devices produce digital output through their GPIO pins to control various other peripheral devices. Meanwhile, there are sensors that produces digital output that can be read by a microcontroller/SoC. Furthermore, there are communication happening between multiple devices using digital protocols. Being able to observe any such digital signal helps to debug things when they are not functioning as expected. Although the obvious tool for observing signals is oscilloscope, there is a much better hardware device that is purpose-built for observing digital signals: logic analyser. 


A logic analyser has a collection of input puts through which we can input digital signals. The device would read these pins and transfer the identified digital values to an attached computer. A specialised software running on the computer helps to visualise these data against time. Depending on the features of the software, it would be possible to decode a signal and take any usable data out in addition to simple observation of the signal. The Saleae Logic is such a logic analyser product that has multiple variants. I'm using the 8-channel version of the product that can be used to observe 8 digital signals at the same time. The device can be connected to a computer through the USB port. The host computer can run the official software application provided by the manufacturer, called Logic 2, which can be downloaded from their website (https://www.saleae.com/downloads).

Let's explore how we can use Saleae Logic device to observe a signal. For this purpose, we are going to use an Arduino Uno device as the target device being observed. We are going to turn a digital output pin of the Arduino Uno to switch between high and low logic states by programming it to run a small code. So, program the Arduino Uno device to run the following code as the first step. This program is simply switching the pin 13 to HIGH and LOW states with a small time delay in between. Since there is a 1000 milliseconds (1 second) delay in between, we should be able to observe the digital output staying in HIGH and LOW states each 1 second time period.

Once programmed, it is the time to observe the output using logic analyser. Connect the logic analyser to the computer through the USB port and launch the Logic 2 software on the computer. Connect the ground pin of the logic analyser to a ground pin of the Arduino Uno device. Then, let's connect first pin (pin 0) of the logic analyser to the pin 13 of the Arduino Uno. The following figure illustrates this wiring between the logic analyser and Arduino Uno devices. The logic analyser has nice clips that can be attached to jumper wires connected to Arduino Uno's pins. Now, powering up the Arduino Uno device should result in its digital pin 13 going high and low, which will be captured by the logic analyser and fed to the computer. The pin 13 value going high and low should be visible in Logic 2 software window in the specific channel --- channel 0 in this particular case. The following figure illustrates the signal observation on the Logic 2 software. It should be visible that the timing set by program code are very closely achieved by the Arduino Uno device.

















Out of curiosity, I decided to attach the oscilloscope's probe to the ground and pin 13 of the Arduino Uno device to see how the digital signal is visualised on it. The following two figures show how the hardware wiring and the oscilloscope display looked like.



That's all for this blog post. Using logic analyser, let's explore how to intercept and understand digital communication protocols in some future blog posts. 

Monday, March 13, 2023

Troubles, Confusion, and Hope

The paddy fields in Thalpavila.
Last long weekend, I went to Matara to my home town with my wife. We don't get to travel to Matara very often --- just once a month in the best case. This is mostly due to us getting busy over the weekends. The renovation work at home in Matara has been progressing well, although in a slow pace since the last year. It's a pleasure to see the beautiful transformation of our childhood home getting refurbished and modernised. The economic hardships in the country challenged us in various stages of this project due to increase cost of raw material and labour. Although I carry my work with me to Matara hoping that I would be able to do some work there, I didn't do any work at home in the last weekend. It would be unfair to my family if I spend holidays in front of my computer doing works; holidays are holidays after all. It's a safe haven for us to take a break from work and have a breath and good sleep.

In Matara, my younger brother has a bicycle. Every time I go to Matara, I wanted to take it out and ride in the neighborhood. One day a few months back, I went on a ride across the village over a long distance.  In that journey, I managed to go through roads that I had either never traveled or haven't traveled for a long time. In the last weekend, I took the bicycle to go all the way closer to the Kekanadura railway station. Although the expressed objective of this journey was to buy some bread, my real objective was to visit a water stream near Kenanadura railway station. Over 25 years ago, when I was in 6th, 7th, and 8th grades, I used to walk from home to Kekanadura to attend tuition classes in weekends. In evenings, after a class, I would walk with a few neighborhood friends back home, sipping an ice packet — not that drug, but a frozen sweetened beverage in a polythene packaging. Somewhere in between Kekanadura and Thalpavila — near modern-day railway station — there used to be this stream of water. It brought water, what I believe to be from Allakanda Reservoir, to the paddy fields all around that area. As kids, we used to stop by this stream, on our way home, to have a look at various types of fishes. This time after 25 years, my visit in a bicycle to this place revealed that a lot of construction work has happened and the stream is gone. It is sad that urbanisation is taking over the nature.

The lab with new arrangement of equipment.

 In my research, I have been struggling to complete many work I had started since last year. The year 2022 has been mostly occupied with various new administration duties at the university. Due to that, I had less time to make progress in my research, impacting negatively to my profile. This year, I got one paper accepted in MDPI Applied Sciences journal, which was a much needed achievement to start this year 2023. Meanwhile, I'm facing a serious challenge from the ongoing research project funded by Dialog Axiata. The research assistant and the interns assigned to the project were making very little progress in the project, which was very tight in terms of timeline. I was constantly under pressure to move even tiny steps forward in that project's tasks. I think, there is an issue in the way I have been recruiting and managing human resources. This project taught me many lessons on how to manage a project and how to deal with employees. Just throwing people into a project and expecting that they would do a good job on their own is not realistic; as PI, I have to proactively engage and monitor the progress of a project from the beginning.

In a tough time like this, it is necessary to have a proper research team who can help each other and make everybody in company. The lack of such a team is impacting my research negatively. Under such circumstances, I've found a good companion who has the same enthusiasm towards research as myself. Akila was a Master's degree student, whom I supervised for his final project. Since I started supervising his project, we turned into good friends and are in constant contact. He successfully completed his project and submitted his thesis recently. He regularly visits UCSC and do various kinds of experiments whenever he finds something interesting. It is a great pleasure to work with him. Last few days, I got together with him and arranged the lab in a novel way so that we now have a better working environment in the lab. I hope that the support I'm getting from him would help me to keep my enthusiasm high on continuing my research work.