2000-04-27 22:03:57 +02:00
|
|
|
/**********
|
|
|
|
|
Copyright 1990 Regents of the University of California. All rights reserved.
|
|
|
|
|
Author: 1985 Thomas L. Quarles
|
2000-09-03 11:00:08 +02:00
|
|
|
Modified: 2000 AlansFixes
|
2005-10-15 15:53:58 +02:00
|
|
|
$Id$
|
2000-04-27 22:03:57 +02:00
|
|
|
**********/
|
|
|
|
|
|
|
|
|
|
#include "ngspice.h"
|
|
|
|
|
#include "cktdefs.h"
|
|
|
|
|
#include "vsrcdefs.h"
|
|
|
|
|
#include "trandefs.h"
|
|
|
|
|
#include "sperror.h"
|
|
|
|
|
#include "suffix.h"
|
|
|
|
|
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE_EXP
|
|
|
|
|
/* gtri - begin - wbk - modify for supply ramping option */
|
|
|
|
|
#include "cmproto.h"
|
|
|
|
|
/* gtri - end - wbk - modify for supply ramping option */
|
|
|
|
|
#endif /* XSPICE_EXP */
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
int
|
2004-01-26 20:51:11 +01:00
|
|
|
VSRCload(GENmodel *inModel, CKTcircuit *ckt)
|
2000-04-27 22:03:57 +02:00
|
|
|
/* actually load the current voltage value into the
|
|
|
|
|
* sparse matrix previously provided
|
|
|
|
|
*/
|
|
|
|
|
{
|
2000-07-11 15:39:04 +02:00
|
|
|
VSRCmodel *model = (VSRCmodel *)inModel;
|
|
|
|
|
VSRCinstance *here;
|
2000-04-27 22:03:57 +02:00
|
|
|
double time;
|
2000-09-03 11:00:08 +02:00
|
|
|
double value;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
/* loop through all the voltage source models */
|
|
|
|
|
for( ; model != NULL; model = model->VSRCnextModel ) {
|
|
|
|
|
|
|
|
|
|
/* loop through all the instances of the model */
|
|
|
|
|
for (here = model->VSRCinstances; here != NULL ;
|
|
|
|
|
here=here->VSRCnextInstance) {
|
|
|
|
|
if (here->VSRCowner != ARCHme) continue;
|
|
|
|
|
|
|
|
|
|
*(here->VSRCposIbrptr) += 1.0 ;
|
|
|
|
|
*(here->VSRCnegIbrptr) -= 1.0 ;
|
|
|
|
|
*(here->VSRCibrPosptr) += 1.0 ;
|
|
|
|
|
*(here->VSRCibrNegptr) -= 1.0 ;
|
|
|
|
|
if( (ckt->CKTmode & (MODEDCOP | MODEDCTRANCURVE)) &&
|
|
|
|
|
here->VSRCdcGiven ) {
|
|
|
|
|
/* grab dc value */
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE_EXP
|
|
|
|
|
value = here->VSRCdcValue;
|
|
|
|
|
#else
|
2000-09-03 11:00:08 +02:00
|
|
|
value = ckt->CKTsrcFact * here->VSRCdcValue;
|
2005-05-10 09:01:47 +02:00
|
|
|
#endif
|
2000-04-27 22:03:57 +02:00
|
|
|
} else {
|
|
|
|
|
if(ckt->CKTmode & (MODEDC)) {
|
|
|
|
|
time = 0;
|
|
|
|
|
} else {
|
|
|
|
|
time = ckt->CKTtime;
|
|
|
|
|
}
|
|
|
|
|
/* use the transient functions */
|
|
|
|
|
switch(here->VSRCfunctionType) {
|
|
|
|
|
default: { /* no function specified: use the DC value */
|
2000-09-03 11:00:08 +02:00
|
|
|
value = here->VSRCdcValue;
|
2000-04-27 22:03:57 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case PULSE: {
|
|
|
|
|
double V1, V2, TD, TR, TF, PW, PER;
|
|
|
|
|
double basetime = 0;
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE
|
|
|
|
|
double PHASE;
|
|
|
|
|
double phase;
|
|
|
|
|
double deltat;
|
|
|
|
|
double basephase;
|
|
|
|
|
#endif
|
2000-04-27 22:03:57 +02:00
|
|
|
V1 = here->VSRCcoeffs[0];
|
|
|
|
|
V2 = here->VSRCcoeffs[1];
|
|
|
|
|
TD = here->VSRCfunctionOrder > 2
|
|
|
|
|
? here->VSRCcoeffs[2] : 0.0;
|
|
|
|
|
TR = here->VSRCfunctionOrder > 3
|
|
|
|
|
&& here->VSRCcoeffs[3] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[3] : ckt->CKTstep;
|
|
|
|
|
TF = here->VSRCfunctionOrder > 4
|
|
|
|
|
&& here->VSRCcoeffs[4] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[4] : ckt->CKTstep;
|
|
|
|
|
PW = here->VSRCfunctionOrder > 5
|
|
|
|
|
&& here->VSRCcoeffs[5] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[5] : ckt->CKTfinalTime;
|
|
|
|
|
PER = here->VSRCfunctionOrder > 6
|
|
|
|
|
&& here->VSRCcoeffs[6] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[6] : ckt->CKTfinalTime;
|
2005-10-15 15:53:58 +02:00
|
|
|
#ifdef XSPICE
|
|
|
|
|
/* gtri - begin - wbk - add PHASE parameter */
|
|
|
|
|
PHASE = here->VSRCfunctionOrder > 7
|
|
|
|
|
? here->VSRCcoeffs[7] : 0.0;
|
|
|
|
|
|
|
|
|
|
/* normalize phase to 0 - 2PI */
|
|
|
|
|
phase = PHASE * M_PI / 180.0;
|
|
|
|
|
basephase = 2 * M_PI * floor(phase / (2 * M_PI));
|
|
|
|
|
phase -= basephase;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2005-10-15 15:53:58 +02:00
|
|
|
/* compute equivalent delta time and add to time */
|
|
|
|
|
deltat = (phase / (2 * M_PI)) * PER;
|
|
|
|
|
time += deltat;
|
|
|
|
|
/* gtri - end - wbk - add PHASE parameter */
|
|
|
|
|
#endif
|
2000-04-27 22:03:57 +02:00
|
|
|
time -= TD;
|
|
|
|
|
if(time > PER) {
|
|
|
|
|
/* repeating signal - figure out where we are */
|
|
|
|
|
/* in period */
|
|
|
|
|
basetime = PER * floor(time/PER);
|
|
|
|
|
time -= basetime;
|
|
|
|
|
}
|
|
|
|
|
if (time <= 0 || time >= TR + PW + TF) {
|
2000-09-03 11:00:08 +02:00
|
|
|
value = V1;
|
2000-04-27 22:03:57 +02:00
|
|
|
} else if (time >= TR && time <= TR + PW) {
|
2000-09-03 11:00:08 +02:00
|
|
|
value = V2;
|
2000-04-27 22:03:57 +02:00
|
|
|
} else if (time > 0 && time < TR) {
|
2000-09-03 11:00:08 +02:00
|
|
|
value = V1 + (V2 - V1) * (time) / TR;
|
2000-04-27 22:03:57 +02:00
|
|
|
} else { /* time > TR + PW && < TR + PW + TF */
|
2000-09-03 11:00:08 +02:00
|
|
|
value = V2 + (V1 - V2) * (time - (TR + PW)) / TF;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SINE: {
|
2005-05-10 09:01:47 +02:00
|
|
|
|
|
|
|
|
double VO, VA, FREQ, TD, THETA;
|
|
|
|
|
/* gtri - begin - wbk - add PHASE parameter */
|
|
|
|
|
#ifdef XSPICE
|
|
|
|
|
double PHASE;
|
|
|
|
|
double phase;
|
|
|
|
|
|
|
|
|
|
PHASE = here->VSRCfunctionOrder > 5
|
|
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
|
|
|
|
|
|
|
|
|
/* compute phase in radians */
|
|
|
|
|
phase = PHASE * M_PI / 180.0;
|
|
|
|
|
#endif
|
|
|
|
|
VO = here->VSRCcoeffs[0];
|
|
|
|
|
VA = here->VSRCcoeffs[1];
|
|
|
|
|
FREQ = here->VSRCfunctionOrder > 2
|
|
|
|
|
&& here->VSRCcoeffs[2] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
|
|
|
|
|
TD = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.0;
|
|
|
|
|
THETA = here->VSRCfunctionOrder > 4
|
|
|
|
|
? here->VSRCcoeffs[4] : 0.0;
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
time -= TD;
|
|
|
|
|
if (time <= 0) {
|
2000-09-03 11:00:08 +02:00
|
|
|
value = VO;
|
2000-04-27 22:03:57 +02:00
|
|
|
} else {
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE
|
|
|
|
|
value = VO + VA * sin(FREQ*time * 2.0 * M_PI + phase) *
|
|
|
|
|
exp(-time*THETA);
|
|
|
|
|
#else
|
2000-09-03 11:00:08 +02:00
|
|
|
value = VO + VA * sin(FREQ * time * 2.0 * M_PI) *
|
2000-04-27 22:03:57 +02:00
|
|
|
exp(-(time*THETA));
|
2005-05-10 09:01:47 +02:00
|
|
|
#endif
|
|
|
|
|
/* gtri - end - wbk - add PHASE parameter */
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EXP: {
|
2005-05-10 09:01:47 +02:00
|
|
|
double V1, V2, TD1, TD2, TAU1, TAU2;
|
|
|
|
|
|
|
|
|
|
V1 = here->VSRCcoeffs[0];
|
|
|
|
|
V2 = here->VSRCcoeffs[1];
|
|
|
|
|
TD1 = here->VSRCfunctionOrder > 2
|
|
|
|
|
&& here->VSRCcoeffs[2] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[2] : ckt->CKTstep;
|
|
|
|
|
TAU1 = here->VSRCfunctionOrder > 3
|
|
|
|
|
&& here->VSRCcoeffs[3] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[3] : ckt->CKTstep;
|
|
|
|
|
TD2 = here->VSRCfunctionOrder > 4
|
|
|
|
|
&& here->VSRCcoeffs[4] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[4] : TD1 + ckt->CKTstep;
|
|
|
|
|
TAU2 = here->VSRCfunctionOrder > 5
|
|
|
|
|
&& here->VSRCcoeffs[5]
|
|
|
|
|
? here->VSRCcoeffs[5] : ckt->CKTstep;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(time <= TD1) {
|
2000-09-03 11:00:08 +02:00
|
|
|
value = V1;
|
2005-05-10 09:01:47 +02:00
|
|
|
} else if (time <= TD2) {
|
|
|
|
|
value = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1));
|
2000-04-27 22:03:57 +02:00
|
|
|
} else {
|
2005-05-10 09:01:47 +02:00
|
|
|
value = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1)) +
|
|
|
|
|
(V1-V2)*(1-exp(-(time-TD2)/TAU2)) ;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SFFM:{
|
2005-05-10 09:01:47 +02:00
|
|
|
|
|
|
|
|
double VO, VA, FC, MDI, FS;
|
|
|
|
|
/* gtri - begin - wbk - add PHASE parameters */
|
|
|
|
|
#ifdef XSPICE
|
|
|
|
|
|
|
|
|
|
double PHASEC, PHASES;
|
|
|
|
|
double phasec;
|
|
|
|
|
double phases;
|
|
|
|
|
|
|
|
|
|
PHASEC = here->VSRCfunctionOrder > 5
|
|
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
|
|
|
|
PHASES = here->VSRCfunctionOrder > 6
|
|
|
|
|
? here->VSRCcoeffs[6] : 0.0;
|
|
|
|
|
|
|
|
|
|
/* compute phases in radians */
|
|
|
|
|
phasec = PHASEC * M_PI / 180.0;
|
|
|
|
|
phases = PHASES * M_PI / 180.0;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
VO = here->VSRCcoeffs[0];
|
|
|
|
|
VA = here->VSRCcoeffs[1];
|
|
|
|
|
FC = here->VSRCfunctionOrder > 2
|
|
|
|
|
&& here->VSRCcoeffs[2]
|
|
|
|
|
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
|
|
|
|
|
MDI = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.0;
|
|
|
|
|
FS = here->VSRCfunctionOrder > 4
|
|
|
|
|
&& here->VSRCcoeffs[4]
|
|
|
|
|
? here->VSRCcoeffs[4] : (1/ckt->CKTfinalTime);
|
|
|
|
|
#ifdef XSPICE
|
|
|
|
|
/* compute waveform value */
|
|
|
|
|
value = VO + VA *
|
|
|
|
|
sin((2 * M_PI * FC * time + phasec) +
|
|
|
|
|
MDI * sin(2.0 * M_PI * FS * time + phases));
|
|
|
|
|
#else /* XSPICE */
|
2000-09-03 11:00:08 +02:00
|
|
|
value = VO + VA *
|
2005-05-10 09:01:47 +02:00
|
|
|
sin((2.0 * M_PI * FC * time) +
|
|
|
|
|
MDI * sin(2 * M_PI * FS * time));
|
|
|
|
|
#endif /* XSPICE */
|
|
|
|
|
/* gtri - end - wbk - add PHASE parameters */
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2005-05-10 09:01:47 +02:00
|
|
|
case AM:{
|
|
|
|
|
|
|
|
|
|
double VA, FC, MF, VO, TD;
|
|
|
|
|
/* gtri - begin - wbk - add PHASE parameters */
|
|
|
|
|
#ifdef XSPICE
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2005-05-10 09:01:47 +02:00
|
|
|
double PHASEC, PHASES;
|
|
|
|
|
double phasec;
|
|
|
|
|
double phases;
|
|
|
|
|
|
|
|
|
|
PHASEC = here->VSRCfunctionOrder > 5
|
|
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
|
|
|
|
PHASES = here->VSRCfunctionOrder > 6
|
|
|
|
|
? here->VSRCcoeffs[6] : 0.0;
|
|
|
|
|
|
|
|
|
|
/* compute phases in radians */
|
|
|
|
|
phasec = PHASEC * M_PI / 180.0;
|
|
|
|
|
phases = PHASES * M_PI / 180.0;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
VA = here->VSRCcoeffs[0];
|
|
|
|
|
VO = here->VSRCcoeffs[1];
|
|
|
|
|
MF = here->VSRCfunctionOrder > 2
|
|
|
|
|
&& here->VSRCcoeffs[2]
|
|
|
|
|
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
|
|
|
|
|
FC = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.0;
|
|
|
|
|
TD = here->VSRCfunctionOrder > 4
|
|
|
|
|
&& here->VSRCcoeffs[4]
|
|
|
|
|
? here->VSRCcoeffs[4] : 0,0;
|
|
|
|
|
|
|
|
|
|
time -= TD;
|
|
|
|
|
if (time <= 0) {
|
|
|
|
|
value = 0;
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef XSPICE
|
|
|
|
|
/* compute waveform value */
|
|
|
|
|
value = VA * (VO + sin(2.0 * M_PI * MF * time + phases )) *
|
|
|
|
|
sin(2 * M_PI * FC * time + phases);
|
|
|
|
|
|
|
|
|
|
#else /* XSPICE */
|
|
|
|
|
value = VA * (VO + sin(2.0 * M_PI * MF * time)) *
|
|
|
|
|
sin(2 * M_PI * FC * time);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* gtri - end - wbk - add PHASE parameters */
|
|
|
|
|
}
|
|
|
|
|
break;
|
2000-04-27 22:03:57 +02:00
|
|
|
case PWL: {
|
2000-07-11 15:39:04 +02:00
|
|
|
int i;
|
2000-04-27 22:03:57 +02:00
|
|
|
double foo;
|
|
|
|
|
if(time < *(here->VSRCcoeffs)) {
|
|
|
|
|
foo = *(here->VSRCcoeffs + 1) ;
|
2000-09-03 11:00:08 +02:00
|
|
|
value = foo;
|
2000-04-27 22:03:57 +02:00
|
|
|
goto loadDone;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) {
|
|
|
|
|
if((*(here->VSRCcoeffs+2*i)==time)) {
|
|
|
|
|
foo = *(here->VSRCcoeffs+2*i+1);
|
2000-09-03 11:00:08 +02:00
|
|
|
value = foo;
|
2000-04-27 22:03:57 +02:00
|
|
|
goto loadDone;
|
|
|
|
|
} else if((*(here->VSRCcoeffs+2*i)<time) &&
|
|
|
|
|
(*(here->VSRCcoeffs+2*(i+1)) >time)) {
|
|
|
|
|
foo = *(here->VSRCcoeffs+2*i+1) +
|
|
|
|
|
(((time-*(here->VSRCcoeffs+2*i))/
|
|
|
|
|
(*(here->VSRCcoeffs+2*(i+1)) -
|
|
|
|
|
*(here->VSRCcoeffs+2*i))) *
|
|
|
|
|
(*(here->VSRCcoeffs+2*i+3) -
|
|
|
|
|
*(here->VSRCcoeffs+2*i+1)));
|
2000-09-03 11:00:08 +02:00
|
|
|
value = foo;
|
2000-04-27 22:03:57 +02:00
|
|
|
goto loadDone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foo = *(here->VSRCcoeffs+ here->VSRCfunctionOrder-1) ;
|
2000-09-03 11:00:08 +02:00
|
|
|
value = foo;
|
2000-04-27 22:03:57 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-03 11:00:08 +02:00
|
|
|
loadDone:
|
2005-05-10 09:01:47 +02:00
|
|
|
/* gtri - begin - wbk - modify for supply ramping option */
|
|
|
|
|
#ifdef XSPICE_EXP
|
|
|
|
|
value *= ckt->CKTsrcFact;
|
|
|
|
|
value *= cm_analog_ramp_factor();
|
|
|
|
|
#else
|
2000-09-03 11:00:08 +02:00
|
|
|
if (ckt->CKTmode & MODETRANOP) value *= ckt->CKTsrcFact;
|
|
|
|
|
*(ckt->CKTrhs + (here->VSRCbranch)) += value;
|
2005-05-10 09:01:47 +02:00
|
|
|
#endif
|
|
|
|
|
/* gtri - end - wbk - modify to process srcFact, etc. for all sources */
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(OK);
|
|
|
|
|
}
|