[eispice] Re: eispice and semi-conductors models

  • From: Charles Eidsness <charles@xxxxxxxxxxxxxxxxxxxxx>
  • To: eispice@xxxxxxxxxxxxx
  • Date: Mon, 19 Mar 2007 21:30:44 -0400

Hi Cyril,

It's good to hear from you again, and I'm happy to see that you're still 
interested in eispice. I've tried to answer all of your questions below, 
if I've missed any please let me know.
> Firstly, I thought about building a wrapper around gnucap, but by lack 
> of time, I haven't been very far in that way.
> Al Davis would like such a wrapper, It's still in my plans...
I thought I should add a little disclaimer here, gnucap is a much more 
mature simulator than eispice, and contains a lot of cool features like 
ADMS modelling and fancy FET models that eispice will probably never 
have. I don't want to discourage you from using eispice, I'd love to see 
someone else get some use out of it (and maybe even contribute to it) 
and based on your examples below I don't see any reason why eispice 
can't be made to do what you want it to but I thought I should mention 
that if you're looking for something that's mature and stable gnucap may 
be a better choice.
> Can the PyB model handle all components, particularly with more than 2 
> branches ?
A PyB model can have any number of currents and voltages as its 
dependent sources but can control the current between or the voltage 
across only two nodes. My intent was that if someone wanted to control 
more than 2 nodes they can use more than one PyB model in a subckt, but 
if for some reason that doesn't work out I can add additional PyB models 
with more nodes, i.e. a PyB4. In fact my intent was to use multiple PyB 
models, caps, inductors, etc... in a subckt to create new models, not 
just PyB models alone.
> Can you explain me the way to create a PyB element for a JFET 
> transistor for instance ?
Sure, Jon's model from a couple of moths ago is a good example. You can 
find the entire example in the test/pass folder of the source 
distribution. The file is called py_fets.py.

The model is below, it defines a new class called PMOS that inherits 
from the PyB base class. You can pass whatever variables you want to the 
local __init__ function. The local __init__ calls the PyB base class' 
__init__ which expects the name of two nodes (the plus node and minus 
node), the keyword Current or Voltage which defines it as a current or 
voltage source and a bunch (can be any length) of node voltages, device 
currents, or 'Time' that you want to use as dependent variables. In this 
case the PMOS model controls the current across the drain and source, it 
uses the gate and source voltages as dependent variables and also stores 
some other constants like Vt, etc...

For each time step the simulator (C code) calls the Python based model 
function that's part of the PMOS class. It passes whatever variables 
were asked for, in the same order and expects as a return the value you 
want to set the Current or Voltage to. The simulator also requires the 
derivative of the function wrt each of the dependent variables. They are 
calculated n the background. The variables that are passed to the model 
function are instances of the Variable class (can be found in the 
calc.py file in the src directory) which has overloaded operators so 
that the derivatives are calculated at the same time as the function. 
The intent is for the derivative layer to be seamless and invisible but 
I thought I would mention it in case you find some bugs in it if you try 
to write your own models.

class PMOS(dev.PyB):

   def __init__(self, d, g, s, k=2.0e-6, w=2, l=1, power=2.0):

       dev.PyB.__init__(self, d, s, Current, v(g), v(s))

       self.Vt = 0.7

       self.beta = k * (w/l)

       self.power = power
   def model(self, Vg, Vs):

       if ((Vs - Vg) > self.Vt):

           return -0.5* self.beta * (Vs - Vg - self.Vt)**self.power

       else :

           return 0.0

> How do you mix python and C ?
I wrote my own C/Python interface for eispice, it's called 
simulatormodule.c and can be found in the src directory of the source tree.
> Could Pyrex be a mix method (instead of the C language) to add PyB 
> models in order to gain time ?
Maybe, but I'm not too familiar with Pyrex. My intent for the 
semi-conductor models was to write them using PyB/Subckt and once they 
are working convert them to C. The C models aren't that complicated, a 
big chunk of them are just over-head which can be cut / pasted from 
other similar models. For examples you can look in the 
clibs/simulator/devices directory of the source tree. If you develop 
some models using the PyB/Subckt model I can walk you through converting 
them to C models (or convert them for you if they're not too complicated).
> Does the list of features you would to add in the next releases sort 
> the features by priority ?
The top item (improved T-Line model) is my top priority, everything else 
is pretty much equal.
> What are your plans about the C based implementation of semi conductors ?
I don't have as much time to work on eispice as I had last year, and my 
top priority is the W-Element model but if someone had some working PyB 
based models as a reference I could turn them into C Models.
> Will it be a hard task ?
Yes and no, the diode is pretty straight forward, a BSIM3 FET model is 
crazily complicated. It all depends on the type of model you need. For 
more details on semi-conductor models take a look at the Qucs White 
Paper http://qucs.sourceforge.net/docs/technical.pdf, but if you want 
something that will give you the exact same result as spice try to get a 
copy of "The Spice Book" by Vladimirescu it has descriptions of all of 
the basic semi-conductor models used in spice.
> A lot of questions I see :-)
That's okay, I hope I managed to give you the answers you were looking for.
> I imagine I can help you but I don't know the theory of spice-like 
> simulators (I can learn it)...
> I know python, and C languages.
That's a good start, and if you just want to develop some models you 
shouldn't have to know all the ins and outs of spice. If you want to do 
some googling. Spice simulators use modified nodal analysis to solve 
linearized circuits. They use the Newton-Raphson method to linearize 
non-linear models and trapezoidal or backward Euler methods to perform 
integration for caps and inductors. The Qucs white-paper and the Spice 
Book are good references, and so is "Electronic Circuit & System 
Simulation Methods" by Pillage, Rohrer, and Visweswariah.
> Have you an idea of the time needed to write a model, of the time to 
> get started ?
It depends on the model. The W-Element has taken me a couple of months 
and I'm not finished yet... (it took me a few weeks just to understand 
the original paper it is based on, a mathematician I'm not) but a diode 
shouldn't take more than a day, or maybe even a few hours if you have a 
good reference with all of the equations layed out for you, and assuming 
the eispice simulator doesn't choke on it.
> What kind of help would you like ?
If you're interested in semi-conductor models then writing PyB / Subckt 
versions of those models would be a big help. I'm guessing you'll run 
into bugs / limitations in the eispice code if you try new things, and 
either reporting them, or fixing / expanding eispice would be a big help 
too. Generally I set any new reported bugs as a higher priority than any 
new feature I'm working on so I don't mind helping out fixing them.
> Here is an exemple of a PSPICE circuit netlist :
> Do you see any serious problem which could not allow eispice use ?
No, nothing pops out. But it will take some work to get eispice to 
simulate a circuit like that. I'm willing to help when I can but I'm not 
sure if adding and debugging those models in eispice would be less work 
that adding a Python interface to gnucap (I think that was the 
underlying question in your email). If it helps you could even grab the 
eispice Python/C interface and see if it could be modified to work with 
gnucap. (not that I'm trying to discourage you, I'd be happy to see 
these models added to eispice, but I don't want you to be disappointed 
in the long run)


To unsubscribe from the eispice list send an email to:
eispice-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field

Other related posts: