The Red Pitaya is essentially a two channel fast ADC and DAC connected to a Zynq series FPGA+SoC. The most common model (for which the applications described here are designed) is the STEMlab 125-14, which has 60MHz bandwidth and 14 bit resolution for both input and output.

To utilize the full capabilities of the hardware, it is helpful to make specialized FPGA designs. Presented here are designs I have created that I hope may be useful to others. My designs generally use minimal Vivado TCL scripts to generate connections to the processor and Verilog for functional modules (for details on how to setup and build these projects, see the setup and build instructions). I target the Red Pitaya 2.00 OS release; these projects will not be compatible with earlier versions (in particular, due to how the FPGA image is loaded).

These projects generally consist of a hardware design for the FPGA and a nearly SCPI compatible server that runs on the processor to provide user friendly remote access to the hardware design.

The significant deviation from SCPI compatibility is for binary arrays. For this server, these are encoded as binary with values 0 (\0), 10 (\n), and 92 (\) escaped with backslashes (\). This allows for relatively efficient transmission of arrays without special cases in the server or client (which can continue to assume results occupy a single line).

Red Pitaya Scope AWG

The Red Pitaya Scope AWG design is basic project that accesses CPU RAM from the FPGA. FPGA RAM is limited to <40kB, which limits the length of a signal that can be processed on the FPGA. Even a small 1MB portion of the CPU RAM allows much longer signals to be manipulated. This project implements an oscilloscope and a simple arbitrary waveform generator (not yet available via the server). This design is also intended to test setup and installation procedures, and thus has a number of static registers on the FPGA that are accessible via the server.

SCPI Variables
NameData typeRead onlyDescription
:LEDs:4boolFalseSets LED 4
:LEDs:5boolFalseSets LED 5
:LEDs:6boolFalseSets LED 6
:LEDs:7boolFalseSets LED 7
:DEADbeefuintTrueReturns 0xDEADBEEF
:ABADcafeuintTrueReturns 0xABADCAFE
:BEEFbeefuintTrueReturns 0xBEEFBEEF
:LOOP:INputintFalseSets the value of the loop
:LOOP:OUTputintTrueReads the value of the loop
:SCOPe:Aint16 binary arrayTrueScope channel A trace
:SCOPe:Bint16 binary arrayTrueScope channel B trace
:SCOPe:TRIGgerboolFalseWait for trigger to start scope
:SCOPe:LENgthuintFalseLength of scope trace
:SCOPe:STATusuintTrueScope status register
:SCOPe:CONTrolenumFalseWrite STARt to start scope, STOP to stop scope, RESET to reset scope, or WAIT to wait for recording to complete. ? returns current scope status.
:AWG:Aint16 binary arrayFalseAWG channel A trace
:AWG:Bint16 binary arrayFalseAWG channel B trace
:AWG:TRIGgerboolFalseWait for trigger to start AWG
:AWG:LENgthintFalseLength of AWG trace
:AWG:STATusuintTrueAWG status register
:AWG:CONTrolenumFalseWrite STARt to start AWG, STOP to stop AWG, RESET to reset AWG, or WAIT to wait for output to complete. ? returns current AWG status.

Red Pitaya Vector Network Analyzer

The Red Pitaya Vector Network Analyzer (RPVNA) uses the two DAC channels of the Red Pitaya to produce two sin waves (I and Q) of the same frequency with a 90° (tunable) phase shift between them while measuring the amplitude and phase of the signals at each input at that frequency. The frequency can then be swept. This allows the RPVNA to function as a swept sin vector network analyzer. While the swept sin approach has a slower cycle time than FFT based vector network analyzers, each frequency can be sampled for longer without storing the entire trace. This allows the RPVNA to reach narrow resolution bandwidths.

SCPI Variables
NameData typeRead onlyDescription
:VNA:CONTrolenumFalseSTARt to start VNA, STOP to stop VNA, RESET to reset VNA, or WAIT to wait for recording to complete. ? returns currect VNA status.
:VNA:STARtfreqfloatFalseFrequency to begin sweep at (Hz)
:VNA:STEPfreqfloatFalseFrequency step size (Hz)
:VNA:LENgthuintFalseNumber of steps
:VNA:TIMEfloatFalseTime per step (s)
:VNA:AMPlitudefloatFalseAmplitude (V), -1V to 1V
:VNA:QPHAseoffsetfloatFalsePhase offset for the Q output (output 2) (degrees). This must be set to +/-90 for amplitude and phase measurements to be reasonable.
:VNA:STATusuintTrueVNA status register
:VNA:A:Iint32 binary arrayTrueRaw sum of product of input 1 with I sin wave
:VNA:A:Qint32 binary arrayTrueRaw sum of product of input 1 with Q sin wave
:VNA:A:AMPlitudefloat32 binary arrayTrueAmplitude of input 1 at each sweep frequency, computed as sqrt(I^2 + Q^2)
:VNA:A:PHAsefloat32 binary arrayTruePhase of input 1 at each sweep frequency, computed as arctan2(I, Q)
:VNA:B:Iint32 binary arrayTrueRaw sum of product of input 2 with I sin wave
:VNA:B:Qint32 binary arrayTrueRaw sum of product of input 2 with Q sin wave
:VNA:B:AMPlitudefloat32 binary arrayTrueAmplitude of input 2 at each sweep frequency, computed as sqrt(I^2 + Q^2)
:VNA:B:PHAsefloat32 binary arrayTruePhase of input 2 at each sweep frequency, computed as arctan2(I, Q)

Red Pitaya Amplitude Lockbox

The Red Pitaya Amplitude Lockbox is a PI lockbox optimized for with integrator conditioning for anti-windup and conditioned transfer. Input 1 is used for process variable measurement. Input 2 can be used for an external setpoint. Output 1 is used for the control variable. The scope module from the Red Pitaya Scope AWG design is incorporated to provide a method to monitor the performance of the PI loop.

SCPI Variables
NameData typeRead onlyDescription
:PID:SETpointfloatFalseSetpoint of the PI loop, when setpoint is not set to external (V)
:PID:SETpoint:EXTernalboolFalseTrue to use input 2 for setpoint, false to use :PID:SETpoint for setpoint
:PID:PfloatFalseP Coefficient (a.u.)
:PID:IfloatFalseI Coefficient (a.u.)
:PID:MONitor:INputfloatTrueCurrent input value (V)
:PID:MONitor:ErrorfloatTrueCurrent error value (V)
:PID:MONitor:OUTputfloatTrueCurrent output value (V)
:PID:MONitor:PfloatTrueCurrent P*error result (a.u.)
:PID:MONitor:IfloatTrueCurrent Integral(I*error) result (a.u.)
:PID:CONditioning:MINimumfloatFalseMinimum obtainable control variable (V)
:PID:CONditioning:MAXimumfloatFalseMaximum obtainable control variable (V)
:PID:CONditioning:SLOPe:MINimumfloatFalseMinimum obtainable control variable derivative (V/s)
:PID:CONditioning:SLOPe:MINimumfloatFalseMaximum obtainable control variable derivative (V/s)
:SCOPe:Aint16 binary arrayTrueScope channel A trace
:SCOPe:Bint16 binary arrayTrueScope channel B trace
:SCOPe:TRIGgerboolFalseWait for trigger to start scope
:SCOPe:LENgthuintFalseLength of scope trace
:SCOPe:STATusuintTrueScope status register
:SCOPe:CONTrolenumFalseWrite STARt to start scope, STOP to stop scope, RESET to reset scope, or WAIT to wait for recording to complete. ? returns currect scope status.

Setup and Build

Setup Build Environment

Install a recent version of Vivado from Xilinx.com. "ML Edition" is suitable for these projects.

Building

Launch Vivado. In the TCL shell at the bottom, use cd to change to the hardware_design subdirectory of the cloned project. Then run source [project name].tcl. If there are no bugs, Vivado should begin building the project. The first time, the processor connections and other IP will be generated, causing Vivado to open (and then close) many windows. Subsequent runs will not regenerate these automatically (unless the hardware_design/bd subdirectory is deleted), and will thus be much faster. The FPGA bitsream will be stored in the hardware_design/out subdirectory.

To avoid issues with cross-compiling, the interfacing server is intended to be compiled on the Red Pitaya.

Installing

First, run ./upload.sh [Red Pitaya IP address] in a POSIX terminal (GNU/Linux, BSD, MacOS, or WSL). This script uses ssh and scp to copy the FPGA bitstream, server code, and helper scripts to the Red Pitaya in /root (the root user home directory). The uploaded files will be in a folder named red_pitaya_[abbreviated project name].

Next, open an ssh connection to the Red Pitaya. Use cd to change directory to the folder created by upload.sh. Build the server code by running make (this may take a few minutes). Install the FPGA bitstream by running ./rp_install.sh.

Running

First, open an ssh connection to the Red Pitaya. Use cd to change directory to the folder created by upload.sh. If the FPGA bitstream has been replaced, run ./rp_install.sh again. Start the server by running ./start.sh. If you wish to close the ssh connection, instead run nohup ./start.sh & to start the server in the background.

At this point, the system is ready to use. Open a raw socket connection to the SCPI server using the Red Pitaya IP address and port 5025. The non-standard command close should be used to cleanly disconnect from the SCPI server. The non-standard command shutdown can be used to stop the SCPI server. Note that the FPGA will continue running after the SCPI server is shutdown.