QEP: Qucs schematic simulation with ngspice - Qucs/qucs GitHub Wiki

QEP: Qucs schematic simulation with ngspice

Author: Vadim Kuznetsov
Status: Draft
Created: 23/11/2014

Aims

The purpose of this enhancement is to implement simulation kernel selction feature for Qucs. You can use spice simulation kernel instead of qucsator. It is known that qucsator can simulate not all circuits. It concerns especially time-domain simualtion. With this feature we can use good old spice simulation kernel to simulate various electronic circuits. This feature may be way to overcome issues #34 and #41.

We should use free and open-source spice implementation ngspice http://ngspice.sourceforge.net/. The most of Linux distributions already have ngspice in their repos.

Tasks

  • Implement qucs schematic to spice netlist converter. This converter will be executed from Qucs GUI. Problems: there may be spice-incompatible components and simulations. We can ignore or try to convert them.
  • Implement Ngspice simulation dialog window. This dialog may be similar to Simmessage dialog (simmessage.cpp)
  • Implement ngspice numeric result output postprocessor. We need to convert ngspice output data to qucs XML dataset.

Status

You can see current state of source code at test branch at my fork of qucs: https://github.com/ra3xdh/qucs/tree/spice4qucs.

The following features are implemented now:

  • spice netlist generator. Only RCL-components, AC,DC,pulse sources, and relay are supported. AC and Transient simulations are supported. The list of supported components:
  • resistor
  • inductor
  • capacitor
  • ac source
  • dc source
  • CCVS
  • CCCS
  • VCVS
  • VCCS
  • rectangular pulse source
  • single pulse source
  • relay
  • diode
  • BJT
  • JFET
  • MOSFET
  • Current and voltage probes
  • Rudimental simulation dialog (dialogs/ngspicesimdialog.cpp).
  • Ngspice numeric output postprocessor.

You can discuss this feature at https://github.com/Qucs/qucs/issues/77. Here you can find screenshots of ngspice simulation of RCL circuit in action.

Build instructions

Sources are located on spice4qucs branch of Qucs Github repo here https://github.com/Qucs/qucs/tree/spice4qucs . You need to clone this branch:

git clone https://github.com/Qucs/qucs
cd qucs
git checkout -b spice4qucs origin/spice4qucs

Then you need to rebuild only Qucs-GUI. Qucs-core and qucs-tools are not needed to rebuild. I recommend you to use Linux. MacOS also tested by Xyce developers. You should use CMake build system. Autotools support will be added later. Perform following commands:

cd qucs/qucs
cmake . -B/path_to_build_directory/build_directory
cd /path_to_build_directory/build_directory
make

Or you can open CMakeLists.txt of QucsGUI with QtCreator and build QucsGUI.

Then run Qucs GUI (qucs binary). Use Simulation->Simulate with Spice to execute Ngspice. Ngspice should be in $PATH environment variable. To specify your own path to Ngspice executable edit line 27 of qucs/qucs/exsimkernels/ngspice.cpp . Xyce (serial) simulation kernel is also supported.