merge TRRANDOM vsrc -> isrc

This commit is contained in:
rlar 2011-02-28 20:32:34 +00:00
parent 49211d2153
commit 2a693e2d80
9 changed files with 84 additions and 2 deletions

View File

@ -1,3 +1,15 @@
2011-02-28 Robert Larice
* src/spicelib/devices/isrc/isrc.c ,
* src/spicelib/devices/isrc/isrcacct.c ,
* src/spicelib/devices/isrc/isrcask.c ,
* src/spicelib/devices/isrc/isrcdefs.h ,
* src/spicelib/devices/isrc/isrcload.c ,
* src/spicelib/devices/isrc/isrcpar.c ,
* src/spicelib/devices/vsrc/vsrc.c ,
* src/spicelib/devices/vsrc/vsrcload.c :
merge TRRANDOM vsrc -> isrc
see commit from 11-01-16
2011-02-27 Robert Larice
* src/spicelib/devices/isrc/* ,
* src/spicelib/devices/vsrc/* :

View File

@ -22,6 +22,8 @@ IFparm ISRCpTable[] = { /* parameters */
IOP ("sffm", ISRC_SFFM, IF_REALVEC,"Single freq. FM description"),
IOP ("am", ISRC_AM, IF_REALVEC,"Amplitude modulation description"),
IOP ("trnoise", ISRC_TRNOISE, IF_REALVEC,"Transient noise description"),
IOP ("trrandom", ISRC_TRRANDOM, IF_REALVEC,"random source description"),
OPU ("pos_node",ISRC_POS_NODE, IF_INTEGER,"Positive node of source"),
OPU ("neg_node",ISRC_NEG_NODE, IF_INTEGER,"Negative node of source"),
OPU ("function",ISRC_FCN_TYPE, IF_INTEGER,"Function of the source"),

View File

@ -263,6 +263,35 @@ ISRCaccept(CKTcircuit *ckt, GENmodel *inModel)
}
break;
case TRRANDOM: {
struct trrandom_state *state = here -> ISRCtrrandom_state;
double TS = state -> TS;
double TD = state -> TD;
double time = ckt->CKTtime - TD;
if (time < 0) break;
if(ckt->CKTbreak) {
int n = (int) floor(time / TS + 0.5);
volatile double nearest = n * TS;
if(AlmostEqualUlps(nearest, time, 3)) {
/* carefully calculate `next'
* make sure it is really identical
* with the next calculated `nearest' value
*/
volatile double next = (n+1) * TS + TD;
error = CKTsetBreak(ckt, next);
if(error)
return(error);
state->value = trrandom_state_get(state);
}
}
}
break;
} // switch
} // if ... else
bkptset: ;

View File

@ -47,6 +47,7 @@ ISRCask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, IFvalue *
case ISRC_SFFM:
case ISRC_AM:
case ISRC_TRNOISE:
case ISRC_TRRANDOM:
case ISRC_FCN_COEFFS:
temp = value->v.numValue = here->ISRCfunctionOrder;
v = value->v.vec.rVec = TMALLOC(double, here->ISRCfunctionOrder);

View File

@ -47,6 +47,7 @@ typedef struct sISRCinstance {
double ISRCdF2phase; /* distortion f2 phase */
struct trnoise_state *ISRCtrnoise_state; /* transient noise */
struct trrandom_state *ISRCtrrandom_state; /* transient random source */
/* gtri - begin - add member to hold current source value */
#ifdef XSPICE
@ -89,6 +90,7 @@ typedef struct sISRCmodel {
#define PWL 5
#define AM 6
#define TRNOISE 7
#define TRRANDOM 8
#endif /*PULSE*/
/* device parameters */
@ -121,6 +123,8 @@ typedef struct sISRCmodel {
#endif
/* gtri - end - add define for current source value */
#define ISRC_TRNOISE 25
#define ISRC_TRRANDOM 26
/* model parameters */
/* device questions */

View File

@ -354,6 +354,15 @@ INoi1 1 0 DC 0 TRNOISE(0n 0.5n 1 10n) : generate 1/f noise
}
break;
case TRRANDOM: {
struct trrandom_state *state = here -> ISRCtrrandom_state;
value = state -> value;
/* DC value */
if(here -> ISRCdcGiven)
value += here->ISRCdcValue;
}
break;
} // switch
} // else (line 48)
loadDone:

View File

@ -202,7 +202,32 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->ISRCtrnoise_state =
trnoise_state_init(NA, TS, NALPHA, NAMP, RTSAM, RTSCAPT, RTSEMT);
}
break;
case ISRC_TRRANDOM: {
double TD = 0.0, TS;
int rndtype = 1;
double PARAM1 = 1.0;
double PARAM2 = 0.0;
here->ISRCfunctionType = TRRANDOM;
here->ISRCfuncTGiven = TRUE;
copy_coeffs(here, value);
rndtype = (int)here->ISRCcoeffs[0]; // type of random function
TS = here->ISRCcoeffs[1]; // time step
if (here->ISRCfunctionOrder > 2)
TD = here->ISRCcoeffs[2]; // delay
if (here->ISRCfunctionOrder > 3)
PARAM1 = here->ISRCcoeffs[3]; // first parameter
if (here->ISRCfunctionOrder > 4)
PARAM2 = here->ISRCcoeffs[4]; // second parameter
here->ISRCtrrandom_state =
trrandom_state_init(rndtype, TS, TD, PARAM1, PARAM2);
}
break;

View File

@ -22,7 +22,7 @@ IFparm VSRCpTable[] = { /* parameters */
IOP ("sffm", VSRC_SFFM, IF_REALVEC,"Single freq. FM description"),
IOP ("am", VSRC_AM, IF_REALVEC,"Amplitude modulation description"),
IOP ("trnoise", VSRC_TRNOISE, IF_REALVEC,"Transient noise description"),
IOP ("trrandom", VSRC_TRRANDOM, IF_REALVEC,"random voltage description"),
IOP ("trrandom", VSRC_TRRANDOM, IF_REALVEC,"random source description"),
OPU ("pos_node",VSRC_POS_NODE, IF_INTEGER,"Positive node of source"),
OPU ("neg_node",VSRC_NEG_NODE, IF_INTEGER,"Negative node of source"),

View File

@ -367,7 +367,7 @@ VNoi3 3 0 DC 0 TRNOISE(0 0 0 0 15m 22u 50u) : generate RTS noise
value += RTSAM;
}
/* DC value */
/* DC value */
if(here -> VSRCdcGiven)
value += here->VSRCdcValue;
}