Xyce on a Raspberry Pi: simulate circuit design in Raspbian

By Russell Barnes. Posted

There are many circuit simulators, such as SPICE, TINA or DoCircuits, available for use in designing circuits. However, most of them are either limited-use free versions or academic programs. Xyce is an open-source and fully functional circuit simulator developed by Sandia National Laboratories (supported by the US Department of Energy), that you can compile on a Raspberry Pi.

A quick warning: there are challenges associated with compiling using the limited memory on a Pi, and this project will take about a half day to complete, even on a Raspberry Pi 3.

System preparation for using Xyce on a Raspberry Pi

Start by updating and upgrading your distribution. Xyce does not compile on systems with only 1GB of memory. The minimum recommended is 4GB, so next we must expand the swap file size to accommodate the compilation:

sudo nano /etc/dphys-swapfile

Change the CONF_SWAPSIZE from 100 to 2048 (the maximum possible), save, and exit. Next make the change effective:

sudo dphys-swapfile setup

When you have compiled the code, you can reset the swap file to 100Mb if you like.
Install the required utilities for the compilation:

sudo apt-get install gfortran cmake bison flex libsuitesparse-dev libtool

Install Fourier transform libraries

Next, install the Fortran fast Fourier transform libraries. Use the Chrome browser to do all the downloading. Click here and get the 3.3.6 release via tar.gz – this will put the file in your Downloads folder. Navigate to the Downloads directory in a Terminal window and unzip and extract the file:

cd ~/Downloads
tar xzf fftw-3.3.6-pl2.tar.gz

Now build and install fftw:

cd fftw3-3.3.6-pl2
./configure
make
sudo make install

Install Trilinos libraries

Next, we install the Trilinos libraries, a very powerful set of serial and parallel solvers. Go to trilinos.org and navigate to Download > Previous Releases. In the Pages section on the right-hand side of the screen, find the version 12.6.3 link. You want this version for Xyce 6.7, as later versions aren’t guaranteed to work with Xyce. Trilinos is free, but you will need to sign up to access the files. Download and unzip the Trilinos files:

cd ~/Downloads
tar -xzf trilinos-12.6.3-Source.tar.gz

The last command places the source code in ~/Downloads/trilinos-12.6.3-Source, but we want to do an ‘out of source build’, so create a directory to do this:

cd ~
mkdir Trilinos12.6
cd Trilinos12.6

Xyce only uses some of Trilinos, and there is a suggested reconfigure file on their build page. You can find a modified version at magpi.cc/2vI6loE, called reconfigure. The SRCDIR line assumes you have followed the instructions above. Make sure that reconfigure is executable, run it, and then build the code. The make command will take about an hour and a half to complete.

chmod u+x reconfigure
./reconfigure
make
sudo make install

Build Xyce on a Raspberry Pi

Download Xyce from Sandia National Laboratories. Register for free, and the downloads page will open. Grab the files containing the source code Xyce-6.7.tar.gz, as well as the regression suite XyceRegression-6.7.tar.gz, and the documentation XyceDocs-6.7.tar.gz. These will arrive in your Downloads directory.

cd ~/Downloads
tar xzf Xyce-6.7.tar.gz
cd ~
mkdir Xyce6.7
cd Xyce6.7

The next line places the documentation in the proper Xyce folder:

tar xzf ~/Downloads/Xyce_Docs-6.7.tar.gz

Get the file config from the GitHub directory and make sure it is executable. Then compile and install, which will take an hour or so.

chmod u+x config
./config
make
sudo make install

Next, we test things with the regression suite. Staying in the Xyce-6.7 directory, unpack and execute the regression suite:

tar xzf ~/Downloads/XyceRegression-6.7.tar.gz
cd Xyce
Regression-6.7/TestScripts
./runxyceregression

The regression suite takes a while to execute. A few tests related to calling Xyce as a library will fail, and the huge test problem (RCladder), which uses more memory than the Pi has, will fail, but the vast majority should pass.

A sample problem for Xyce

A favourite test problem is a detailed model of the OP17 operational amplifier. The net list is available in the Xyce GitHub, as OP27.cir. Copy this file to a directory on your Pi, and run Xyce with the command:

Xyce -l op27.log -o op27.prn OP27.cir

The log file is defined by -l, -o defines the output file, and the final argument is the input netlist. This will only take a few seconds to execute. You can inspect the op27.log file to see how things went. LibreOffice Calc can be used to view .prn files, so use it to open op27.prn. Visualise the output by selecting the time and voltages, and creating a graph (x-y line). You can clearly see the inverting nature of this circuit setup.

Start designing your circuits on a Raspberry Pi

Xyce will run most standard netlists for SPICE with just a few minor modifications. The Xyce Reference Guide in the Documentation folder lists the specific changes needed for several popular circuit simulators.

Now you have a state-of-the-art circuit simulator on your Raspberry Pi for your next design project! Note that many manufacturers provide free SPICE models for their components on their websites.

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.