User Tools

Site Tools


kicad:using_arbitrary_spice_engines_in_kicad_5

This is an old revision of the document!


Using Arbitrary SPICE Engines in KiCad 5

Simulation support in KiCad 5 has been significantly reworked to make it a better simulation platform. One casualty of this is that the OldWays no longer work1). In particular, when KiCad generates *cir files, it no longer prepends -PSPICE/-GNUCAP nor appends +PSPICE/+GNUCAP text blocks found on your schematic to the file. But it does add a .title directive to the file that my simulator doesn't understand and chokes on.

I have a lot of simulations I built under KiCad 4. So I hacked together a bash script that makes it relatively easy to convert KiCad 4 simulations to something that works in KiCad 5. I'm dumping the source code here for now but will probably be moving it to Git[lab|hub] soon.

#! /bin/bash
 
# (C) 2018 Mithat Konar https://mithatkonar.com
 
# A scheme to use arbitrary SPICE simulators in Kicad 5.
#
# Usage:
# * Put all the stuff to be prepended (e.g., -PSPICE stuff) in pre.cir.
# * Put all the stuff to be appended (e.g., +PSPICE stuff) in post.cir.
# * In this script:
#       * Set CIRCUITNAME to point to the .cir file KiCad 5 generates.
#       * Set SPICE_ENGINE to your desired SPICE engine. (You'll need to
#         hack the line where it's invoked to add command line
#         parameters or if it's weird.)
# * In the KiCad Netlist dialog SPICE tab, set the simulator to this file using an absolute path.
# * In KiCad, Run Simulator
 
### --- config ------------------------------------------------------- #
# The name of the cir file to simulate with (w/o extension):
CIRCUITNAME=opa-x5-spice
 
# The command for the SPICE engine you want to use:
SPICE_ENGINE=spiceopus
# -------------------------------------------------------------------- #
 
### constants
CIRCUITFILE=${CIRCUITNAME}.cir
CIRCUITFILE_CLEANED=${CIRCUITNAME}-cleaned.cir
GENERATED_CIR=${CIRCUITNAME}-complete.cir
 
### Go!
# set the script's directory as the working directory
cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 
# remove all lines starting with .title from CIRCUITFILE
sed '/^.title/d' $CIRCUITFILE > $CIRCUITFILE_CLEANED
 
# concatenate the final file
cat pre.cir > $GENERATED_CIR
cat $CIRCUITFILE_CLEANED >> $GENERATED_CIR
cat post.cir >> $GENERATED_CIR
 
# run it
$SPICE_ENGINE $GENERATED_CIR
 
# cleanup
#~ rm $GENERATED_CIR
rm $CIRCUITFILE_CLEANED
1)
At least not on my Debian sid system
kicad/using_arbitrary_spice_engines_in_kicad_5.1536502966.txt.gz · Last modified: 2018/09/09 14:22 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki