Corr - david-macmahon/wiki_convert_test GitHub Wiki

Corr is a Python library for interacting with CASPER packetized correlators. It can also be used as a general-purpose control framework for ROACH-based CASPER instruments.

Dependencies

You need Python 2.5 or later.

  • In Debian, you should be all set.
  • In RHEL5, you need to install a newer version, as described here.

You'll also need easy_install to get packages from PyPI.

  • In Debian, apt-get install python-setuptools.
  • In RHEL5, yum install python26-distribute from epel.

Some libraries also need access to Python headers.

  • In Debian, apt-get install python-dev.
  • In RHEL5, yum install python26-devel from epel.

For basic Corr functionality (ie, just board control), you need the following libraries:

For full Corr functionality, you'll need the following additional libraries:

  • AIPy - Astronomical Interferometry in Python
  • PyEphem - Scientific-grade astronomy routines

Installation

For almost all of the dependencies, you can just download/unpack the library and run:

$ python setup.py install

Under RHEL5, you'll want to use python2.6 instead python.

NumPy

In Debian: Install the latest version of NumPy from the Debian repository.

$ apt-get install python-numpy

In RHEL5: You can easy_install-2.6 numpy, but you will not get the latest version. This is a problem if you plan to use other python packages (eg, matplotlib). We strongly recommend that you download the source from NumPy and install it with setup.py as described above.

Usage

Basic ROACH board interaction

To interact with a board, just instantiate an FpgaClient object.

from corr import katcp_wrapper
myroach = katcp_wrapper.FpgaClient('HOSTNAME', 7147)

You can interact with the board by calling FpgaClient methods on myroach. Since iPython supports tab-completion, you can type myroach. and hit Tab twice to get a list of available methods.

To see what .bof files are available on a given ROACH:

myroach.listbof()

To run one of the listed .bof files, you can program the FPGA:

myroach.progdev('BOF_FILENAME')

Once something is running on the FPGA, you can see what registers are available:

myroach.listdev()

To write to two registers called control and my_other_register and then read out a signed integer called status_signed and an unsigned integer called status_unsigned:

myroach.write_int('control',23)
myroach.write_int('my_other_register',0x56)
x = myroach.read_int('status_signed')
y = myroach.read_uint('status_unsigned')

To read out a BRAM called data and filled with 1024 32-bit unsigned big-endian (ROACH's PPC is big-endian) values:

import struct
x = myroach.read('data', 4096)
y = struct.unpack('>1024I', x)

That should be enough to get started. For information about any unfamiliar tab-completed command, use the built-in python help system:

help roach.read_dram

ADC controls

The ADC interfaces are still pretty crude and have not been thoroughly tested (in some cases not yet tested at all). YMMV. The iADC and KATADCs have slightly different interfaces. In both cases, registers on the ADCs are write only so you can't confirm that your commands have been successfully applied by reading them back.

iADC example Consider the case where we'd like to switch the ADC in Zdok slot 0 into interleaved mode, sampling input "I" with an 800MHz sampling clock and rerun the built-in self-calibration. Then we'd like to adjust the built-in analogue gain to +1dB on one input and -1dB on the other.

corr.iadc.set_mode(myroach,mode='SPI')
corr.iadc.configure(myroach,0,mode='inter_I',cal='new')
corr.iadc.analogue_gain_adj(myroach, 0, gain_I=1, gain_Q=-1)

KATADC example In addition to the IIC-controlled analogue frontend, the KATADC includes an onboard EEPROM which stores serial number, chip ID, front-end ID and calibration data. AFAIK, these are shipped blank from Digicom. There are also onboard temperature sensors (ambient and on-die) which can be queried using this library.

corr.katadc.set_interleaved(myroach,0, 'I')
corr.katadc.get_ambient_temp(myroach,0)
corr.katadc.eeprom_details_get(myroach,0)