Working with Logic Analyzer in PSLab application

This blog demonstrates the working of Logic Analyzer instrument available in PSLab Desktop Application. It also includes a detailed description of the features available in the Logic Analyzer instrument. Also, it provides a step by step guide on how to work with the Logic Analyzer provided by PSLab which will be beneficial to first-time users. What is a Logic Analyzer? A Logic Analyzer is an electronic instrument used to capture and display digital signals with an added functionality of providing the time difference between different edges of different pulses. It is mainly used to observe the time relationship between different digital signals. An example of a standard Logic Analyzer available in the market is as shown in figure 1. Figure 1. Standard Logic Analyzer How to generate different digital pulses in PSLab? Logic Analyzer needs to be provided with some input of digital pulses among whom time relationship is to be found out. Digital pulses generated from different systems can be directly provided as input to the logic analyzer for analyzing. But PSLab provides a functionality to generate digital pulses up to some constrained frequency. Following are the steps to generate different digital waves in the PSLab desktop application : Go to Advanced Control Section of PSLab app. The screen should look like one as shown in Figure 2. Figure 2.  Advanced Control Section PSLab device provides generation of maximum four digital waves at once. In this example, I will proceed by utilizing all the four pins i.e. SQR1, SQR2, SQR3, SQR4 (where SQR = Acronym of square wave generator and the number next to it is the pin ID available on the PSLab device). Set the duty cycles for each of the pins as desired (try to keep all the duty cycles different from each other to understand the process of measurement easily). After setting it should look something like Figure 3. Figure 3. Configuring PWM NOTE: User can also set phase angle for different waves but I will proceed keeping all without any phase difference. Now set the frequency of the digital waves in the tab provided next to text Frequency and then press the SET button. This should generate desired digital waves when connected. How to analyze the generated waves in Logic Analyzer? Now go to the Experiments section and click on the Logic Analyzer instrument as shown in Figure 4. Figure 4. Test and Measurement Page Now a screen as shown in Figure 5 should open which is the main screen for Logic Analyzer Instrument. Figure 5. Logic Analyzer Main Page On the right, you can see three buttons i.e Start, Plot Data and Raw Data. Below that selection for the number of channels is provided. And at last, the time measurement tool is provided which can measure the time difference between different edges of different digital waves. The graph at the center is the place where all the waves generated will be plotted. Now as we have generated four different waves, we need to navigate to…

Continue ReadingWorking with Logic Analyzer in PSLab application

Markdown Support for Experiment Docs in PSLab Android

The PSLab Android App and the PSLab Desktop App come with built-in experiments which include the experiment setups as well as the experiment docs. The experiment docs for PSLab have been written in the Markdown format. So, the markdown support had to be enabled in the PSLab Android App. There are numerous markdown file renderers for android. The most popular among them is MarkdownView (https://github.com/falnatsheh/MarkdownView) which is an  open-source service. This blog covers how to enable the support for markdown in apps and use to generate elegant documentation. Enabling MarkdownView MarkdownView can be enabled by simply adding a dependency in the build.gradle file compile 'us.feras.mdv:markdownview:1.1.0'   Creating the layout file The layout file for supporting a markdown file is fairly simple. The inclusion of the above dependency simplifies the things. The view holder for markdown is created and an id is assigned to it. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <br.tiagohm.markdownview.MarkdownView android:layout_width="match_parent" app:escapeHtml="false" android:layout_height="match_parent" android:id="@+id/perform_experiment_md" /> </LinearLayout>   Loading the markdown file In order to load the markdown file, a MarkdownView object is created. Since, in the PSLab Android app, markdown files which form the documentation part are a part of the experiments. So, the files are displayed in the documentation fragment of the experiments. private String mdFile; private MarkdownView mMarkdownView; public static ExperimentDocFragment newInstance(String mdFile) { ExperimentDocFragment experimentDocFragment = new ExperimentDocFragment(); experimentDocFragment.mdFile = mdFile; return experimentDocFragment; }   The MarkdownView object created is assigned to markdown viewholder of the relevant layout file. Here, the layout file was named experiment_doc_md and the view holder was assigned the id perform_experiment_md. The markdown files were stored in the assets directory of the app and the files were loaded from the there. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.experiment_doc_md, container, false); mMarkdownView = (MarkdownView) view.findViewById(R.id.perform_experiment_md); mMarkdownView.loadMarkdownFromAsset("capacitance.md"); return view; }   The available methods in markdown view are loadMarkdown - loads directly from the content in the string  mMarkdownView.loadMarkdown("**MarkdownView**");   loadMarkdownFromAsset - loads markdown files located in the assets directory of the app mMarkdownView.loadMarkdownFromAsset("markdown1.md");   loadMarkdownFromFile - loads markdown from a file stored in the app not present in the assets directory mMarkdownView.loadMarkdownFromFile(new File());   loadMarkdownFromUrl - loads markdown from the specified URL (requires internet connection, as file is loaded from the web) mMarkdownView.loadMarkdownFromUrl("url");   Important points for consideration Avoid using elements of GitHub Flavoured Markdown (GFM) as it is not fully supported. It is better to stick to the traditional markdown style. While adding images in the markdown files, avoid using specific dimensions as the images may not load properly in some cases due to the wide variety of screen sizes in android devices. It is better to store the Markdown files to be loaded in the assets directory of the app and load it from there instead of the other methods mentioned above. References A comprehensive markdown tutorial to learn markdown scripting https://www.markdowntutorial.com/ MarkdownView repository on Github by tiagohm https://github.com/tiagohm/MarkdownView Learn more about Github Flavoured Markdown (GFM) https://guides.github.com/features/mastering-markdown/

Continue ReadingMarkdown Support for Experiment Docs in PSLab Android

Performing Custom Experiments with PSLab

PSLab has the capability to perform a variety of experiments. The PSLab Android App and the PSLab Desktop App have built-in support for about 70 experiments. The experiments range from variety of trivial ones which are for school level to complicated ones which are meant for college students. However, it is nearly impossible to support a vast variety of experiments that can be performed using simple electronic circuits. So, the blog intends to show how PSLab can be efficiently used for performing experiments which are otherwise not a part of the built-in experiments of PSLab. PSLab might have some limitations on its hardware, however in almost all types of experiments, it proves to be good enough. Identifying the requirements for experiments The user needs to identify the tools which are necessary for analysing the circuit in a given experiment. Oscilloscope would be essential for most experiments. The voltage & current sources might be useful if the circuit requires DC sources and similarly, the waveform generator would be essential if AC sources are needed. If the circuit involves the use and analysis of data of sensor, the sensor analysis tools might prove to be essential. The circuit diagram of any given experiment gives a good idea of the requirements. In case, if the requirements are not satisfied due to the limitations of PSLab, then the user can try out alternate external features. Using the features of PSLab Using the oscilloscope Oscilloscope can be used to visualise the voltage. The PSLab board has 3 channels marked CH1, CH2 and CH3. When connected to any point in the circuit, the voltages are displayed in the oscilloscope with respect to the corresponding channels. The MIC channel can be if the input is taken from a microphone. It is necessary to connect the GND of the channels to the common ground of the circuit otherwise some unnecessary voltage might be added to the channels. Using the voltage/current source The voltage and current sources on board can be used for requirements within the range of +5V. The sources are named PV1, PV2, PV3 and PCS with V1, V2 and V3 standing for voltage sources and CS for current source. Each of the sources have their own dedicated ranges. While using the sources, keep in mind that the power drawn from the PSLab board should be quite less than the power drawn by the board from the USB bus. USB 3.0 - 4.5W roughly USB 2.0 - 2.5W roughly Micro USB (in phones) - 2W roughly PSLab board draws a current of 140 mA when no other components are connected. So, it is advisable to limit the current drawn to less than 200 mA to ensure the safety of the device. It is better to do a rough calculation of the power requirements in mind before utilising the sources otherwise attempting to draw excess power will damage the device. Using the Waveform Generator The waveform generator in PSLab is limited to 5 - 5000 Hz. This range…

Continue ReadingPerforming Custom Experiments with PSLab

SPI Communication in PSLab

PSLab supports communication using the Serial Peripheral Interface (SPI) protocol. The Desktop App as well as the Android App have the framework set-up to use this feature. SPI protocol is mainly used by a few sensors which can be connected to PSLab. For supporting SPI communication, the PSLab Communication library has a dedicated class defined for SPI. A brief overview of how SPI communication works and its advantages & limitations can be found here. The class dedicated for SPI communication with numerous methods defined in them. The methods required for a particular SPI sensor may differ slightly, however, in general most sensors utilise a certain common set of methods. The set of methods that are commonly used are listed below with their functions. In the setParameters method, the SPI parameters like Clock Polarity (CKP/CPOL), Clock Edge (CKE/CPHA), SPI modes (SMP) and other parameters like primary and secondary prescalar which are specific to the device used. Primary Prescaler (0,1,2,3) for 64MHz clock->(64:1,16:1,4:1,1:1) Secondary prescaler (0,1,..7)->(8:1,7:1,..1:1) The values of CKP/CPOL and CKE/CPHA needs to set using the following convention and according to our requirements. At CPOL=0 the base value of the clock is zero, i.e. the idle state is 0 and active state is 1. For CPHA=0, data is captured on the clock's rising edge (low→high transition) and data is changed at the falling edge (high→low transition). For CPHA=1, data is captured on the clock's falling edge (high→low transition) and data is changed at the rising edge (low→high transition). At CPOL=1 the base value of the clock is one (inversion of CPOL=0), i.e. the idle state is 1 and active state is 0. For CPHA=0, data is captured on the clock's falling edge (high→low transition) and data is changed at the rising edge (low→high transition). For CPHA=1, data is captured on the clock's rising edge (low→high transition) and data is changed at the falling edge (high→low transition). public void setParameters(int primaryPreScalar, int secondaryPreScalar, Integer CKE, Integer CKP, Integer SMP) throws IOException { if (CKE != null) this.CKE = CKE; if (CKP != null) this.CKP = CKP; if (SMP != null) this.SMP = SMP; packetHandler.sendByte(commandsProto.SPI_HEADER); packetHandler.sendByte(commandsProto.SET_SPI_PARAMETERS); packetHandler.sendByte(secondaryPreScalar | (primaryPreScalar << 3) | (this.CKE << 5) | (this.CKP << 6) | (this.SMP << 7)); packetHandler.getAcknowledgement(); }   The start method is responsible for sending the instruction to initiate the SPI communication and it takes the channel which will be used for communication as input. public void start(int channel) throws IOException { packetHandler.sendByte(commandsProto.SPI_HEADER); packetHandler.sendByte(commandsProto.START_SPI); packetHandler.sendByte(channel); }   The setCS method is responsible for selecting the slave with which the SPI communication has to be done. This feature of SPI communication is known as Chip Select (CS) or Slave Select (SS). A master can use multiple Chip/Slave Select pins for communication whereas a slave utilises just one pin as SPI is based on single master multiple slaves principle. The capacity of PSLab is limited to two slave devices at a time. public void setCS(String channel, int state) throws IOException { String[] chipSelect = new String[]{"CS1", "CS2"}; channel =…

Continue ReadingSPI Communication in PSLab