PYNQ Edition! Signal Generation and Logic Tracing

One of the great things about PYNQ is it opens several hardware functions and tools such as Boolean, Pattern and FSM Generation and Logic…

Adam Taylor
5 years ago

One of the great things about PYNQ is that it opens several hardware functions and tools, such as Boolean, Pattern and FSM Generation, and logic signal analysis, easily within the Python environment.

This makes it easier for developers familiar with Python to get low-level access directly to the hardware, where they can not only see what is happening directly at the device pins, but also generate necessary stimulus.

To leverage these interfaces, we use the logictools overlay; however, as we will see when we are looking at creating our own overlay, we can integrate these IP blocks into our overlay with ease.

On the PYNQ-Z2, the logictools overlay allows us to connect and work with the following:

  • 4 push button switches
  • 4 LEDs
  • 20 Arduino IO and 22 Raspberry Pi IO

In this blog, we are going to explore how we can work with the Boolean and Pattern Generator, and Logic Tracing.

Let’s start with the simplest the Boolean generation, which enables us to create Boolean functions between the input and output — for example, the push button switches and LEDs.

To use the Boolean generator, we need to download the logictools overlay, and select the Boolean generator.

from pynq.overlays.logictools import LogicToolsOverlay

logictools_olay = LogicToolsOverlay(‘logictools.bit’)

boolean_generator = logictools_olay.boolean_generator

We can then define the function we desire:

function = {‘XOR_gate’: ‘LD2 = PB3 ^ PB0’}

Different logic gates are implemented using the symbols AND = &, XOR = ^, OR = | and NOT = ~. With these, we can create logic equations. The video below shows the Boolean generator implementing a Boolean OR function.

Of course, the real power of the logictools is in its ability to generate patterns and analyze signals. Doing this is really simple and is based around the popular open source Timing Diagram tool WaveDrom. WaveDrom is Java based and lets us draw digital timing diagrams using JSON, in the waveJSON format. In the Pynq environment, we use waveJSON format to not only display the results of the logic analysis but to define the stimulus of the Pattern Generator as well.

This is achieved by extensions to the waveJSON format, which adds in ability for the waveform being defined to be used for stimulus or analysis.

Within out Jupyter notebook, we use the pattern generator and analyzer by loading in the logictools overlay. To be able to work with waveforms, we need to import the following packages:

from pynq.lib.logictools import Waveform

In the code example above, the stimulus section is defined to create a simple binary counter that counts from 0 to 7.

If we want to see what our waveform looks like before we output it, we can view it in our Jupyter note book using the function:

waveform = Waveform(up_counter)

waveform.display()

In order to be able to view the counter with the PYNQ Board, we need to loop back the output signals on to the input signals so we can view them in the analyzer.

To work with the analyzer, we first need to configure the Pattern Generator as below:

pattern_generator = logictools_olay.pattern_generator

pattern_generator.trace(num_analyzer_samples=16)

pattern_generator.setup(up_counter, stimulus_group_name=’stimulus’, analysis_group_name=’analysis’)

This allows us to define the number of samples the analyzer takes, in this case 16 while also setting up the generator. When the generator is setup, we need to define which of our waveJSON components is to be used for stimulus and which is used for analysis.

When we are ready to run the Pattern Generator, we can use the commands:

pattern_generator.run()

pattern_generator.show_waveform()

This will run the Pattern Generator and display the waveform.

The final command stops the Pattern Generator:

pattern_generator.stop()

Both the Pattern Generator and logic analysis are very powerful tools. The Pattern Generator allows us to easily generate waveform to test interfaces, for example. While the logic analysis enables us to analyze signals within a system and determine if they are as expected.

Overall, I think the logictools overlay is one of the hidden gems of the PYNQ framework. Obviously, we can also include these IP blocks in our own overlay.

If you want to know more about PYNQ, check out the new MPSOC & PYNQ book from Xilinx and the University of Strathclyde here.

See My FPGA / SoC Projects: Adam Taylor on Hackster.io

Get the Code: ATaylorCEngFIET (Adam Taylor)

Access the MicroZed Chronicles Archives with over 280 articles on the Zynq / Zynq MpSoC updated weekly at MicroZed Chronicles.

Adam Taylor
Adam Taylor is an expert in design and development of embedded systems and FPGA’s for several end applications (Space, Defense, Automotive)
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles