switch loading code


To <ng-spice@ieee.ing.uniroma1.it>
From "Jon Engelbert" <jon@beigebag.com>
Date Mon, 23 Apr 2001 19:17:46 -0400
Delivered-To mailing list ng-spice@ieee.ing.uniroma1.it
Importance Normal
In-Reply-To <Pine.LNX.3.96.1010423205959.24369B-100000@ieee.ing.uniroma1.it >
Mailing-List contact ng-spice-help@ieee.ing.uniroma1.it; run by ezmlm
Reply-To ng-spice@ieee.ing.uniroma1.it

There were a couple of problems with the switch and current switch in
Berkeley Spice.  I'll discuss some of the problems, and I'm including the
changed files.

Negative Hysteresis:
Spice only supports positive hysteresis values for switches.  I.e., the
switch turns on at vt + vh, and then it turns off at vt-vh.  So nothing
changes when the controlling value enters the hysteresis region, only upon
exiting.  However, sometimes we want a negative hysteresis, i.e. turn on and
off when entering the hysteresis region.
I've made changes and added code to implement this option.

Problems with initial state processing:
The switch's DEVLOAD routine (Swload) branches off into different cases
whether it is handling the initial state or not.  For the initial state
processing branch, it sets a temporary variable with the state, but not the
persistent state.
Try this circuit below.  The source starts at the threshold voltage of 5 due
to the delay of -2n, then it goes up to 10, then falls to 0.
The switch should start in the on position and stay on until the source
voltage falls below 4v.  However, with my old spice code, the output
oscillates at the onset of the transient.

VCS_Test.ckt
V1 77  0 DC 12.5
R1 4  0  1K
S1 77  3  33 0 S2_switch on
V2 33  0 DC 5 PULSE( 0 10 -2n 4n 4n 2n 10n)
R2 33  0  1K
VAm1 3  4 0
IVm1 33  0 0
.model S2_switch SW  vt = 5   vh = 1   ron = 1   roff = 1gig
.OPTIONS  gmin = 1E-12  reltol = 1E-4  itl1 = 500  itl4 = 500
.TRAN  1u 10n 0 .5n uic
.IC  V(33)= 5
.END

I've included the changed source files as attachments.  Hopefully someone
can reconcile them with the code in ng-spice.

I'm not sure about some of the code.  I kept the same basic form for the old
Load functions and changed what I knew should be changed.
One thing I'm not sure about is all of the circuit modes.  Specifically,
ckt->CKTmode & (MODEINITFIX|MODEINITJCT) :
ckt->CKTmode & (MODEINITSMSIG)
ckt->CKTmode & (MODEINITFLOAT)
ckt->CKTmode & (MODEINITTRAN|MODEINITPRED)
There's a separate case for each of these within SWload.  What is the
meaning of each of these MODE... constants?

The other thing I don't understand is the need for the following code
snippet:
if(current_state != old_current_state) {
ckt->CKTnoncon++;       /* ensure one more iteration */
ckt->CKTtroubleElt = (GENinstance *) here;
}
I traced the code, and I found that this code is hit at every time point.  I
also found that the routine is called, at minimum, twice per time point.
The condition is true when the state is changing.  I guess it's there to
make sure that the transient routine repeats the time point if the switch
changes state... So I take it back.  It does make sense.

The final error I noticed does not have to do with the switch, but with the
initial point of the transient routine when "UIC" is specified.  I'll
discuss this in a separate email, however, notice that when you run the
simulator on the netlist above, the initial data point of the results is
off.  This is a problem with the transient routine when UIC is specified.

Jon Engelbert
President, Beige Bag Software
279 E. Liberty, Ann Arbor, MI 48105
jon@beigebag.com

-----Original Message-----
From: p.nenzi@ieee.org [mailto:pnenzi@ieee.ing.uniroma1.it]
Sent: Monday, April 23, 2001 3:06 PM
To: ng-spice@ieee.ing.uniroma1.it
Subject: Re: [ng-spice] [ng-spice-devel] Pre3 is out (fwd)


On Mon, 23 Apr 2001, Manu Rouat wrote:

> Robert Lindsell wrote:
> >
> > Hi,
> >
> > A bit of feedback for you.
> >
> > I tried building this on Solaris 2.6 with the following results;
> >
> > gcc -DHAVE_CONFIG_H -I. -I. -I../.. -I../../src/include
> > -I/usr/X11R6.4/include     -g -O2 -Wall  -c terminal.c
> > terminal.c:27: termcap.h: No such file or directory
> >
> > Solaris doesn't use termcap. Commented out this line from terminal.c
> > then continued make...
>
> there is an #IFDEF HAVE_TERMCAP that isn't use dproperly in that file.

Robert,

Take the old terminal.c or readd the #include "term.h" and write:


#ifdef HAVE_TERMCAP
#include <termcap.h>
#endif

#include <ngspice.h>
#include <cpdefs.h>

#include "variable.h"
#ifndef HAVE_TERMCAP
#include "terminal.h"
#endif



or user the #ifdef - #else - #endif syntax.

Can you try this for me ?

Thnaks,
Paolo

CSWLOAD.C

CSWMPAR.C

SWLOAD.C

SWMPARAM.C


Partial thread listing: