calandigital Package

Requirements: MATLAB/Xilinx/CASPER setup, Tutorials 1, 2, and 3 from Basics finished.

Introduction

Over the years working in different projects we have realize that all the scripts we code to interface with the ROACH are very similar, and many of the functions are rewritten every single time. Even though corr and casperfpga provide the basic functionalities to interface with the ROACH, there are still a lot high level operations we use repeatedly for every project. In an effort to avoid code duplication and speed up ROACH development, we created the calandigital python package. roach_tools has two main objectives:

  • Provide helper functions to quickly perform commonly used task in ROACH (initialize ROACH, simultaneously read data from multiple snapshots and brams, interleave data from brams, etc) that can be used inside a script.

  • Provide some basic scripts to common ROACH tasks/operations that work out of the box (plot snapshots, plot spectra, synchronize ADCs, etc).


Installation

The installation instructions an basic information of the calandigital package can be found in its README file. Please read it carefully and install the package before continuing.

Making a script for a Snapshot model

First let's get a snapshot model, you can use the one you built in Tutorial 2 or you could download it from here. Compile it. Now we'll write a script that get the snapshot data and print it into the console. We need to perform 3 steps: load the package, initialize the ROACH and get the data. The actual script would look something like this:

  • import calandigital as cd

  • roach = cd.initialize_roach(<ROACH_IP>, boffile=<boffile_name>, upload=True)

  • while True:

    • snapdata = cd.read_snapshots(roach, [<snaps block names>])

    • print snapdata

And that's it. Turn on your ROACH and run the script as python <script name>. If you have the calandigital package installed correctly you should see the data from the snapshot being printed out in the terminal. Of course this is not very nice, and probably what you what is an updating plot. You can do that with matplotlib animation package. See this example to adapt your script.

However, if you don't want to write your own script, you are in luck, because plotting snapshots is one of the already available scripts from calandigital. You can simply type:

  • plot_snapshots.py --ip <ROACH_IP> --bof <boffilename> --upload --snapnames <snap block names>

And the script will automatically create the snapshot plots. You can see the implementation of the script here if you are curious and an executable file version of the command here. The resulting plot should be something like this:

Using the plot_spectra.py script

Now let's try to print spectral data using the plot_spectra.py script from calandigital. You can try using your model from Tutorial 3 or you can get an spectrometer model from here. Compile it. Remember that the spectral data get divided into different block RAMs. In order to plot it correctly we need to read the data from the brams and interleave the all the data arrays. You could also want to normalize the data for their accumulation length and convert it into dBFS. These two operations are already implemented in calandigital as the read_interleave_data and scale_and_dBFS_specdata functions respectively.

However, spectral plotting is already implemented as script. The script arguments can be checked in the implementation, and they are:

  • --ip: ROACH IP address

  • --bof: Boffile to load into de FPGA

  • --upload: help="If used, upload .bof from PC memory (ROACH2 only)

  • --bramnames: Names of bram blocks to read

  • --nspecs: Number of independent spectra to plot.

  • --addrwidth: Width of bram address in bits

  • --datawidth: Width of bram data in bits.

  • --bandwidth: Bandwidth of the spectra to plot in MHz.

  • --nbits: Number of bits used to sample the data (ADC bits).

  • --countreg: Counter register name. Reset at initialization.

  • --accreg: Accumulation register name. Set at initialization.

  • --acclen: Accumulation length. Set at initialization.

An example of plot_spectra command in executable file form can be seen here. The resulting plots should look something like this:

Learn more of calandigital package

A list of all calandigital functions and scripts can be found in the README file. To look at help information of the implemented functions, you can do help(cd.<function>) on a python shell. For help information for the scripts you type <script.py> --help on the terminal.

You are welcome to take the code and modified for your own need, is for you to play around and make your life easier in the convoluted world of ROACH programming.