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
|
2000-04-27 22:03:57 +02:00
|
|
|
**********/
|
|
|
|
|
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/ngspice.h"
|
|
|
|
|
#include "ngspice/cktdefs.h"
|
2000-04-27 22:03:57 +02:00
|
|
|
#include "vsrcdefs.h"
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/trandefs.h"
|
|
|
|
|
#include "ngspice/sperror.h"
|
|
|
|
|
#include "ngspice/suffix.h"
|
|
|
|
|
#include "ngspice/1-f-code.h"
|
2022-11-24 14:46:54 +01:00
|
|
|
#include "ngspice/compatmode.h"
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE_EXP
|
|
|
|
|
/* gtri - begin - wbk - modify for supply ramping option */
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/cmproto.h"
|
2005-05-10 09:01:47 +02:00
|
|
|
/* gtri - end - wbk - modify for supply ramping option */
|
2011-02-27 21:39:03 +01:00
|
|
|
#endif
|
2005-05-10 09:01:47 +02:00
|
|
|
|
2013-07-14 18:45:49 +02:00
|
|
|
#ifdef SHARED_MODULE
|
|
|
|
|
extern double getvsrcval(double, char*);
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
int
|
2004-01-26 20:51:11 +01:00
|
|
|
VSRCload(GENmodel *inModel, CKTcircuit *ckt)
|
2011-02-27 21:39:03 +01:00
|
|
|
/* actually load the current value into the
|
|
|
|
|
* sparse matrix previously provided
|
2000-04-27 22:03:57 +02:00
|
|
|
*/
|
|
|
|
|
{
|
2011-02-27 21:40:48 +01:00
|
|
|
VSRCmodel *model = (VSRCmodel *) inModel;
|
2000-07-11 15:39:04 +02:00
|
|
|
VSRCinstance *here;
|
2000-04-27 22:03:57 +02:00
|
|
|
double time;
|
2010-11-27 17:36:03 +01:00
|
|
|
double value = 0.0;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2011-02-27 21:39:03 +01:00
|
|
|
/* loop through all the source models */
|
2018-02-14 22:04:23 +01:00
|
|
|
for( ; model != NULL; model = VSRCnextModel(model)) {
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
/* loop through all the instances of the model */
|
2018-02-14 22:04:23 +01:00
|
|
|
for (here = VSRCinstances(model); here != NULL ;
|
|
|
|
|
here=VSRCnextInstance(here)) {
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2022-01-08 15:39:47 +01:00
|
|
|
#ifndef RFSPICE
|
2023-05-19 23:28:31 +02:00
|
|
|
*(here->VSRCposIbrPtr) += 1.0;
|
2022-01-08 15:39:47 +01:00
|
|
|
*(here->VSRCnegIbrPtr) -= 1.0;
|
|
|
|
|
*(here->VSRCibrPosPtr) += 1.0;
|
|
|
|
|
*(here->VSRCibrNegPtr) -= 1.0;
|
|
|
|
|
#else
|
|
|
|
|
if (here->VSRCisPort)
|
|
|
|
|
{
|
|
|
|
|
// here->VSRCcurrent = (*(ckt->CKTrhs[Old] + (here->VSRCbranch))
|
|
|
|
|
|
|
|
|
|
*(here->VSRCposIbrPtr) += 1.0;
|
|
|
|
|
*(here->VSRCnegIbrPtr) -= 1.0;
|
|
|
|
|
*(here->VSRCibrPosPtr) += 1.0;
|
|
|
|
|
*(here->VSRCibrNegPtr) -= 1.0;
|
|
|
|
|
|
|
|
|
|
double g0 = here->VSRCportY0;
|
|
|
|
|
*(here->VSRCposPosPtr) += g0;
|
|
|
|
|
*(here->VSRCnegNegPtr) += g0;
|
|
|
|
|
*(here->VSRCposNegPtr) -= g0;
|
|
|
|
|
*(here->VSRCnegPosPtr) -= g0;
|
2022-03-29 09:06:10 +02:00
|
|
|
}
|
2022-01-08 15:39:47 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*(here->VSRCposIbrPtr) += 1.0;
|
|
|
|
|
*(here->VSRCnegIbrPtr) -= 1.0;
|
|
|
|
|
*(here->VSRCibrPosPtr) += 1.0;
|
|
|
|
|
*(here->VSRCibrNegPtr) -= 1.0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
if( (ckt->CKTmode & (MODEDCOP | MODEDCTRANCURVE)) &&
|
|
|
|
|
here->VSRCdcGiven ) {
|
2011-02-27 21:39:03 +01:00
|
|
|
/* load using DC value */
|
2005-05-10 09:01:47 +02:00
|
|
|
#ifdef XSPICE_EXP
|
2011-02-27 21:39:03 +01:00
|
|
|
/* gtri - begin - wbk - modify to process srcFact, etc. for all sources */
|
2005-05-10 09:01:47 +02:00
|
|
|
value = here->VSRCdcValue;
|
|
|
|
|
#else
|
2011-02-27 21:39:03 +01:00
|
|
|
value = here->VSRCdcValue * ckt->CKTsrcFact;
|
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) {
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2011-02-27 21:39:03 +01:00
|
|
|
default:
|
2010-12-18 18:05:44 +01:00
|
|
|
value = here->VSRCdcValue;
|
|
|
|
|
break;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
case PULSE: {
|
2011-01-16 20:19:42 +01:00
|
|
|
double V1, V2, TD, TR, TF, PW, PER;
|
2010-12-18 18:05:44 +01:00
|
|
|
double basetime = 0;
|
|
|
|
|
double PHASE;
|
|
|
|
|
double phase;
|
|
|
|
|
double deltat;
|
2022-11-24 14:46:54 +01:00
|
|
|
double tmax = 1e99;
|
2020-12-07 14:39:52 +01:00
|
|
|
|
2010-12-18 18:05:44 +01: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;
|
2010-11-21 18:16:49 +01:00
|
|
|
|
2011-02-27 21:40:48 +01:00
|
|
|
/* shift time by delay time TD */
|
2010-12-18 18:05:44 +01:00
|
|
|
time -= TD;
|
2010-11-21 18:16:49 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
PHASE = here->VSRCfunctionOrder > 7
|
|
|
|
|
? here->VSRCcoeffs[7] : 0.0;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2022-11-24 14:46:54 +01:00
|
|
|
if (newcompat.xs) { /* 7th parameter is PHASE */
|
|
|
|
|
/* normalize phase to cycles */
|
|
|
|
|
phase = PHASE / 360.0;
|
|
|
|
|
phase = fmod(phase, 1.0);
|
|
|
|
|
deltat = phase * PER;
|
|
|
|
|
while (deltat > 0)
|
|
|
|
|
deltat -= PER;
|
|
|
|
|
/* shift time by pase (neg. for pos. phase value) */
|
|
|
|
|
time += deltat;
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
2022-11-24 14:46:54 +01:00
|
|
|
else if (PHASE > 0.0) { /* 7th parameter is number of pulses */
|
|
|
|
|
tmax = PHASE * PER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!newcompat.xs && time > tmax) {
|
2010-12-18 18:05:44 +01:00
|
|
|
value = V1;
|
2022-11-24 14:46:54 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
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) {
|
|
|
|
|
value = V1;
|
|
|
|
|
}
|
|
|
|
|
else if (time >= TR && time <= TR + PW) {
|
|
|
|
|
value = V2;
|
|
|
|
|
}
|
|
|
|
|
else if (time > 0 && time < TR) {
|
|
|
|
|
value = V1 + (V2 - V1) * (time) / TR;
|
|
|
|
|
}
|
|
|
|
|
else { /* time > TR + PW && < TR + PW + TF */
|
|
|
|
|
value = V2 + (V1 - V2) * (time - (TR + PW)) / TF;
|
|
|
|
|
}
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
case SINE: {
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
double VO, VA, FREQ, TD, THETA;
|
|
|
|
|
double PHASE;
|
|
|
|
|
double phase;
|
2005-05-10 09:01:47 +02:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
PHASE = here->VSRCfunctionOrder > 5
|
|
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
|
|
|
|
/* compute phase in radians */
|
2010-12-18 18:05:44 +01:00
|
|
|
phase = PHASE * M_PI / 180.0;
|
2020-12-07 14:39:52 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
VO = here->VSRCcoeffs[0];
|
|
|
|
|
VA = here->VSRCcoeffs[1];
|
2011-02-27 21:40:48 +01:00
|
|
|
FREQ = here->VSRCfunctionOrder > 2
|
2011-01-16 20:19:42 +01:00
|
|
|
&& here->VSRCcoeffs[2] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
|
|
|
|
|
TD = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.0;
|
2010-12-18 18:05:44 +01:00
|
|
|
THETA = here->VSRCfunctionOrder > 4
|
2011-01-16 20:19:42 +01:00
|
|
|
? here->VSRCcoeffs[4] : 0.0;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
time -= TD;
|
|
|
|
|
if (time <= 0) {
|
|
|
|
|
value = VO + VA * sin(phase);
|
|
|
|
|
} else {
|
2011-02-27 21:40:48 +01:00
|
|
|
value = VO + VA * sin(FREQ*time * 2.0 * M_PI + phase) *
|
|
|
|
|
exp(-time*THETA);
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
2010-12-18 18:05:44 +01:00
|
|
|
break;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
case EXP: {
|
|
|
|
|
double V1, V2, TD1, TD2, TAU1, TAU2;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
V1 = here->VSRCcoeffs[0];
|
|
|
|
|
V2 = here->VSRCcoeffs[1];
|
2011-02-27 21:40:48 +01:00
|
|
|
TD1 = here->VSRCfunctionOrder > 2
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[2] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[2] : ckt->CKTstep;
|
2011-02-27 21:40:48 +01:00
|
|
|
TAU1 = here->VSRCfunctionOrder > 3
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[3] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[3] : ckt->CKTstep;
|
2011-02-27 21:40:48 +01:00
|
|
|
TD2 = here->VSRCfunctionOrder > 4
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[4] != 0.0
|
|
|
|
|
? here->VSRCcoeffs[4] : TD1 + ckt->CKTstep;
|
2011-02-27 21:40:48 +01:00
|
|
|
TAU2 = here->VSRCfunctionOrder > 5
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[5]
|
|
|
|
|
? here->VSRCcoeffs[5] : ckt->CKTstep;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
if(time <= TD1) {
|
|
|
|
|
value = V1;
|
|
|
|
|
} else if (time <= TD2) {
|
2011-02-27 21:40:48 +01:00
|
|
|
value = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1));
|
2010-12-18 18:05:44 +01:00
|
|
|
} else {
|
|
|
|
|
value = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1)) +
|
|
|
|
|
(V1-V2)*(1-exp(-(time-TD2)/TAU2)) ;
|
|
|
|
|
}
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
2010-12-18 18:05:44 +01:00
|
|
|
break;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2011-02-27 21:40:48 +01:00
|
|
|
case SFFM: {
|
|
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
double VO, VA, FC, MDI, FS;
|
|
|
|
|
double PHASEC, PHASES;
|
|
|
|
|
double phasec;
|
|
|
|
|
double phases;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
PHASEC = here->VSRCfunctionOrder > 5
|
2011-02-27 21:40:48 +01:00
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
2010-12-18 18:05:44 +01:00
|
|
|
PHASES = here->VSRCfunctionOrder > 6
|
2011-02-27 21:40:48 +01:00
|
|
|
? here->VSRCcoeffs[6] : 0.0;
|
|
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
/* compute phases in radians */
|
|
|
|
|
phasec = PHASEC * M_PI / 180.0;
|
2011-02-27 21:40:48 +01:00
|
|
|
phases = PHASES * M_PI / 180.0;
|
|
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
VO = here->VSRCcoeffs[0];
|
|
|
|
|
VA = here->VSRCcoeffs[1];
|
2011-02-27 21:40:48 +01:00
|
|
|
FC = here->VSRCfunctionOrder > 2
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[2]
|
|
|
|
|
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
|
|
|
|
|
MDI = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.0;
|
2011-02-27 21:40:48 +01:00
|
|
|
FS = here->VSRCfunctionOrder > 4
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[4]
|
|
|
|
|
? here->VSRCcoeffs[4] : (1/ckt->CKTfinalTime);
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
/* compute waveform value */
|
2011-02-27 21:40:48 +01:00
|
|
|
value = VO + VA *
|
2011-02-27 21:39:03 +01:00
|
|
|
sin((2.0 * M_PI * FC * time + phasec) +
|
2010-12-18 18:05:44 +01:00
|
|
|
MDI * sin(2.0 * M_PI * FS * time + phases));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
|
|
|
|
case AM: {
|
|
|
|
|
|
2024-01-06 23:09:27 +01:00
|
|
|
double VO, VA, FM, MD, FC, TD, PHASEM, PHASEC;
|
2010-12-18 18:05:44 +01:00
|
|
|
double phasec;
|
2024-01-06 23:09:27 +01:00
|
|
|
double phasem;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2024-01-06 23:09:27 +01:00
|
|
|
VO = here->VSRCcoeffs[0];
|
|
|
|
|
VA = here->VSRCcoeffs[1];
|
|
|
|
|
FM = here->VSRCfunctionOrder > 2
|
2010-12-18 18:05:44 +01:00
|
|
|
&& here->VSRCcoeffs[2]
|
2024-01-07 11:59:33 +01:00
|
|
|
? here->VSRCcoeffs[2] : (5. / ckt->CKTfinalTime);
|
2024-01-06 23:09:27 +01:00
|
|
|
MD = here->VSRCfunctionOrder > 3
|
|
|
|
|
? here->VSRCcoeffs[3] : 0.5;
|
|
|
|
|
FC = here->VSRCfunctionOrder > 4
|
2024-01-07 11:59:33 +01:00
|
|
|
? here->VSRCcoeffs[4] : (500. / ckt->CKTfinalTime);
|
2024-01-06 23:09:27 +01:00
|
|
|
TD = here->VSRCfunctionOrder > 5
|
|
|
|
|
&& here->VSRCcoeffs[5]
|
|
|
|
|
? here->VSRCcoeffs[5] : 0.0;
|
2024-01-07 11:59:33 +01:00
|
|
|
PHASEM = here->VSRCfunctionOrder > 6
|
|
|
|
|
? here->VSRCcoeffs[6] : 0.0;
|
|
|
|
|
PHASEC = here->VSRCfunctionOrder > 7
|
|
|
|
|
? here->VSRCcoeffs[7] : 0.0;
|
|
|
|
|
|
|
|
|
|
/* compute phases in radians */
|
|
|
|
|
phasec = PHASEC * M_PI / 180.0;
|
|
|
|
|
phasem = PHASEM * M_PI / 180.0;
|
2024-01-06 23:09:27 +01:00
|
|
|
|
|
|
|
|
/* limit the modulation depth */
|
|
|
|
|
if (MD > 1)
|
|
|
|
|
MD = 1;
|
|
|
|
|
else if (MD < 0)
|
|
|
|
|
MD = 0;
|
2005-05-10 09:01:47 +02:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
time -= TD;
|
|
|
|
|
if (time <= 0) {
|
|
|
|
|
value = 0;
|
|
|
|
|
} else {
|
|
|
|
|
/* compute waveform value */
|
2024-01-06 23:09:27 +01:00
|
|
|
value = VO + VA * (1 + MD * sin(2.0 * M_PI * FM * time + phasem)) *
|
|
|
|
|
sin(2.0 * M_PI * FC * time + phasec);
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
2010-11-27 17:36:03 +01:00
|
|
|
}
|
2010-12-18 18:05:44 +01:00
|
|
|
break;
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
case PWL: {
|
2023-04-03 20:12:51 +02:00
|
|
|
int i;
|
|
|
|
|
double end_time, itime;
|
2010-02-26 23:55:40 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
time -= here->VSRCrdelay;
|
2023-04-03 20:12:51 +02:00
|
|
|
if (time < here->VSRCcoeffs[0]) {
|
|
|
|
|
value = here->VSRCcoeffs[1];
|
|
|
|
|
value = value;
|
|
|
|
|
break;
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
2007-10-09 10:44:49 +02:00
|
|
|
|
2023-04-03 20:12:51 +02:00
|
|
|
end_time =
|
|
|
|
|
here->VSRCcoeffs[here->VSRCfunctionOrder - 2];
|
|
|
|
|
if (time > end_time) {
|
|
|
|
|
double period;
|
2007-10-09 10:44:49 +02:00
|
|
|
|
2023-04-03 20:12:51 +02:00
|
|
|
if (here->VSRCrGiven) {
|
|
|
|
|
/* Repeating. */
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2023-04-03 20:12:51 +02:00
|
|
|
period = end_time -
|
|
|
|
|
here->VSRCcoeffs[here->VSRCrBreakpt];
|
2023-06-20 10:50:06 +02:00
|
|
|
time -= here->VSRCcoeffs[here->VSRCrBreakpt];
|
2023-04-03 20:12:51 +02:00
|
|
|
time -= period * floor(time / period);
|
2023-05-14 18:16:24 +02:00
|
|
|
time += here->VSRCcoeffs[here->VSRCrBreakpt];
|
2023-04-03 20:12:51 +02:00
|
|
|
} else {
|
2023-04-26 22:34:37 +02:00
|
|
|
value =
|
|
|
|
|
here->VSRCcoeffs[here->VSRCfunctionOrder - 1];
|
2023-04-03 20:12:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 2; i < here->VSRCfunctionOrder; i += 2) {
|
|
|
|
|
itime = here->VSRCcoeffs[i];
|
|
|
|
|
if (itime >= time) {
|
|
|
|
|
time -= here->VSRCcoeffs[i - 2];
|
|
|
|
|
time /= here->VSRCcoeffs[i] -
|
|
|
|
|
here->VSRCcoeffs[i - 2];
|
|
|
|
|
value = here->VSRCcoeffs[i - 1];
|
|
|
|
|
value += time *
|
|
|
|
|
( here->VSRCcoeffs[i + 1] -
|
|
|
|
|
here->VSRCcoeffs[i - 1]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-18 18:05:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2011-02-27 21:40:48 +01:00
|
|
|
/**** tansient noise routines:
|
2010-11-27 17:36:03 +01:00
|
|
|
VNoi2 2 0 DC 0 TRNOISE(10n 0.5n 0 0n) : generate gaussian distributed noise
|
|
|
|
|
rms value, time step, 0 0
|
|
|
|
|
VNoi1 1 0 DC 0 TRNOISE(0n 0.5n 1 10n) : generate 1/f noise
|
|
|
|
|
0, time step, exponent < 2, rms value
|
2010-12-18 18:05:44 +01:00
|
|
|
|
|
|
|
|
VNoi3 3 0 DC 0 TRNOISE(0 0 0 0 15m 22u 50u) : generate RTS noise
|
|
|
|
|
0 0 0 0, amplitude, capture time, emission time
|
2010-11-27 17:36:03 +01:00
|
|
|
*/
|
2010-12-18 18:05:44 +01:00
|
|
|
case TRNOISE: {
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
struct trnoise_state *state = here -> VSRCtrnoise_state;
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
double TS = state -> TS;
|
|
|
|
|
double RTSAM = state->RTSAM;
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2018-08-22 22:38:34 +02:00
|
|
|
/* reset top (hack for repeated tran commands)
|
|
|
|
|
when there is the jump from time=0 to time>0 */
|
|
|
|
|
if (time == 0.0)
|
|
|
|
|
state->timezero = TRUE;
|
|
|
|
|
else
|
|
|
|
|
if (state->timezero) {
|
|
|
|
|
state->top = 0;
|
|
|
|
|
state->timezero = FALSE;
|
|
|
|
|
}
|
2012-12-22 17:57:31 +01:00
|
|
|
|
2018-08-22 22:38:34 +02:00
|
|
|
/* no noise or time == 0 */
|
|
|
|
|
if(TS == 0.0 || time == 0.0) {
|
2010-12-18 18:05:44 +01:00
|
|
|
value = 0.0;
|
|
|
|
|
} else {
|
2012-12-22 17:57:31 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
/* 1/f and white noise */
|
|
|
|
|
size_t n1 = (size_t) floor(time / TS);
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2010-12-18 18:05:44 +01:00
|
|
|
double V1 = trnoise_state_get(state, ckt, n1);
|
|
|
|
|
double V2 = trnoise_state_get(state, ckt, n1+1);
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2012-10-26 18:04:44 +02:00
|
|
|
value = V1 + (V2 - V1) * (time / TS - (double)n1);
|
2010-12-18 18:05:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* RTS noise */
|
|
|
|
|
if (RTSAM > 0) {
|
|
|
|
|
double RTScapTime = state->RTScapTime;
|
|
|
|
|
if (time >= RTScapTime)
|
|
|
|
|
value += RTSAM;
|
|
|
|
|
}
|
2010-11-27 17:36:03 +01:00
|
|
|
|
2011-02-28 21:32:34 +01:00
|
|
|
/* DC value */
|
2010-12-18 18:05:44 +01:00
|
|
|
if(here -> VSRCdcGiven)
|
|
|
|
|
value += here->VSRCdcValue;
|
2011-02-27 21:39:03 +01:00
|
|
|
}
|
2011-02-27 21:40:48 +01:00
|
|
|
break;
|
2011-01-16 20:19:42 +01:00
|
|
|
|
|
|
|
|
case TRRANDOM: {
|
|
|
|
|
struct trrandom_state *state = here -> VSRCtrrandom_state;
|
|
|
|
|
value = state -> value;
|
2011-02-27 21:40:48 +01:00
|
|
|
/* DC value */
|
2011-01-16 20:19:42 +01:00
|
|
|
if(here -> VSRCdcGiven)
|
|
|
|
|
value += here->VSRCdcValue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-07-14 18:45:49 +02:00
|
|
|
#ifdef SHARED_MODULE
|
|
|
|
|
case EXTERNAL: {
|
|
|
|
|
value = getvsrcval(time, here->VSRCname);
|
|
|
|
|
if(here -> VSRCdcGiven)
|
|
|
|
|
value += here->VSRCdcValue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2022-01-08 15:39:47 +01:00
|
|
|
#ifdef RFSPICE
|
|
|
|
|
case PORT:
|
|
|
|
|
{
|
|
|
|
|
value += here->VSRCVAmplitude * cos(time * here->VSRC2pifreq);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2013-07-14 18:45:49 +02:00
|
|
|
|
2010-11-27 17:36:03 +01:00
|
|
|
} // switch
|
2011-02-27 21:39:03 +01:00
|
|
|
} // else (line 48)
|
2011-02-27 21:40:48 +01:00
|
|
|
|
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
|
2011-02-27 21:39:03 +01:00
|
|
|
if (ckt->CKTmode & MODETRANOP)
|
|
|
|
|
value *= ckt->CKTsrcFact;
|
2005-05-10 09:01:47 +02:00
|
|
|
#endif
|
|
|
|
|
/* gtri - end - wbk - modify to process srcFact, etc. for all sources */
|
2011-02-27 21:05:32 +01:00
|
|
|
|
|
|
|
|
/* load the new voltage value into the matrix */
|
|
|
|
|
*(ckt->CKTrhs + (here->VSRCbranch)) += value;
|
|
|
|
|
|
2010-11-27 17:36:03 +01:00
|
|
|
} // for loop instances
|
|
|
|
|
} // for loop models
|
2011-02-27 21:40:48 +01:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
return(OK);
|
|
|
|
|
}
|