home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 49.2 KB | 1,714 lines |
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
- From: al@rbc.uucp (Al Davis)
- Newsgroups: alt.sources
- Subject: ACS circuit simulator part 12/20
- Message-ID: <1993Jan27.040747.11522@rbc.uucp>
- Date: 27 Jan 93 04:07:47 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1703
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # src/d_bjt.c
- # src/d_cap.c
- # src/d_coil.c
- # src/d_coment.c
- # src/d_cs.c
- # src/d_diode.c
- # src/d_dot.c
- # This archive created: Tue Jan 26 22:51:02 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/d_bjt.c'
- then
- echo shar: will not over-write existing file "'src/d_bjt.c'"
- else
- cat << \SHAR_EOF > 'src/d_bjt.c'
- /* dev_bjt.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * bjt model.
- * this is not really a bjt, but a diode
- * It exists only as a frame. Don't use it!!!!
- * netlist syntax:
- * device: qxxxx n+ n- mname <area> <off> <ic=vd> <model-card-args>
- * model: .model mname D <args>
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "d_bjt.h"
- #include "d_diode.h"
- #include "error.h"
- #include "mode.h"
- #include "status.h"
- #include "types.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_bjt(const branch_t*);
- static void parse_bjt(branch_t*,const char*,int*);
- static void print_bjt(const branch_t*,int,int);
- static branch_t *create_model_bjt(const branch_t*);
- static void parse_model_bjt(branch_t*,const char*,int*);
- static void print_model_bjt(const branch_t*,int,int);
- static void expand_bjt(branch_t*);
- static double trprobe_bjt(const branch_t*,const char*);
- static int tr_bjt(branch_t*);
- static void ac_bjt(branch_t*);
- static void evalbjt(branch_t*);
- static void bjtcap(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_bjt = {
- sizeof(branch_t),
- create_bjt,
- parse_bjt,
- print_bjt,
- expand_bjt,
- trprobe_bjt,
- (double(*)())NULL,
- tr_bjt,
- (void(*)())NULL,
- ac_bjt,
- (void(*)())NULL,
- (void(*)())NULL,
- (complex_t(*)())NULL,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- functions_t model_bjt = {
- sizeof(branch_t),
- create_model_bjt,
- parse_model_bjt,
- print_model_bjt,
- (void(*)())NULL,
- trprobe_bjt,
- (double(*)())NULL,
- (int(*)())NULL,
- (void(*)())NULL,
- (void(*)())NULL,
- (void(*)())NULL,
- (void(*)())NULL,
- (complex_t(*)())NULL,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- static struct bjt *x;
-
- static struct bjt defalt = {(generic_t*)NULL, sizeof(struct bjt),
- (struct qmod*)NULL, qDEFDEV_modelname, qDEFDEV_is, qDEFDEV_rs,
- qDEFDEV_cj, qDEFDEV_cjsw, qDEFDEV_area, qDEFDEV_perim,
- qDEFDEV_ic, qDEFDEV_off};
- static struct qmod defaltmodel = {(generic_t*)NULL, sizeof(struct qmod),
- qDEFMOD_js, qDEFMOD_rs, qDEFMOD_n, qDEFMOD_tt, qDEFMOD_cj,
- qDEFMOD_pb, qDEFMOD_mj, qDEFMOD_eg, qDEFMOD_xti, qDEFMOD_kf,
- qDEFMOD_af, qDEFMOD_fc, qDEFMOD_bv, qDEFMOD_ibv, qDEFMOD_cjsw,
- qDEFMOD_mjsw, qDEFMOD_fcpb};
- static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
- &model_bjt, &modellist, &modellist, &modellist, &modellist,
- (branch_t*)NULL, (branch_t*)NULL, qDEFMOD_modelname, /* more */};
- /*--------------------------------------------------------------------------*/
- static branch_t *create_bjt(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)&defalt,&dev_bjt);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_bjt(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct bjt *x;
-
- x = (struct bjt*)brh->x;
-
- parselabel(brh,cmd,cnt);
- (void)parsenodes(brh,cmd,cnt,2);
- (void)ctostr(cmd, cnt, x->modelname, LABELEN);
- x->m = (struct qmod*)NULL;
- if (isdigit(cmd[*cnt]) || cmd[*cnt] == '.')
- x->area = fabs(ctof(cmd,cnt));
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "Area", aUDOUBLE, &x->area,
- "Perim",aUDOUBLE, &x->perim,
- "IC", aDOUBLE, &x->ic,
- "OFF", aENUM, &x->off, YES,
- "IS", aUDOUBLE, &x->is,
- "Rs", aUDOUBLE, &x->rs,
- "Cjo", aUDOUBLE, &x->cj,
- "CJSW", aUDOUBLE, &x->cjsw,
- ""))
- ;
- else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_bjt(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct bjt *x;
-
- x = (struct bjt*)brh->x;
-
- (void)printlabel(brh,where);
- printnodes(brh,where);
- mprintf(where, " %s ", x->modelname);
-
- mprintf(where, " %s ", ftos(x->area,"", 7, 0));
- if (x->perim != 0.)
- mprintf(where,"perim=%s ",ftos(x->perim,"", 7, 0));
- if (x->off)
- mprintf(where, " off ");
- if (x->ic != NOT_INPUT)
- mprintf(where, " ic=%s ", ftos(x->ic, "", 7, 0));
- if (!x->calc.is && x->is != NOT_INPUT)
- mprintf(where, " is=%s ", ftos(x->is, "", 7, 0));
- if (!x->calc.rs && x->rs != NOT_INPUT)
- mprintf(where, " rs=%s ", ftos(x->rs, "", 7, 0));
- if (!x->calc.cj && x->cj != NOT_INPUT)
- mprintf(where, " cj=%s ", ftos(x->cj, "", 7, 0));
- if (!x->calc.cjsw && x->cjsw != NOT_INPUT)
- mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
- if (x->calc.is && x->calc.rs && x->calc.cj && x->calc.cjsw)
- mprintf(where, "\n*+");
- if (x->calc.is && x->is != NOT_INPUT)
- mprintf(where, " is=%s ", ftos(x->is, "", 7, 0));
- if (x->calc.rs && x->rs != NOT_INPUT)
- mprintf(where, " rs=%s ", ftos(x->rs, "", 7, 0));
- if (x->calc.cj && x->cj != NOT_INPUT)
- mprintf(where, " cj=%s ", ftos(x->cj, "", 7, 0));
- if (x->calc.cjsw && x->cjsw != NOT_INPUT)
- mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
- mprintf(where, "\n");
- }
- /*--------------------------------------------------------------------------*/
- static branch_t *create_model_bjt(proto)
- const branch_t *proto;
- {
- branch_t *brh;
-
- brh = createbranch(proto,(generic_t*)&defaltmodel,&model_bjt);
- brh->stprev = &modellist;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_model_bjt(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct qmod *m;
-
- m = (struct qmod*)brh->x;
-
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- skiparg(cmd,cnt); /* skip known "d" */
-
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "IS", aUDOUBLE, &m->js,
- "RS", aUDOUBLE, &m->rs,
- "N", aUDOUBLE, &m->n,
- "TT", aUDOUBLE, &m->tt,
- "CJo", aUDOUBLE, &m->cj,
- "VJ", aUDOUBLE, &m->pb,
- "PB", aUDOUBLE, &m->pb,
- "Mj", aUDOUBLE, &m->mj,
- "EGap", aUDOUBLE, &m->eg,
- ""))
- ;
- else if (argparse(cmd,cnt,REPEAT,
- "XTI", aUDOUBLE, &m->xti,
- "KF", aUDOUBLE, &m->kf,
- "AF", aUDOUBLE, &m->af,
- "FC", aUDOUBLE, &m->fc,
- "BV", aUDOUBLE, &m->bv,
- "IBV", aUDOUBLE, &m->ibv,
- "CJSw", aUDOUBLE, &m->cjsw,
- "MJSw", aUDOUBLE, &m->mjsw,
- ""))
- ;
- else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- m->fcpb = m->fc * m->pb;
- if (m->tt != 0.)
- error(bWARNING, "%s: tt not implemented\n", printlabel(brh,NO));
- }
- /*--------------------------------------------------------------------------*/
- static void print_model_bjt(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct qmod *m;
- m = (struct qmod*)brh->x;
-
- mprintf(where, ".model %s d (", brh->label);
- mprintf(where, " is=%s ", ftos(m->js, "", 7, 0));
- mprintf(where, " rs=%s ", ftos(m->rs, "", 7, 0));
- mprintf(where, " n=%s ", ftos(m->n, "", 7, 0));
- mprintf(where, " tt=%s ", ftos(m->tt, "", 7, 0));
- mprintf(where, " cjo=%s ", ftos(m->cj, "", 7, 0));
- mprintf(where, " vj=%s ", ftos(m->pb, "", 7, 0));
- mprintf(where, " m=%s ", ftos(m->mj, "", 7, 0));
- mprintf(where, " eg=%s ", ftos(m->eg, "", 7, 0));
- mprintf(where, " xti=%s ", ftos(m->xti, "", 7, 0));
- mprintf(where, " kf=%s ", ftos(m->kf, "", 7, 0));
- mprintf(where, " af=%s ", ftos(m->af, "", 7, 0));
- mprintf(where, " fc=%s ", ftos(m->fc, "", 7, 0));
- mprintf(where, " bv=%s ", ftos(m->bv, "", 7, 0));
- mprintf(where, " ibv=%s ", ftos(m->ibv, "", 7, 0));
- if (m->cjsw != 0.){
- mprintf(where, " cjsw=%s ", ftos(m->cjsw,"", 7, 0));
- mprintf(where, " mjsw=%s ", ftos(m->mjsw,"", 7, 0));
- }
- mprintf(where, ")\n");
- }
- /*--------------------------------------------------------------------------*/
- static void expand_bjt(brh)
- branch_t *brh;
- {
- const struct qmod *m;
- struct bjt *x;
- branch_t *scratch;
-
- expandgeneric(brh,&modellist);
- x = (struct bjt*)brh->x;
- m = x->m;
-
- if (x->calc.is || x->is == NOT_INPUT){ /* calculate parameters */
- x->is = m->js * x->area;
- x->calc.is = YES;
- }
- if (x->calc.rs || x->rs == NOT_INPUT){
- x->rs = m->rs * x->area;
- x->calc.rs = YES;
- }
- if (x->calc.cj || x->cj == NOT_INPUT){
- x->cj = m->cj * x->area;
- x->calc.cj = YES;
- }
- if (x->calc.cjsw || x->cjsw == NOT_INPUT){
- x->cjsw = m->cjsw * x->perim;
- x->calc.cjsw = YES;
- }
-
- /* build subckt */
- if (x->cj != 0. || x->cjsw != 0.){
- scratch = (*(dev_cap.create))((branch_t*)NULL);
- scratch->parent = brh;
- {functions_t *ff;
- ff = (functions_t*)calloc(1, sizeof(functions_t));
- *ff = *(scratch->f);
- ff->expand = (void(*)())NULL;
- ff->trfun1 = bjtcap;
- ff->acfun = (complex_t(*)())NULL;
- scratch->f = ff;}
- strcpy(scratch->label,"Cj");
- scratch->n[OUT1].t = brh->n[OUT1].t;
- scratch->n[OUT2].t = brh->n[OUT2].t;
- scratch->next = brh->subckt;
- brh->subckt = insertbranch(scratch);
- }
-
- scratch = (*(dev_admittance.create))((branch_t*)NULL);
- scratch->parent = brh;
- {functions_t *ff;
- ff = (functions_t*)calloc(1, sizeof(functions_t));
- *ff = *(scratch->f);
- ff->expand = (void(*)())NULL;
- ff->trfun1 = evalbjt;
- ff->acfun = (complex_t(*)())NULL;
- scratch->f = ff;}
- strcpy(scratch->label,"Yj");
- scratch->n[OUT1].t = brh->n[OUT1].t;
- scratch->n[OUT2].t = brh->n[OUT2].t;
- scratch->next = brh->subckt;
- brh->subckt = insertbranch(scratch);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_bjt(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return NOT_VALID;
- }
- /*--------------------------------------------------------------------------*/
- static int tr_bjt(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- x = (struct bjt*)brh->x;
- if (!x->m)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- return brh->status = tr_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_bjt(brh)
- branch_t *brh;
- {
- x = (struct bjt*)brh->x;
- if (!x->m)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- ac_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void evalbjt(brh)
- branch_t *brh;
- {;}
- /*--------------------------------------------------------------------------*/
- static void bjtcap(brh)
- branch_t *brh;
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_cap.c'
- then
- echo shar: will not over-write existing file "'src/d_cap.c'"
- else
- cat << \SHAR_EOF > 'src/d_cap.c'
- /* dev_cap.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * capacitor models
- * two levels: linear (lin) and nonlinear (nl)
- * y.x = volts, y.f0 = coulombs, ev = y.f1 = farads
- */
- #include "ecah.h"
- #include "ac.h"
- #include "branch.h"
- #include "convstat.h"
- #include "error.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_cap(const branch_t*);
- static void parse_cap(branch_t*,const char*,int*);
- static void print_cap(const branch_t*,int,int);
- static void expand_cap(branch_t*);
- static double trprobe_cap(const branch_t*,const char*);
- static double acprobe_cap(const branch_t*,const char*);
- static int tr_cap_lin(branch_t*);
- static int tr_cap_nl(branch_t*);
- static void un_cap(branch_t*);
- static void integrate(branch_t*);
- static void ac_cap_lin(branch_t*);
- static void ac_cap_nl(branch_t*);
- static double tr_review_cap(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_cap_lin = {
- sizeof(branch_t),
- create_cap,
- parse_cap,
- print_cap,
- expand_cap,
- trprobe_cap,
- acprobe_cap,
- tr_cap_lin,
- un_cap,
- ac_cap_lin,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_cap
- };
- functions_t dev_cap = {
- sizeof(branch_t),
- create_cap,
- parse_cap,
- print_cap,
- expand_cap,
- trprobe_cap,
- acprobe_cap,
- tr_cap_nl,
- un_cap,
- ac_cap_nl,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_cap
- };
- /*--------------------------------------------------------------------------*/
- extern const int stiff; /* flag: use "stiff" integration method */
- extern const double init_curr; /* initial current */
- extern const double init_volt; /* initial voltage */
- extern const double trtime; /* transient analysis time */
- extern const int sim_mode; /* what type simulation is this */
- extern const int sim_phase; /* how far it got */
- extern const ac_t ac;
- extern const struct options opt;
- extern const struct status stats;
- extern const char e_int[];
-
- extern int in_curr; /* flag: initial current */
- extern int in_volt; /* flag: initial voltage */
- /*--------------------------------------------------------------------------*/
- static branch_t *create_cap(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_cap);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_cap(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- brh->f = &dev_cap;
- }
- /*--------------------------------------------------------------------------*/
- static void print_cap(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static void expand_cap(brh)
- branch_t *brh;
- {
- if (!brh->x){
- brh->f = &dev_cap_lin;
- brh->y0.f0 = 0.;
- brh->y0.f1 = brh->ev = brh->val;
- }
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_cap(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_cap(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_cap_lin(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
- integrate(brh);
- trloadpassive(brh);
- return brh->status = cGOOD;
- }
- /*--------------------------------------------------------------------------*/
- static int tr_cap_nl(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- in_volt = in_curr = NO;
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
- brh->y0.x = brh->m0.x;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- brh->ev = brh->y0.f1;
- }
- integrate(brh);
- trloadpassive(brh);
- return brh->status = cGOOD;
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_cap(brh)
- branch_t *brh;
- {
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void integrate(brh)
- branch_t *brh;
- {
- if (sim_mode == sDC || sim_mode == sOP){
- brh->m0.c0 = brh->m0.f1 = 0.;
- }else if (sim_phase == pINIT_DC){
- if (trtime == 0.){
- if (in_curr){
- brh->m0.f1 = 0.;
- brh->m0.c0 = -init_curr;
- }else if (in_volt){
- brh->m0.f1 = 1./opt.shortckt;
- brh->m0.c0 = -init_volt * brh->m0.f1;
- }else{
- brh->m0.c0 = brh->m0.f1 = 0.;
- }
- }else{
- /* leave it alone to restore */
- }
- }else if (brh->dt == 0.){
- error(bERROR, e_int, "time step is 0.\n");
- }else{
- double oldv;
- oldv = tr_volts_t1(brh->n[OUT1],brh->n[OUT2]);
- if (stiff){
- brh->m0.f1 = brh->ev / brh->dt; /* first order */
- brh->m0.c0 = -brh->m0.f1 * oldv; /* (stiff) (backward Euler) */
- }else{
- double oldi; /* second order */
- oldi = brh->mt1.c0 + brh->mt1.f1*oldv; /* (non-stiff) (trapezoid) */
- brh->m0.f1 = 2. * brh->ev / brh->dt;
- brh->m0.c0 = -brh->m0.f1 * oldv - oldi;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void ac_cap_lin(brh)
- branch_t *brh;
- {
- brh->acg.x = 0.;
- brh->acg.y = brh->val * ac.omega;
- acloadpassiveimaginary(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_cap_nl(brh)
- branch_t *brh;
- {
- complex_t y;
-
- if (brh->f->acfun){
- brh->acbias = dc_volts(brh->n[OUT1],brh->n[OUT2]);
- y = (*brh->f->acfun)(brh);
- brh->acg.x = -y.y * ac.omega;
- brh->acg.y = y.x * ac.omega;
- acloadpassive(brh);
- }else{
- brh->acg.x = 0.;
- brh->acg.y = brh->ev * ac.omega;
- acloadpassiveimaginary(brh);
- }
- }
- /*--------------------------------------------------------------------------*/
- static double tr_review_cap(brh)
- branch_t *brh;
- {
- return BIGBIG;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_coil.c'
- then
- echo shar: will not over-write existing file "'src/d_coil.c'"
- else
- cat << \SHAR_EOF > 'src/d_coil.c'
- /* dev_coil.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * inductors
- * two levels: linear (lin) and nonlinear (nl) (not really)
- * x = amps, y.f0 = flux, ev = y.f1 = henrys
- */
- #include "ecah.h"
- #include "ac.h"
- #include "branch.h"
- #include "error.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_coil(const branch_t*);
- static void parse_coil(branch_t*,const char*,int*);
- static void print_coil(const branch_t*,int,int);
- static void expand_coil(branch_t*);
- static double trprobe_coil(const branch_t*,const char*);
- static double acprobe_coil(const branch_t*,const char*);
- static int tr_coil(branch_t*);
- static void un_coil(branch_t*);
- static void integrate(branch_t*);
- static void ac_coil_lin(branch_t*);
- static void ac_coil_nl(branch_t*);
- static double tr_review_coil(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_coil_lin = {
- sizeof(branch_t),
- create_coil,
- parse_coil,
- print_coil,
- expand_coil,
- trprobe_coil,
- acprobe_coil,
- tr_coil,
- un_coil,
- ac_coil_lin,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_coil
- };
- functions_t dev_coil = {
- sizeof(branch_t),
- create_coil,
- parse_coil,
- print_coil,
- expand_coil,
- trprobe_coil,
- acprobe_coil,
- tr_coil,
- un_coil,
- ac_coil_nl,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_coil
- };
- /*--------------------------------------------------------------------------*/
- extern const int stiff; /* flag: use "stiff" integration method */
- extern const double init_curr; /* initial current */
- extern const double init_volt; /* initial voltage */
- extern const double trtime; /* transient analysis time */
- extern const int sim_mode; /* what type simulation is this */
- extern const int sim_phase; /* how far it got */
- extern const ac_t ac;
- extern const struct options opt;
- extern const struct status stats;
-
- extern int in_curr; /* flag: initial current */
- extern int in_volt; /* flag: initial voltage */
- /*--------------------------------------------------------------------------*/
- static branch_t *create_coil(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_coil);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_coil(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- brh->f = &dev_coil;
- }
- /*--------------------------------------------------------------------------*/
- static void print_coil(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static void expand_coil(brh)
- branch_t *brh;
- {
- if (!brh->x){
- brh->f = &dev_coil_lin;
- }
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_coil(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_coil(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_coil(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- in_volt = in_curr = NO;
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
- brh->y0.x = brh->m0.c0 + brh->m0.f1 * brh->m0.x;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- }
- brh->ev = brh->y0.f1;
- if (brh->y0.f1 == 0.){
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- }
-
- integrate(brh);
- trloadpassive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_coil(brh)
- branch_t *brh;
- {
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void integrate(brh)
- branch_t *brh;
- {
- if (sim_mode == sDC || sim_mode == sOP || brh->y0.f1 == 0.){
- brh->m0.f1 = 1./opt.shortckt;
- brh->m0.c0 = 0.;
- }else if (sim_phase == pINIT_DC){
- if (trtime == 0.){
- if (in_curr){
- brh->m0.f1 = 0.;
- brh->m0.c0 = -init_curr;
- }else if (in_volt){
- brh->m0.f1 = 1./opt.shortckt;
- brh->m0.c0 = -init_volt * brh->m0.f1;
- }else{
- brh->m0.f1 = 1./opt.shortckt;
- brh->m0.c0 = 0.;
- }
- }else{
- /* leave it alone to restore */
- }
- }else{
- if (stiff){
- brh->m0.f1 = brh->dt / brh->y0.f1;
- brh->m0.c0 = brh->mt1.c0 + brh->mt1.f1 * brh->mt1.x; /* oldi */
- }else{ /* not stiff */
- /* oldi = brh->mt1.c0 + brh->mt1.f1 * brh->mt1.x; */
- brh->m0.f1 = brh->dt/(2*brh->y0.f1);
- brh->m0.c0 = brh->mt1.c0 + (brh->mt1.f1 + brh->m0.f1) * brh->mt1.x;
- /* oldi + f1*oldv, with combined terms */
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void ac_coil_lin(brh)
- branch_t *brh;
- {
- if (ac.omega == 0.){
- brh->acg.x = 1. / opt.shortckt;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- }else{
- brh->acg.x = 0.;
- brh->acg.y = -1. / (brh->val * ac.omega);
- acloadpassiveimaginary(brh);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void ac_coil_nl(brh)
- branch_t *brh;
- {
- double dcvolts;
- complex_t y;
-
- if (brh->f->acfun){
- dcvolts = dc_volts(brh->n[OUT1],brh->n[OUT2]);
- brh->acbias = brh->m0.c0 + brh->m0.f1*dcvolts;
- y = (*brh->f->acfun)(brh);
- if (ac.omega == 0.){
- brh->acg.x = 1. / opt.shortckt;
- brh->acg.y = 0.;
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- }else{
- y.x *= ac.omega;
- y.y *= ac.omega;
- y = cflip(y);
- brh->acg.x = y.y;
- brh->acg.y = -y.x;
- }
- acloadpassive(brh);
- }else{
- if (ac.omega == 0.){
- brh->acg.x = 1. / opt.shortckt;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- }else{
- brh->acg.x = 0.;
- brh->acg.y = -1. / (brh->ev * ac.omega);
- acloadpassiveimaginary(brh);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static double tr_review_coil(brh)
- branch_t *brh;
- {
- return BIGBIG;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_coment.c'
- then
- echo shar: will not over-write existing file "'src/d_coment.c'"
- else
- cat << \SHAR_EOF > 'src/d_coment.c'
- /* dev_coment.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * processing for COMMENT netlist item (pseudo-device)
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_comment(const branch_t*);
- static void parse_comment(branch_t*,const char*,int*);
- static void print_comment(const branch_t*,int,int);
- /*--------------------------------------------------------------------------*/
- functions_t dev_comment = {
- sizeof(branch_t),
- create_comment,
- parse_comment,
- print_comment,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL, /* acprobe */
- (int(*)())NULL, /* dotr */
- (void(*)())NULL, /* untr */
- (void(*)())NULL, /* doac */
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- static branch_t *create_comment(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_comment);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_comment(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- (*cnt)++;
- if (cmd[*cnt] == '+'){ /* throw away comments starting with "*+" */
- brh->f = (functions_t*)NULL;
- }else{
- int maxlen = sizeof(branch_t) - (&(brh->label[0]) - (char*)brh);
- (void)strncpy(brh->label, &cmd[*cnt], maxlen);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_comment(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- mprintf(where, "*%s\n", brh->label);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_cs.c'
- then
- echo shar: will not over-write existing file "'src/d_cs.c'"
- else
- cat << \SHAR_EOF > 'src/d_cs.c'
- /* dev_cs.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for fixed current source
- * x = 0, y.f0 = nothing, ev = y.f1 = amps.
- */
- #include "ecah.h"
- #include "branch.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_cs(const branch_t*);
- static void parse_cs(branch_t*,const char*,int*);
- static void print_cs(const branch_t*,int,int);
- static double trprobe_cs(const branch_t*,const char*);
- static double acprobe_cs(const branch_t*,const char*);
- static int tr_cs(branch_t*);
- static void un_cs(branch_t*);
- static void ac_cs(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_cs = {
- sizeof(branch_t),
- create_cs,
- parse_cs,
- print_cs,
- (void(*)())NULL, /* expand */
- trprobe_cs,
- acprobe_cs,
- tr_cs,
- un_cs,
- ac_cs,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_cs(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_cs);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_cs(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- }
- /*--------------------------------------------------------------------------*/
- static void print_cs(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_cs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_cs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_cs(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = NOT_VALID; /* anything * 0 = 0 */
- brh->y0.x = 0.;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = 0.;
- }
- brh->ev = brh->y0.f1;
- brh->m0.f1 = 0.;
- brh->m0.c0 = brh->ev;
- trloadsource(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_cs(brh)
- branch_t *brh;
- {
- unloadsource(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_cs(brh)
- branch_t *brh;
- {
- if (brh->f->acfun){
- brh->acbias = 0.;
- brh->acg = (*brh->f->acfun)(brh);
- }else{
- brh->acg.x = brh->ev;
- brh->acg.y = 0.;
- }
- acloadsource(brh);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_diode.c'
- then
- echo shar: will not over-write existing file "'src/d_diode.c'"
- else
- cat << \SHAR_EOF > 'src/d_diode.c'
- /* dev_diod.c 01/05/93
- * Copyright 1983-1992 Albert Davis
- * diode model.
- * netlist syntax:
- * device: dxxxx n+ n- mname <area> <off> <ic=vd> <model-card-args>
- * model: .model mname D <args>
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "convstat.h"
- #include "dev.h"
- #include "d_diode.h"
- #include "error.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "types.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_diode(const branch_t*);
- static void parse_diode(branch_t*,const char*,int*);
- static void print_diode(const branch_t*,int,int);
- static branch_t *create_model_diode(const branch_t*);
- static void parse_model_diode(branch_t*,const char*,int*);
- static void print_model_diode(const branch_t*,int,int);
- static void expand_diode(branch_t*);
- static double trprobe_diode(const branch_t*,const char*);
- static int tr_diode(branch_t*);
- static void un_diode(branch_t*);
- static void ac_diode(branch_t*);
- static void evaldiode0(branch_t*);
- static void evaldiode1(branch_t*);
- static void diodecap0(branch_t*);
- static void diodecap1(branch_t*);
- static double tr_review_diode(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_diode = {
- sizeof(branch_t),
- create_diode,
- parse_diode,
- print_diode,
- expand_diode,
- trprobe_diode,
- (double(*)())NULL,/* acprobe */
- tr_diode,
- un_diode,
- ac_diode,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_diode
- };
- functions_t model_diode = {
- sizeof(branch_t),
- create_model_diode,
- parse_model_diode,
- print_model_diode,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL,/* acprobe */
- (int(*)())NULL, /* dotr */
- (void(*)())NULL, /* untr */
- (void(*)())NULL, /* doac */
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern const struct status stats;
- extern const double temp; /* temperature (ambient) */
- static struct diode *x;
-
- static struct diode defalt = {(generic_t*)NULL, sizeof(struct diode),
- (struct dmod*)NULL, dDEFDEV_modelname, dDEFDEV_is, dDEFDEV_rs,
- dDEFDEV_cj, dDEFDEV_cjsw, dDEFDEV_area, dDEFDEV_perim,
- dDEFDEV_ic, dDEFDEV_off};
- static struct dmod defaltmodel = {(generic_t*)NULL, sizeof(struct dmod),
- dDEFMOD_js, dDEFMOD_rs, dDEFMOD_n, dDEFMOD_tt, dDEFMOD_cj,
- dDEFMOD_pb, dDEFMOD_mj, dDEFMOD_eg, dDEFMOD_xti, dDEFMOD_kf,
- dDEFMOD_af, dDEFMOD_fc, dDEFMOD_bv, dDEFMOD_ibv, dDEFMOD_cjsw,
- dDEFMOD_mjsw, dDEFMOD_fcpb};
- static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
- &model_diode, &modellist, &modellist, &modellist, &modellist,
- (branch_t*)NULL, (branch_t*)NULL, dDEFMOD_modelname, /* more */};
- /*--------------------------------------------------------------------------*/
- static branch_t *create_diode(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)&defalt,&dev_diode);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_diode(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct diode *x;
-
- x = (struct diode*)brh->x;
-
- parselabel(brh,cmd,cnt);
- (void)parsenodes(brh,cmd,cnt,2);
- (void)ctostr(cmd, cnt, x->modelname, LABELEN);
- x->m = (struct dmod*)NULL;
- if (isdigit(cmd[*cnt]) || cmd[*cnt] == '.')
- x->area = fabs(ctof(cmd,cnt));
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "Area", aUDOUBLE, &x->area,
- "Perim",aUDOUBLE, &x->perim,
- "IC", aDOUBLE, &x->ic,
- "OFF", aENUM, &x->off, YES,
- "IS", aUDOUBLE, &x->is,
- "Rs", aUDOUBLE, &x->rs,
- "Cjo", aUDOUBLE, &x->cj,
- "CJSW", aUDOUBLE, &x->cjsw,
- ""))
- ;
- else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_diode(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct diode *x;
-
- x = (struct diode*)brh->x;
-
- (void)printlabel(brh,where);
- printnodes(brh,where);
- mprintf(where, " %s ", x->modelname);
-
- mprintf(where, " %s ", ftos(x->area,"", 7, 0));
- if (x->perim != 0.)
- mprintf(where,"perim=%s ",ftos(x->perim,"", 7, 0));
- if (x->off)
- mprintf(where, " off ");
- if (x->ic != NOT_INPUT)
- mprintf(where, " ic=%s ", ftos(x->ic, "", 7, 0));
- if (!x->calc.is && x->is != NOT_INPUT)
- mprintf(where, " is=%s ", ftos(x->is, "", 7, 0));
- if (!x->calc.rs && x->rs != NOT_INPUT)
- mprintf(where, " rs=%s ", ftos(x->rs, "", 7, 0));
- if (!x->calc.cj && x->cj != NOT_INPUT)
- mprintf(where, " cj=%s ", ftos(x->cj, "", 7, 0));
- if (!x->calc.cjsw && x->cjsw != NOT_INPUT)
- mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
- if (x->calc.is && x->calc.rs && x->calc.cj && x->calc.cjsw)
- mprintf(where, "\n*+");
- if (x->calc.is && x->is != NOT_INPUT)
- mprintf(where, " is=%s ", ftos(x->is, "", 7, 0));
- if (x->calc.rs && x->rs != NOT_INPUT)
- mprintf(where, " rs=%s ", ftos(x->rs, "", 7, 0));
- if (x->calc.cj && x->cj != NOT_INPUT)
- mprintf(where, " cj=%s ", ftos(x->cj, "", 7, 0));
- if (x->calc.cjsw && x->cjsw != NOT_INPUT)
- mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
- mprintf(where, "\n");
- }
- /*--------------------------------------------------------------------------*/
- static branch_t *create_model_diode(proto)
- const branch_t *proto;
- {
- branch_t *brh;
-
- brh = createbranch(proto,(generic_t*)&defaltmodel,&model_diode);
- brh->stprev = &modellist;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_model_diode(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct dmod *m;
-
- m = (struct dmod*)brh->x;
-
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- skiparg(cmd,cnt); /* skip known "d" */
- (void)skiplparen(cmd,cnt);
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "IS", aUDOUBLE, &m->js,
- "RS", aUDOUBLE, &m->rs,
- "N", aUDOUBLE, &m->n,
- "TT", aUDOUBLE, &m->tt,
- "CJo", aUDOUBLE, &m->cj,
- "VJ", aUDOUBLE, &m->pb,
- "PB", aUDOUBLE, &m->pb,
- "Mj", aUDOUBLE, &m->mj,
- "EGap", aUDOUBLE, &m->eg,
- ""))
- ;
- else if (argparse(cmd,cnt,REPEAT,
- "XTI", aUDOUBLE, &m->xti,
- "KF", aUDOUBLE, &m->kf,
- "AF", aUDOUBLE, &m->af,
- "FC", aUDOUBLE, &m->fc,
- "BV", aUDOUBLE, &m->bv,
- "IBV", aUDOUBLE, &m->ibv,
- "CJSw", aUDOUBLE, &m->cjsw,
- "MJSw", aUDOUBLE, &m->mjsw,
- ""))
- ;
- else{
- (void)skiprparen(cmd,cnt);
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- m->fcpb = m->fc * m->pb;
- if (m->tt != 0.)
- error(bWARNING, "%s: tt not implemented\n", printlabel(brh,NO));
- }
- /*--------------------------------------------------------------------------*/
- static void print_model_diode(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct dmod *m;
- m = (struct dmod*)brh->x;
-
- mprintf(where, ".model %s d (", brh->label);
- mprintf(where, " is=%s ", ftos(m->js, "", 7, 0));
- mprintf(where, " rs=%s ", ftos(m->rs, "", 7, 0));
- mprintf(where, " n=%s ", ftos(m->n, "", 7, 0));
- mprintf(where, " tt=%s ", ftos(m->tt, "", 7, 0));
- mprintf(where, " cjo=%s ", ftos(m->cj, "", 7, 0));
- mprintf(where, " vj=%s ", ftos(m->pb, "", 7, 0));
- mprintf(where, " m=%s ", ftos(m->mj, "", 7, 0));
- mprintf(where, " eg=%s ", ftos(m->eg, "", 7, 0));
- mprintf(where, " xti=%s ", ftos(m->xti, "", 7, 0));
- mprintf(where, " kf=%s ", ftos(m->kf, "", 7, 0));
- mprintf(where, " af=%s ", ftos(m->af, "", 7, 0));
- mprintf(where, " fc=%s ", ftos(m->fc, "", 7, 0));
- mprintf(where, " bv=%s ", ftos(m->bv, "", 7, 0));
- mprintf(where, " ibv=%s ", ftos(m->ibv, "", 7, 0));
- if (m->cjsw != 0.){
- mprintf(where, " cjsw=%s ", ftos(m->cjsw,"", 7, 0));
- mprintf(where, " mjsw=%s ", ftos(m->mjsw,"", 7, 0));
- }
- mprintf(where, ")\n");
- }
- /*--------------------------------------------------------------------------*/
- static void expand_diode(brh)
- branch_t *brh;
- {
- const struct dmod *m;
- struct diode *x;
-
- expandgeneric(brh,&modellist);
- x = (struct diode*)brh->x;
- m = x->m;
-
- if (x->calc.is || x->is == NOT_INPUT){ /* calculate parameters */
- x->is = m->js * x->area;
- x->calc.is = YES;
- }
- if (x->calc.rs || x->rs == NOT_INPUT){
- x->rs = m->rs * x->area;
- x->calc.rs = YES;
- }
- if (x->calc.cj || x->cj == NOT_INPUT){
- x->cj = m->cj * x->area;
- x->calc.cj = YES;
- }
- if (x->calc.cjsw || x->cjsw == NOT_INPUT){
- x->cjsw = m->cjsw * x->perim;
- x->calc.cjsw = YES;
- }
-
- /* build subckt */
- if (x->cj != 0. || x->cjsw != 0.){
- if (!x->Cj){
- static functions_t *ff;
- x->Cj = (*(dev_cap.create))((branch_t*)NULL);
- if (!ff){
- ff = (functions_t*)calloc(1, sizeof(functions_t));
- *ff = *(x->Cj->f);
- ff->expand = (void(*)())NULL;
- ff->trfun1 = diodecap1;
- ff->trfun0 = diodecap0;
- ff->acfun = (complex_t(*)())NULL;
- }
- x->Cj->f = ff;
- }
- x->Cj->parent = brh;
- strcpy(x->Cj->label,"Cj");
- x->Cj->n[OUT1] = brh->n[OUT1];
- x->Cj->n[OUT2] = brh->n[OUT2];
- x->Cj->next = brh->subckt;
- x->Cj->prev = (branch_t*)NULL;
- brh->subckt = insertbranch(x->Cj);
- }else{
- x->Cj = (branch_t*)NULL;
- }
-
- if (!x->Yj){
- static functions_t *ff;
- x->Yj = (*(dev_admittance.create))((branch_t*)NULL);
- if (!ff){
- ff = (functions_t*)calloc(1, sizeof(functions_t));
- *ff = *(x->Yj->f);
- ff->expand = (void(*)())NULL;
- ff->trfun1 = evaldiode1;
- ff->trfun0 = evaldiode0;
- ff->acfun = (complex_t(*)())NULL;
- }
- x->Yj->f = ff;
- }
- x->Yj->parent = brh;
- strcpy(x->Yj->label,"Yj");
- x->Yj->n[OUT1] = brh->n[OUT1];
- x->Yj->n[OUT2] = brh->n[OUT2];
- x->Yj->next = brh->subckt;
- x->Yj->prev = (branch_t*)NULL;
- brh->subckt = insertbranch(x->Yj);
- brh->tracesubckt = YES;
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_diode(brh,what)
- const branch_t *brh;
- const char *what;
- {
- struct diode *x;
- double volts;
- int dummy = 0;
-
- x = (struct diode*)brh->x;
- if (!x->m || !brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
-
- volts = tr_volts(brh->n[OUT1],brh->n[OUT2]);
-
- setmatch(what,&dummy);
- if (rematch("V")){
- return volts;
- }else if (rematch("I")){
- return trprobe_branch(x->Yj,"I") + trprobe_branch(x->Cj,"I");
- }else if (rematch("IJ")){
- return trprobe_branch(x->Yj,"I");
- }else if (rematch("IC")){
- return trprobe_branch(x->Cj,"I");
- }else if (rematch("P")){
- return trprobe_branch(x->Yj,"P") + trprobe_branch(x->Cj,"P");
- }else if (rematch("PJ")){
- return trprobe_branch(x->Yj,"P");
- }else if (rematch("PC")){
- return trprobe_branch(x->Cj,"P");
- }else if (rematch("R")){
- return trprobe_branch(x->Yj,"R");
- }else if (rematch("Z")){
- return trz(brh->n[OUT1],brh->n[OUT2],0.);
- }else { /* bad parameter */
- return NOT_VALID;
- }
- }
- /*--------------------------------------------------------------------------*/
- static int tr_diode(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- x = (struct diode*)brh->x;
- if (!x->m || !brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- return brh->status = tr_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void un_diode(brh)
- branch_t *brh;
- {
- tr_unfill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_diode(brh)
- branch_t *brh;
- {
- x = (struct diode*)brh->x;
- if (!x->m || !brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- ac_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void evaldiode0(brh)
- branch_t *brh;
- {
- evaldiode1(brh);
- brh->y0.f1 = brh->y1.f1; /* BUG */
- }
- /*--------------------------------------------------------------------------*/
- static void evaldiode1(brh)
- branch_t *brh;
- {
- #define y (brh->y0)
- double volts;
- double amps;
- double vt;
- double isat;
- double tempratio;
- const struct dmod *m;
-
- m = x->m;
-
- y = brh->y0;
- volts = y.x;
- amps = y.f0;
-
- tempratio = temp / opt.tnom;
- vt = (K/Q) * temp;
- vt *= m->n;
- isat = x->isat = x->is * pow(tempratio, m->xti) * exp((m->eg/vt) * (tempratio-1));
-
-
- if (volts < 0. && amps < 0.){ /* reverse biased */
- double expterm; /* x = volts, f(x) = amps */
- expterm = isat * exp(volts/vt);
- y.f0 = expterm - isat; /* i = f(x) = isat * (exp(volts/vt)-1) */
- y.f1 = expterm / vt; /* f'(x) = (isat/vt) * exp(volts/vt) */
- }else if (volts > 0. && amps > 0.){ /* forward biased */
- /*poly1 r;*/ /* x = amps, f(x) = volts */
- /*r.f0 = vt * log(amps/isat +1.);*/
- /*r.f1 = vt / (isat + amps);*/ /* if f(x) = log(u): f'(x)=(1/u)(du/dx) */
- /*y.f1 = 1. / r.f1;*/
- y.f1 = (isat + amps) / vt;
- /*y.f0 = amps - r.f0*y.f1 + volts*y.f1;*/
- /*y.f0 = amps - log(amps/isat +1.)*(isat + amps) + volts*y.f1;*/
- y.f0 = amps - log1p(amps/isat)*(isat + amps) + volts*y.f1;
- }else{ /* non-converged, inconsistent */
- y.f1 = isat/vt; /* volts and amps have different signs */
- y.f0 = y.x * y.f1; /* guess that the voltage should be 0 */
- /* (it usually is very close) */
- } /* use the correct value there */
- #undef y
- }
- /*--------------------------------------------------------------------------*/
- static void diodecap0(brh)
- branch_t *brh;
- {
- diodecap1(brh);
- brh->y0.f1 = brh->y1.f1; /* BUG */
- }
- /*--------------------------------------------------------------------------*/
- static void diodecap1(brh)
- branch_t *brh;
- {
- double volts;
- double cd;
- const struct dmod *m;
-
- m = x->m;
-
- volts = brh->y0.x;
- if (x->cj != 0.){
- if (volts < m->fcpb){
- cd = x->cj / pow(1. - (volts / m->pb), m->mj);
- }else{
- cd = (x->cj / pow(1. - m->fc, 1. + m->mj))
- * (1. - m->fc*(1.+m->mj) + (volts/m->pb)*m->mj);
- }
- }else{
- cd = 0.;
- }
- if (x->cjsw != 0.){
- if (volts < m->fcpb){
- cd += x->cjsw / pow(1. - (volts / m->pb), m->mjsw);
- }else{
- cd += (x->cjsw / pow(1. - m->fc, 1. + m->mjsw))
- * (1. - m->fc*(1.+m->mjsw) + (volts/m->pb)*m->mjsw);
- }
- }
-
- brh->y0.f1 = cd;
- brh->y0.f0 = brh->y0.x * brh->y0.f1;
- }
- /*--------------------------------------------------------------------------*/
- static double tr_review_diode(brh)
- branch_t *brh;
- {
- return tr_review_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_dot.c'
- then
- echo shar: will not over-write existing file "'src/d_dot.c'"
- else
- cat << \SHAR_EOF > 'src/d_dot.c'
- /* dev_dot.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * processing for DOTCARD netlist item (pseudo-device)
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "dev.h"
- #include "error.h"
- #include "mode.h"
- #include "types.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_dotcard(const branch_t*);
- static void parse_dotcard(branch_t*,const char*,int*);
- static void print_dotcard(const branch_t*,int,int);
- static void parse_dot_generic(branch_t*,const char*);
- static void parse_dot_model(branch_t*,const char*,int*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_dotcard = {
- sizeof(branch_t),
- create_dotcard,
- parse_dotcard,
- print_dotcard,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL, /* acprobe */
- (int(*)())NULL, /* dotr */
- (void(*)())NULL, /* untr */
- (void(*)())NULL, /* doac */
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern int run_mode;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_dotcard(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_dotcard);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_dotcard(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- (*cnt)++;
- setmatch(cmd,cnt);
- if (rematch("MODEL") || rematch("SUBCKT")){
- parse_dot_model(brh,cmd,cnt);
- }else{
- parse_dot_generic(brh,cmd);
- if (run_mode != rIGNORE)
- cmdproc(&cmd[*cnt]);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_dotcard(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- mprintf(where, "%s\n", brh->label);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- static void parse_dot_generic(brh,cmd)
- branch_t *brh;
- const char *cmd;
- {
- int maxlen = sizeof(branch_t) - (&(brh->label[0]) - (char*)brh);
- (void)strncpy(brh->label, cmd, maxlen);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_dot_model(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- branch_t *new;
- volatile int labelcnt;
-
- new = brh;
- labelcnt = *cnt;
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- setmatch(cmd,cnt);
- if (rematch("D" )) new = (*(model_diode.create))((branch_t*)NULL);
- else if (rematch("NPn" )) new = (*(model_bjt.create))((branch_t*)NULL);
- else if (rematch("PNp" )) new = (*(model_bjt.create))((branch_t*)NULL);
- else if (rematch("NJf" )) syntax(cmd,cnt,bWARNING);
- else if (rematch("PJf" )) syntax(cmd,cnt,bWARNING);
- else if (rematch("NMos")) new = (*(model_mos.create))((branch_t*)NULL);
- else if (rematch("PMos")) new = (*(model_mos.create))((branch_t*)NULL);
- else if (rematch("Logic")) new = (*(model_logic.create))((branch_t*)NULL);
- else new = (*(model_subckt.create))((branch_t*)NULL);
- if (new != brh){
- *brh = *new;
- if (new->n == new->nodes)
- brh->n = brh->nodes;
- free((void*)new);
- parse_branch(brh,cmd,&labelcnt);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-