format
This commit is contained in:
parent
e8f1cd4c92
commit
20c82a5b1b
|
|
@ -11,23 +11,22 @@ Author: 1987 Gary W. Ng
|
||||||
#include "ngspice/suffix.h"
|
#include "ngspice/suffix.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* BJTnoise (mode, operation, firstModel, ckt, data, OnDens)
|
*BJTnoise (mode, operation, firstModel, ckt, data, OnDens)
|
||||||
*
|
*
|
||||||
* This routine names and evaluates all of the noise sources
|
* This routine names and evaluates all of the noise sources
|
||||||
* associated with BJT's. It starts with the model *firstModel and
|
* associated with BJT's. It starts with the model *firstModel and
|
||||||
* traverses all of its insts. It then proceeds to any other models
|
* traverses all of its insts. It then proceeds to any other models
|
||||||
* on the linked list. The total output noise density generated by
|
* on the linked list. The total output noise density generated by
|
||||||
* all of the BJT's is summed with the variable "OnDens".
|
* all of the BJT's is summed with the variable "OnDens".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BJTnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
BJTnoise(int mode, int operation, GENmodel*genmodel, CKTcircuit *ckt,
|
||||||
Ndata *data, double *OnDens)
|
Ndata *data, double *OnDens)
|
||||||
{
|
{
|
||||||
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
|
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
|
||||||
|
|
||||||
BJTmodel *firstModel = (BJTmodel *) genmodel;
|
BJTmodel *firstModel = (BJTmodel*) genmodel;
|
||||||
BJTmodel *model;
|
BJTmodel *model;
|
||||||
BJTinstance *inst;
|
BJTinstance *inst;
|
||||||
double tempOnoise;
|
double tempOnoise;
|
||||||
|
|
@ -39,159 +38,159 @@ BJTnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
/* define the names of the noise sources */
|
/* define the names of the noise sources */
|
||||||
|
|
||||||
static char *BJTnNames[BJTNSRCS] = {
|
static char *BJTnNames[BJTNSRCS] = {
|
||||||
/* Note that we have to keep the order consistent with the
|
/* Note that we have to keep the order consistent with the
|
||||||
strchr definitions in BJTdefs.h */
|
strchr definitions in BJTdefs.h */
|
||||||
"_rc", /* noise due to rc */
|
"_rc", /* noise due to rc */
|
||||||
"_rb", /* noise due to rb */
|
"_rb", /* noise due to rb */
|
||||||
"_re", /* noise due to re */
|
"_re", /* noise due to re */
|
||||||
"_ic", /* noise due to ic */
|
"_ic", /* noise due to ic */
|
||||||
"_ib", /* noise due to ib */
|
"_ib", /* noise due to ib */
|
||||||
"_1overf", /* flicker (1/f) noise */
|
"_1overf", /* flicker (1/f) noise */
|
||||||
"" /* total transistor noise */
|
"" /* total transistor noise */
|
||||||
};
|
};
|
||||||
|
|
||||||
for (model=firstModel; model != NULL; model=BJTnextModel(model)) {
|
for (model = firstModel; model != NULL; model = BJTnextModel(model)) {
|
||||||
for (inst=BJTinstances(model); inst != NULL;
|
for (inst = BJTinstances(model); inst != NULL; inst = BJTnextInstance(inst)) {
|
||||||
inst=BJTnextInstance(inst)) {
|
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
|
||||||
case N_OPEN:
|
case N_OPEN:
|
||||||
|
|
||||||
/* see if we have to to produce a summary report */
|
/* see if we have to to produce a summary report */
|
||||||
/* if so, name all the noise generators */
|
/* if so, name all the noise generators */
|
||||||
|
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->BJTname, BJTnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->BJTname, BJTnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ:
|
case INT_NOIZ:
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->BJTname, BJTnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->BJTname, BJTnNames[i]);
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->BJTname, BJTnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->BJTname, BJTnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case N_CALC:
|
case N_CALC:
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
NevalSrc(&noizDens[BJTRCNOIZ],&lnNdens[BJTRCNOIZ],
|
NevalSrc(&noizDens[BJTRCNOIZ],&lnNdens[BJTRCNOIZ],
|
||||||
ckt,THERMNOISE,inst->BJTcollCXNode,inst->BJTcolNode,
|
ckt, THERMNOISE, inst->BJTcollCXNode, inst->BJTcolNode,
|
||||||
inst->BJTtcollectorConduct * inst->BJTm);
|
inst->BJTtcollectorConduct * inst->BJTm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[BJTRBNOIZ],&lnNdens[BJTRBNOIZ],
|
NevalSrc(&noizDens[BJTRBNOIZ],&lnNdens[BJTRBNOIZ],
|
||||||
ckt,THERMNOISE,inst->BJTbasePrimeNode,inst->BJTbaseNode,
|
ckt, THERMNOISE, inst->BJTbasePrimeNode, inst->BJTbaseNode,
|
||||||
*(ckt->CKTstate0 + inst->BJTgx) * inst->BJTm);
|
*(ckt->CKTstate0 + inst->BJTgx) * inst->BJTm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[BJT_RE_NOISE],&lnNdens[BJT_RE_NOISE],
|
NevalSrc(&noizDens[BJT_RE_NOISE],&lnNdens[BJT_RE_NOISE],
|
||||||
ckt,THERMNOISE,inst->BJTemitPrimeNode,inst->BJTemitNode,
|
ckt, THERMNOISE, inst->BJTemitPrimeNode, inst->BJTemitNode,
|
||||||
inst->BJTtemitterConduct * inst-> BJTm);
|
inst->BJTtemitterConduct * inst->BJTm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[BJTICNOIZ],&lnNdens[BJTICNOIZ],
|
NevalSrc(&noizDens[BJTICNOIZ],&lnNdens[BJTICNOIZ],
|
||||||
ckt,SHOTNOISE,inst->BJTcolPrimeNode, inst->BJTemitPrimeNode,
|
ckt, SHOTNOISE, inst->BJTcolPrimeNode, inst->BJTemitPrimeNode,
|
||||||
*(ckt->CKTstate0 + inst->BJTcc) * inst->BJTm);
|
*(ckt->CKTstate0 + inst->BJTcc) * inst->BJTm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[BJTIBNOIZ],&lnNdens[BJTIBNOIZ],
|
NevalSrc(&noizDens[BJTIBNOIZ],&lnNdens[BJTIBNOIZ],
|
||||||
ckt,SHOTNOISE,inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
|
ckt, SHOTNOISE, inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
|
||||||
*(ckt->CKTstate0 + inst->BJTcb) * inst->BJTm);
|
*(ckt->CKTstate0 + inst->BJTcb) * inst->BJTm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[BJTFLNOIZ], NULL, ckt,
|
NevalSrc(&noizDens[BJTFLNOIZ], NULL, ckt,
|
||||||
N_GAIN,inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
|
N_GAIN, inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
|
||||||
(double)0.0);
|
(double) 0.0);
|
||||||
noizDens[BJTFLNOIZ] *= inst->BJTm * model->BJTfNcoef *
|
noizDens[BJTFLNOIZ] *= inst->BJTm * model->BJTfNcoef *
|
||||||
exp(model->BJTfNexp *
|
exp(model->BJTfNexp *
|
||||||
log(MAX(fabs(*(ckt->CKTstate0 + inst->BJTcb)),N_MINLOG))) /
|
log(MAX(fabs(*(ckt->CKTstate0 + inst->BJTcb)), N_MINLOG))) /
|
||||||
data->freq;
|
data->freq;
|
||||||
lnNdens[BJTFLNOIZ] =
|
lnNdens[BJTFLNOIZ] =
|
||||||
log(MAX(noizDens[BJTFLNOIZ],N_MINLOG));
|
log(MAX(noizDens[BJTFLNOIZ], N_MINLOG));
|
||||||
|
|
||||||
noizDens[BJTTOTNOIZ] = noizDens[BJTRCNOIZ] +
|
noizDens[BJTTOTNOIZ] = noizDens[BJTRCNOIZ] +
|
||||||
noizDens[BJTRBNOIZ] +
|
noizDens[BJTRBNOIZ] +
|
||||||
noizDens[BJT_RE_NOISE] +
|
noizDens[BJT_RE_NOISE] +
|
||||||
noizDens[BJTICNOIZ] +
|
noizDens[BJTICNOIZ] +
|
||||||
noizDens[BJTIBNOIZ] +
|
noizDens[BJTIBNOIZ] +
|
||||||
noizDens[BJTFLNOIZ];
|
noizDens[BJTFLNOIZ];
|
||||||
lnNdens[BJTTOTNOIZ] =
|
lnNdens[BJTTOTNOIZ] =
|
||||||
log(noizDens[BJTTOTNOIZ]);
|
log(noizDens[BJTTOTNOIZ]);
|
||||||
|
|
||||||
*OnDens += noizDens[BJTTOTNOIZ];
|
*OnDens += noizDens[BJTTOTNOIZ];
|
||||||
|
|
||||||
if (data->delFreq == 0.0) {
|
if (data->delFreq == 0.0) {
|
||||||
|
|
||||||
/* if we haven't done any previous integration, we need to */
|
/* if we haven't done any previous integration, we need to */
|
||||||
/* initialize our "history" variables */
|
/* initialize our "history" variables */
|
||||||
|
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear out our integration variables if it's the first pass */
|
/* clear out our integration variables if it's the first pass */
|
||||||
|
|
||||||
if (data->freq == job->NstartFreq) {
|
if (data->freq == job->NstartFreq) {
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
inst->BJTnVar[OUTNOIZ][i] = 0.0;
|
inst->BJTnVar[OUTNOIZ][i] = 0.0;
|
||||||
inst->BJTnVar[INNOIZ][i] = 0.0;
|
inst->BJTnVar[INNOIZ][i] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* data->delFreq != 0.0 (we have to integrate) */
|
} else {
|
||||||
|
/* data->delFreq != 0.0 (we have to integrate) */
|
||||||
|
|
||||||
/* In order to get the best curve fit, we have to integrate each component separately */
|
/* In order to get the best curve fit, we have to integrate each component separately */
|
||||||
|
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
if (i != BJTTOTNOIZ) {
|
if (i != BJTTOTNOIZ) {
|
||||||
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
||||||
inst->BJTnVar[LNLSTDENS][i], data);
|
inst->BJTnVar[LNLSTDENS][i], data);
|
||||||
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
|
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
|
||||||
lnNdens[i] + data->lnGainInv,
|
lnNdens[i] + data->lnGainInv,
|
||||||
inst->BJTnVar[LNLSTDENS][i] + data->lnGainInv,
|
inst->BJTnVar[LNLSTDENS][i] + data->lnGainInv,
|
||||||
data);
|
data);
|
||||||
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
data->outNoiz += tempOnoise;
|
data->outNoiz += tempOnoise;
|
||||||
data->inNoise += tempInoise;
|
data->inNoise += tempInoise;
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
inst->BJTnVar[OUTNOIZ][i] += tempOnoise;
|
inst->BJTnVar[OUTNOIZ][i] += tempOnoise;
|
||||||
inst->BJTnVar[OUTNOIZ][BJTTOTNOIZ] += tempOnoise;
|
inst->BJTnVar[OUTNOIZ][BJTTOTNOIZ] += tempOnoise;
|
||||||
inst->BJTnVar[INNOIZ][i] += tempInoise;
|
inst->BJTnVar[INNOIZ][i] += tempInoise;
|
||||||
inst->BJTnVar[INNOIZ][BJTTOTNOIZ] += tempInoise;
|
inst->BJTnVar[INNOIZ][BJTTOTNOIZ] += tempInoise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data->prtSummary) {
|
if (data->prtSummary) {
|
||||||
for (i=0; i < BJTNSRCS; i++) { /* print a summary report */
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = noizDens[i];
|
/* print a summary report */
|
||||||
}
|
data->outpVector[data->outNumber++] = noizDens[i];
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case INT_NOIZ: /* already calculated, just output */
|
case INT_NOIZ:
|
||||||
if (job->NStpsSm != 0) {
|
/* already calculated, just output */
|
||||||
for (i=0; i < BJTNSRCS; i++) {
|
if (job->NStpsSm != 0) {
|
||||||
data->outpVector[data->outNumber++] = inst->BJTnVar[OUTNOIZ][i];
|
for (i = 0; i < BJTNSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = inst->BJTnVar[INNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->BJTnVar[OUTNOIZ][i];
|
||||||
}
|
data->outpVector[data->outNumber++] = inst->BJTnVar[INNOIZ][i];
|
||||||
} /* if */
|
}
|
||||||
break;
|
} /* if */
|
||||||
} /* switch (mode) */
|
break;
|
||||||
break;
|
} /* switch (mode) */
|
||||||
|
break;
|
||||||
|
|
||||||
case N_CLOSE:
|
case N_CLOSE:
|
||||||
return (OK); /* do nothing, the main calling routine will close */
|
return (OK); /* do nothing, the main calling routine will close */
|
||||||
break; /* the plots */
|
break; /* the plots */
|
||||||
} /* switch (operation) */
|
} /* switch (operation) */
|
||||||
} /* for inst */
|
} /* for inst */
|
||||||
} /* for model */
|
} /* for model */
|
||||||
|
|
||||||
return(OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
|
|
@ -12,23 +12,22 @@ Modified by Dietmar Warning 2003
|
||||||
#include "ngspice/suffix.h"
|
#include "ngspice/suffix.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DIOnoise (mode, operation, firstModel, ckt, data, OnDens)
|
*DIOnoise (mode, operation, firstModel, ckt, data, OnDens)
|
||||||
* This routine names and evaluates all of the noise sources
|
* This routine names and evaluates all of the noise sources
|
||||||
* associated with diodes. It starts with the model *firstModel and
|
* associated with diodes. It starts with the model *firstModel and
|
||||||
* traverses all of its instancess. It then proceeds to any other
|
* traverses all of its instancess. It then proceeds to any other
|
||||||
* models on the linked list. The total output noise density
|
* models on the linked list. The total output noise density
|
||||||
* generated by all of the diodes is summed with the variable
|
* generated by all of the diodes is summed with the variable
|
||||||
* "OnDens".
|
* "OnDens".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DIOnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
DIOnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
Ndata *data, double *OnDens)
|
Ndata *data, double *OnDens)
|
||||||
{
|
{
|
||||||
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
|
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
|
||||||
|
|
||||||
DIOmodel *firstModel = (DIOmodel *) genmodel;
|
DIOmodel *firstModel = (DIOmodel*) genmodel;
|
||||||
DIOmodel *model;
|
DIOmodel *model;
|
||||||
DIOinstance *inst;
|
DIOinstance *inst;
|
||||||
double tempOnoise;
|
double tempOnoise;
|
||||||
|
|
@ -39,138 +38,141 @@ DIOnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
|
|
||||||
/* define the names of the noise sources */
|
/* define the names of the noise sources */
|
||||||
|
|
||||||
static char *DIOnNames[DIONSRCS] = { /* Note that we have to keep the order */
|
static char *DIOnNames[DIONSRCS] = {
|
||||||
"_rs", /* noise due to rs */ /* consistent with thestrchr definitions */
|
/* Note that we have to keep the order
|
||||||
"_id", /* noise due to id */ /* in DIOdefs.h */
|
consistent with thestrchr definitions in DIOdefs.h */
|
||||||
"_1overf", /* flicker (1/f) noise */
|
"_rs", /* noise due to rs */
|
||||||
"" /* total diode noise */
|
"_id", /* noise due to id */
|
||||||
|
"_1overf", /* flicker (1/f) noise */
|
||||||
|
"" /* total diode noise */
|
||||||
};
|
};
|
||||||
|
|
||||||
for (model=firstModel; model != NULL; model=DIOnextModel(model)) {
|
for (model = firstModel; model != NULL; model = DIOnextModel(model)) {
|
||||||
for (inst=DIOinstances(model); inst != NULL; inst=DIOnextInstance(inst)) {
|
for (inst = DIOinstances(model); inst != NULL; inst = DIOnextInstance(inst)) {
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
|
||||||
case N_OPEN:
|
case N_OPEN:
|
||||||
|
|
||||||
/* see if we have to to produce a summary report */
|
/* see if we have to to produce a summary report */
|
||||||
/* if so, name all the noise generators */
|
/* if so, name all the noise generators */
|
||||||
|
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->DIOname, DIOnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->DIOname, DIOnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ:
|
case INT_NOIZ:
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->DIOname, DIOnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->DIOname, DIOnNames[i]);
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->DIOname, DIOnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->DIOname, DIOnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case N_CALC:
|
case N_CALC:
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
NevalSrc(&noizDens[DIORSNOIZ],&lnNdens[DIORSNOIZ],
|
NevalSrc(&noizDens[DIORSNOIZ],&lnNdens[DIORSNOIZ],
|
||||||
ckt,THERMNOISE,inst->DIOposPrimeNode,inst->DIOposNode,
|
ckt, THERMNOISE, inst->DIOposPrimeNode, inst->DIOposNode,
|
||||||
inst->DIOtConductance * inst->DIOarea * inst->DIOm);
|
inst->DIOtConductance * inst->DIOarea * inst->DIOm);
|
||||||
NevalSrc(&noizDens[DIOIDNOIZ],&lnNdens[DIOIDNOIZ],
|
NevalSrc(&noizDens[DIOIDNOIZ],&lnNdens[DIOIDNOIZ],
|
||||||
ckt,SHOTNOISE,inst->DIOposPrimeNode, inst->DIOnegNode,
|
ckt, SHOTNOISE, inst->DIOposPrimeNode, inst->DIOnegNode,
|
||||||
*(ckt->CKTstate0 + inst->DIOcurrent));
|
*(ckt->CKTstate0 + inst->DIOcurrent));
|
||||||
|
|
||||||
NevalSrc(&noizDens[DIOFLNOIZ], NULL, ckt,
|
NevalSrc(&noizDens[DIOFLNOIZ], NULL, ckt,
|
||||||
N_GAIN,inst->DIOposPrimeNode, inst->DIOnegNode,
|
N_GAIN, inst->DIOposPrimeNode, inst->DIOnegNode,
|
||||||
(double)0.0);
|
(double) 0.0);
|
||||||
noizDens[DIOFLNOIZ] *= model->DIOfNcoef *
|
noizDens[DIOFLNOIZ] *= model->DIOfNcoef *
|
||||||
exp(model->DIOfNexp *
|
exp(model->DIOfNexp *
|
||||||
log(MAX(fabs(*(ckt->CKTstate0 + inst->DIOcurrent)/inst->DIOm),N_MINLOG))) /
|
log(MAX(fabs(*(ckt->CKTstate0 + inst->DIOcurrent) / inst->DIOm), N_MINLOG))) /
|
||||||
data->freq * inst->DIOm;
|
data->freq * inst->DIOm;
|
||||||
lnNdens[DIOFLNOIZ] =
|
lnNdens[DIOFLNOIZ] =
|
||||||
log(MAX(noizDens[DIOFLNOIZ],N_MINLOG));
|
log(MAX(noizDens[DIOFLNOIZ], N_MINLOG));
|
||||||
|
|
||||||
noizDens[DIOTOTNOIZ] = noizDens[DIORSNOIZ] +
|
noizDens[DIOTOTNOIZ] = noizDens[DIORSNOIZ] +
|
||||||
noizDens[DIOIDNOIZ] +
|
noizDens[DIOIDNOIZ] +
|
||||||
noizDens[DIOFLNOIZ];
|
noizDens[DIOFLNOIZ];
|
||||||
lnNdens[DIOTOTNOIZ] =
|
lnNdens[DIOTOTNOIZ] =
|
||||||
log(MAX(noizDens[DIOTOTNOIZ], N_MINLOG));
|
log(MAX(noizDens[DIOTOTNOIZ], N_MINLOG));
|
||||||
|
|
||||||
*OnDens += noizDens[DIOTOTNOIZ];
|
*OnDens += noizDens[DIOTOTNOIZ];
|
||||||
|
|
||||||
if (data->delFreq == 0.0) {
|
if (data->delFreq == 0.0) {
|
||||||
|
|
||||||
/* if we haven't done any previous integration, we need to */
|
/* if we haven't done any previous integration, we need to */
|
||||||
/* initialize our "history" variables */
|
/* initialize our "history" variables */
|
||||||
|
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear out our integration variables if it's the first pass */
|
/* clear out our integration variables if it's the first pass */
|
||||||
|
|
||||||
if (data->freq == job->NstartFreq) {
|
if (data->freq == job->NstartFreq) {
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
inst->DIOnVar[OUTNOIZ][i] = 0.0;
|
inst->DIOnVar[OUTNOIZ][i] = 0.0;
|
||||||
inst->DIOnVar[INNOIZ][i] = 0.0;
|
inst->DIOnVar[INNOIZ][i] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* data->delFreq != 0.0 (we have to integrate) */
|
} else {
|
||||||
|
/* data->delFreq != 0.0 (we have to integrate) */
|
||||||
|
|
||||||
/* To insure accurracy, we have to integrate each component separately */
|
/* To insure accurracy, we have to integrate each component separately */
|
||||||
|
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
if (i != DIOTOTNOIZ) {
|
if (i != DIOTOTNOIZ) {
|
||||||
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
||||||
inst->DIOnVar[LNLSTDENS][i], data);
|
inst->DIOnVar[LNLSTDENS][i], data);
|
||||||
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
|
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
|
||||||
lnNdens[i] + data->lnGainInv,
|
lnNdens[i] + data->lnGainInv,
|
||||||
inst->DIOnVar[LNLSTDENS][i] + data->lnGainInv,
|
inst->DIOnVar[LNLSTDENS][i] + data->lnGainInv,
|
||||||
data);
|
data);
|
||||||
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
data->outNoiz += tempOnoise;
|
data->outNoiz += tempOnoise;
|
||||||
data->inNoise += tempInoise;
|
data->inNoise += tempInoise;
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
inst->DIOnVar[OUTNOIZ][i] += tempOnoise;
|
inst->DIOnVar[OUTNOIZ][i] += tempOnoise;
|
||||||
inst->DIOnVar[OUTNOIZ][DIOTOTNOIZ] += tempOnoise;
|
inst->DIOnVar[OUTNOIZ][DIOTOTNOIZ] += tempOnoise;
|
||||||
inst->DIOnVar[INNOIZ][i] += tempInoise;
|
inst->DIOnVar[INNOIZ][i] += tempInoise;
|
||||||
inst->DIOnVar[INNOIZ][DIOTOTNOIZ] += tempInoise;
|
inst->DIOnVar[INNOIZ][DIOTOTNOIZ] += tempInoise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data->prtSummary) {
|
if (data->prtSummary) {
|
||||||
for (i=0; i < DIONSRCS; i++) { /* print a summary report */
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = noizDens[i];
|
/* print a summary report */
|
||||||
}
|
data->outpVector[data->outNumber++] = noizDens[i];
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case INT_NOIZ: /* already calculated, just output */
|
case INT_NOIZ:
|
||||||
if (job->NStpsSm != 0) {
|
/* already calculated, just output */
|
||||||
for (i=0; i < DIONSRCS; i++) {
|
if (job->NStpsSm != 0) {
|
||||||
data->outpVector[data->outNumber++] = inst->DIOnVar[OUTNOIZ][i];
|
for (i = 0; i < DIONSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = inst->DIOnVar[INNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->DIOnVar[OUTNOIZ][i];
|
||||||
}
|
data->outpVector[data->outNumber++] = inst->DIOnVar[INNOIZ][i];
|
||||||
} /* if */
|
}
|
||||||
break;
|
} /* if */
|
||||||
} /* switch (mode) */
|
break;
|
||||||
break;
|
} /* switch (mode) */
|
||||||
|
break;
|
||||||
|
|
||||||
case N_CLOSE:
|
case N_CLOSE:
|
||||||
return (OK); /* do nothing, the main calling routine will close */
|
return (OK); /* do nothing, the main calling routine will close */
|
||||||
break; /* the plots */
|
break; /* the plots */
|
||||||
} /* switch (operation) */
|
} /* switch (operation) */
|
||||||
} /* for inst */
|
} /* for inst */
|
||||||
} /* for model */
|
} /* for model */
|
||||||
|
|
||||||
return(OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
|
|
@ -11,22 +11,21 @@ Author: 1987 Gary W. Ng
|
||||||
#include "ngspice/suffix.h"
|
#include "ngspice/suffix.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JFETnoise (mode, operation, firstModel, ckt, data, OnDens)
|
*JFETnoise (mode, operation, firstModel, ckt, data, OnDens)
|
||||||
* This routine names and evaluates all of the noise sources
|
* This routine names and evaluates all of the noise sources
|
||||||
* associated with JFET's. It starts with the model *firstModel and
|
* associated with JFET's. It starts with the model *firstModel and
|
||||||
* traverses all of its insts. It then proceeds to any other models
|
* traverses all of its insts. It then proceeds to any other models
|
||||||
* on the linked list. The total output noise density generated by
|
* on the linked list. The total output noise density generated by
|
||||||
* all of the JFET's is summed with the variable "OnDens".
|
* all of the JFET's is summed with the variable "OnDens".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *data,
|
JFETnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *data,
|
||||||
double *OnDens)
|
double *OnDens)
|
||||||
{
|
{
|
||||||
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
|
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
|
||||||
|
|
||||||
JFETmodel *firstModel = (JFETmodel *) genmodel;
|
JFETmodel *firstModel = (JFETmodel*) genmodel;
|
||||||
JFETmodel *model;
|
JFETmodel *model;
|
||||||
JFETinstance *inst;
|
JFETinstance *inst;
|
||||||
double tempOnoise;
|
double tempOnoise;
|
||||||
|
|
@ -38,16 +37,18 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
|
||||||
|
|
||||||
/* define the names of the noise sources */
|
/* define the names of the noise sources */
|
||||||
|
|
||||||
static char *JFETnNames[JFETNSRCS] = { /* Note that we have to keep the order */
|
static char *JFETnNames[JFETNSRCS] = {
|
||||||
"_rd", /* noise due to rd */ /* consistent with thestrchr definitions */
|
/* Note that we have to keep the order
|
||||||
"_rs", /* noise due to rs */ /* in JFETdefs.h */
|
consistent with the strchr definitions in JFETdefs.h */
|
||||||
"_id", /* noise due to id */
|
"_rd", /* noise due to rd */
|
||||||
"_1overf", /* flicker (1/f) noise */
|
"_rs", /* noise due to rs */
|
||||||
"" /* total transistor noise */
|
"_id", /* noise due to id */
|
||||||
|
"_1overf", /* flicker (1/f) noise */
|
||||||
|
"" /* total transistor noise */
|
||||||
};
|
};
|
||||||
|
|
||||||
for (model=firstModel; model != NULL; model=JFETnextModel(model)) {
|
for (model = firstModel; model != NULL; model = JFETnextModel(model)) {
|
||||||
for (inst=JFETinstances(model); inst != NULL; inst=JFETnextInstance(inst)) {
|
for (inst = JFETinstances(model); inst != NULL; inst = JFETnextInstance(inst)) {
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
|
||||||
|
|
@ -60,13 +61,13 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->JFETname, JFETnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->JFETname, JFETnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ:
|
case INT_NOIZ:
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->JFETname, JFETnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->JFETname, JFETnNames[i]);
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->JFETname, JFETnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->JFETname, JFETnNames[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -80,80 +81,81 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
NevalSrc(&noizDens[JFETRDNOIZ],&lnNdens[JFETRDNOIZ],
|
NevalSrc(&noizDens[JFETRDNOIZ],&lnNdens[JFETRDNOIZ],
|
||||||
ckt,THERMNOISE,inst->JFETdrainPrimeNode,inst->JFETdrainNode,
|
ckt, THERMNOISE, inst->JFETdrainPrimeNode, inst->JFETdrainNode,
|
||||||
model->JFETdrainConduct * inst->JFETarea * inst->JFETm);
|
model->JFETdrainConduct * inst->JFETarea * inst->JFETm);
|
||||||
|
|
||||||
NevalSrc(&noizDens[JFETRSNOIZ],&lnNdens[JFETRSNOIZ],
|
NevalSrc(&noizDens[JFETRSNOIZ],&lnNdens[JFETRSNOIZ],
|
||||||
ckt,THERMNOISE,inst->JFETsourcePrimeNode,
|
ckt, THERMNOISE, inst->JFETsourcePrimeNode,
|
||||||
inst->JFETsourceNode,model->JFETsourceConduct
|
inst->JFETsourceNode, model->JFETsourceConduct *
|
||||||
* inst->JFETarea * inst->JFETm);
|
inst->JFETarea * inst->JFETm);
|
||||||
|
|
||||||
if (model->JFETnlev < 3) {
|
if (model->JFETnlev < 3) {
|
||||||
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
|
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
|
||||||
ckt,THERMNOISE,inst->JFETdrainPrimeNode,
|
ckt, THERMNOISE, inst->JFETdrainPrimeNode,
|
||||||
inst->JFETsourcePrimeNode,
|
inst->JFETsourcePrimeNode,
|
||||||
(2.0/3.0 * inst->JFETm * fabs(*(ckt->CKTstate0 + inst->JFETgm))));
|
(2.0 / 3.0 * inst->JFETm * fabs(*(ckt->CKTstate0 + inst->JFETgm))));
|
||||||
} else {
|
} else {
|
||||||
vgs = *(ckt->CKTstate0 + inst->JFETvgs);
|
vgs = *(ckt->CKTstate0 + inst->JFETvgs);
|
||||||
vds = vgs - *(ckt->CKTstate0 + inst->JFETvgd);
|
vds = vgs - *(ckt->CKTstate0 + inst->JFETvgd);
|
||||||
vgst = vgs - inst->JFETtThreshold;
|
vgst = vgs - inst->JFETtThreshold;
|
||||||
if (vgst >= vds)
|
if (vgst >= vds)
|
||||||
alpha = 1 - vds/vgst; /* linear region */
|
alpha = 1 - vds / vgst; /* linear region */
|
||||||
else
|
else
|
||||||
alpha = 0; /* saturation region */
|
alpha = 0; /* saturation region */
|
||||||
beta = inst->JFETtBeta * inst->JFETarea * inst->JFETm;
|
beta = inst->JFETtBeta * inst->JFETarea * inst->JFETm;
|
||||||
|
|
||||||
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
|
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
|
||||||
ckt,THERMNOISE,inst->JFETdrainPrimeNode,
|
ckt, THERMNOISE, inst->JFETdrainPrimeNode,
|
||||||
inst->JFETsourcePrimeNode,
|
inst->JFETsourcePrimeNode,
|
||||||
(2.0/3.0 * beta*vgst*(1+alpha+alpha*alpha)/(1+alpha)*model->JFETgdsnoi));
|
(2.0 / 3.0*beta*vgst*(1 + alpha + alpha*alpha) / (1 + alpha) * model->JFETgdsnoi));
|
||||||
}
|
}
|
||||||
|
|
||||||
NevalSrc(&noizDens[JFETFLNOIZ], NULL, ckt,
|
NevalSrc(&noizDens[JFETFLNOIZ], NULL, ckt,
|
||||||
N_GAIN,inst->JFETdrainPrimeNode,
|
N_GAIN, inst->JFETdrainPrimeNode,
|
||||||
inst->JFETsourcePrimeNode, (double)0.0);
|
inst->JFETsourcePrimeNode, (double) 0.0);
|
||||||
noizDens[JFETFLNOIZ] *= inst->JFETm * model->JFETfNcoef *
|
noizDens[JFETFLNOIZ] *= inst->JFETm*model->JFETfNcoef *
|
||||||
exp(model->JFETfNexp *
|
exp(model->JFETfNexp *
|
||||||
log(MAX(fabs(*(ckt->CKTstate0 + inst->JFETcd)),N_MINLOG))) /
|
log(MAX(fabs(*(ckt->CKTstate0 + inst->JFETcd)), N_MINLOG))) /
|
||||||
data->freq;
|
data->freq;
|
||||||
lnNdens[JFETFLNOIZ] =
|
lnNdens[JFETFLNOIZ] =
|
||||||
log(MAX(noizDens[JFETFLNOIZ],N_MINLOG));
|
log(MAX(noizDens[JFETFLNOIZ], N_MINLOG));
|
||||||
|
|
||||||
noizDens[JFETTOTNOIZ] = noizDens[JFETRDNOIZ] +
|
noizDens[JFETTOTNOIZ] = noizDens[JFETRDNOIZ] +
|
||||||
noizDens[JFETRSNOIZ] +
|
noizDens[JFETRSNOIZ] +
|
||||||
noizDens[JFETIDNOIZ] +
|
noizDens[JFETIDNOIZ] +
|
||||||
noizDens[JFETFLNOIZ];
|
noizDens[JFETFLNOIZ];
|
||||||
lnNdens[JFETTOTNOIZ] =
|
lnNdens[JFETTOTNOIZ] =
|
||||||
log(MAX(noizDens[JFETTOTNOIZ], N_MINLOG));
|
log(MAX(noizDens[JFETTOTNOIZ], N_MINLOG));
|
||||||
|
|
||||||
*OnDens += noizDens[JFETTOTNOIZ];
|
*OnDens += noizDens[JFETTOTNOIZ];
|
||||||
|
|
||||||
if (data->delFreq == 0.0) {
|
if (data->delFreq == 0.0) {
|
||||||
|
|
||||||
/* if we haven't done any previous integration, we need to */
|
/* if we haven't done any previous integration, we need to */
|
||||||
/* initialize our "history" variables */
|
/* initialize our "history" variables */
|
||||||
|
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear out our integration variables if it's the first pass */
|
/* clear out our integration variables if it's the first pass */
|
||||||
|
|
||||||
if (data->freq == job->NstartFreq) {
|
if (data->freq == job->NstartFreq) {
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
inst->JFETnVar[OUTNOIZ][i] = 0.0;
|
inst->JFETnVar[OUTNOIZ][i] = 0.0;
|
||||||
inst->JFETnVar[INNOIZ][i] = 0.0;
|
inst->JFETnVar[INNOIZ][i] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* data->delFreq != 0.0 (we have to integrate) */
|
} else {
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
/* data->delFreq != 0.0 (we have to integrate) */
|
||||||
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
if (i != JFETTOTNOIZ) {
|
if (i != JFETTOTNOIZ) {
|
||||||
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
|
||||||
inst->JFETnVar[LNLSTDENS][i], data);
|
inst->JFETnVar[LNLSTDENS][i], data);
|
||||||
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
|
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
|
||||||
lnNdens[i] + data->lnGainInv,
|
lnNdens[i] + data->lnGainInv,
|
||||||
inst->JFETnVar[LNLSTDENS][i] + data->lnGainInv,
|
inst->JFETnVar[LNLSTDENS][i] + data->lnGainInv,
|
||||||
data);
|
data);
|
||||||
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
data->outNoiz += tempOnoise;
|
data->outNoiz += tempOnoise;
|
||||||
data->inNoise += tempInoise;
|
data->inNoise += tempInoise;
|
||||||
|
|
@ -167,29 +169,31 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data->prtSummary) {
|
if (data->prtSummary) {
|
||||||
for (i=0; i < JFETNSRCS; i++) { /* print a summary report */
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
|
/* print a summary report */
|
||||||
data->outpVector[data->outNumber++] = noizDens[i];
|
data->outpVector[data->outNumber++] = noizDens[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ: /* already calculated, just output */
|
case INT_NOIZ:
|
||||||
|
/* already calculated, just output */
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
for (i=0; i < JFETNSRCS; i++) {
|
for (i = 0; i < JFETNSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = inst->JFETnVar[OUTNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->JFETnVar[OUTNOIZ][i];
|
||||||
data->outpVector[data->outNumber++] = inst->JFETnVar[INNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->JFETnVar[INNOIZ][i];
|
||||||
}
|
}
|
||||||
} /* if */
|
} /* if */
|
||||||
break;
|
break;
|
||||||
} /* switch (mode) */
|
} /* switch (mode) */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case N_CLOSE:
|
case N_CLOSE:
|
||||||
return (OK); /* do nothing, the main calling routine will close */
|
return (OK); /* do nothing, the main calling routine will close */
|
||||||
break; /* the plots */
|
break; /* the plots */
|
||||||
} /* switch (operation) */
|
} /* switch (operation) */
|
||||||
} /* for inst */
|
} /* for inst */
|
||||||
} /* for model */
|
} /* for model */
|
||||||
|
|
||||||
return(OK);
|
return (OK);
|
||||||
}
|
}
|
||||||
|
|
@ -11,28 +11,27 @@ Modified: Apr 2000 - Paolo Nenzi
|
||||||
#include "ngspice/noisedef.h"
|
#include "ngspice/noisedef.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RESnoise (mode, operation, firstModel, ckt, data, OnDens)
|
*RESnoise (mode, operation, firstModel, ckt, data, OnDens)
|
||||||
* This routine names and evaluates all of the noise sources
|
* This routine names and evaluates all of the noise sources
|
||||||
* associated with resistors. It starts with the model *firstModel
|
* associated with resistors. It starts with the model *firstModel
|
||||||
* and traverses all of its instances. It then proceeds to any other
|
* and traverses all of its instances. It then proceeds to any other
|
||||||
* models on the linked list. The total output noise density
|
* models on the linked list. The total output noise density
|
||||||
* generated by all the resistors is summed in the variable "OnDens".
|
* generated by all the resistors is summed in the variable "OnDens".
|
||||||
*
|
*
|
||||||
* Paolo Nenzi 2003:
|
*Paolo Nenzi 2003:
|
||||||
* Added flicker noise (Kf-Af) calculation to simulate
|
* Added flicker noise (Kf-Af) calculation to simulate
|
||||||
* carbon resistors.
|
* carbon resistors.
|
||||||
*
|
*
|
||||||
* Added "noisy" switch to simulate noiseless resistors.
|
* Added "noisy" switch to simulate noiseless resistors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
RESnoise(int mode, int operation, GENmodel*genmodel, CKTcircuit *ckt,
|
||||||
Ndata *data, double *OnDens)
|
Ndata *data, double *OnDens)
|
||||||
{
|
{
|
||||||
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
|
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
|
||||||
|
|
||||||
RESmodel *firstModel = (RESmodel *) genmodel;
|
RESmodel *firstModel = (RESmodel*) genmodel;
|
||||||
RESmodel *model;
|
RESmodel *model;
|
||||||
RESinstance *inst;
|
RESinstance *inst;
|
||||||
double tempOutNoise;
|
double tempOutNoise;
|
||||||
|
|
@ -41,23 +40,21 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
double lnNdens[RESNSRCS];
|
double lnNdens[RESNSRCS];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* define the names of the noise sources */
|
/* define the names of the noise sources */
|
||||||
|
|
||||||
static char *RESnNames[RESNSRCS] = {
|
static char *RESnNames[RESNSRCS] = {
|
||||||
/* Note that we have to keep the order consistent with the
|
/* Note that we have to keep the order consistent with the
|
||||||
* strchr definitions in RESdefs.h */
|
strchr definitions in RESdefs.h */
|
||||||
"_thermal", /* Thermal noise */
|
"_thermal", /* Thermal noise */
|
||||||
"_1overf", /* flicker (1/f) noise */
|
"_1overf", /* flicker (1/f) noise */
|
||||||
"" /* total resistor noise */
|
"" /* total resistor noise */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
for (model = firstModel; model != NULL; model = RESnextModel(model)) {
|
for (model = firstModel; model != NULL; model = RESnextModel(model)) {
|
||||||
for (inst = RESinstances(model); inst != NULL;
|
for (inst = RESinstances(model); inst != NULL; inst = RESnextInstance(inst)) {
|
||||||
inst = RESnextInstance(inst)) {
|
|
||||||
|
if (!inst->RESnoisy) continue; /* Quiet resistors are skipped */
|
||||||
|
|
||||||
if(!inst->RESnoisy) continue; /* Quiet resistors are skipped */
|
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
|
||||||
case N_OPEN:
|
case N_OPEN:
|
||||||
|
|
@ -71,13 +68,13 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
for (i=0; i < RESNSRCS; i++) {
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->RESname, RESnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->RESname, RESnNames[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ:
|
case INT_NOIZ:
|
||||||
for (i=0; i < RESNSRCS; i++) {
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->RESname, RESnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->RESname, RESnNames[i]);
|
||||||
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->RESname, RESnNames[i]);
|
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->RESname, RESnNames[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -90,99 +87,100 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
||||||
case N_DENS:
|
case N_DENS:
|
||||||
|
|
||||||
NevalSrcInstanceTemp(&noizDens[RESTHNOIZ],&lnNdens[RESTHNOIZ],
|
|
||||||
ckt,THERMNOISE, inst->RESposNode,inst->RESnegNode,
|
|
||||||
inst->RESconduct, inst->RESdtemp);
|
|
||||||
|
|
||||||
NevalSrcInstanceTemp(&noizDens[RESFLNOIZ], NULL, ckt,
|
NevalSrcInstanceTemp(&noizDens[RESTHNOIZ],&lnNdens[RESTHNOIZ],
|
||||||
N_GAIN,inst->RESposNode, inst->RESnegNode,
|
ckt, THERMNOISE, inst->RESposNode, inst->RESnegNode,
|
||||||
(double)0.0, (double)0.0);
|
inst->RESconduct, inst->RESdtemp);
|
||||||
|
|
||||||
#if 0
|
|
||||||
printf("DC current in resistor %s: %e\n",inst->RESname, inst->REScurrent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
noizDens[RESFLNOIZ] *= inst->RESm * model->RESfNcoef *
|
|
||||||
pow(fabs(inst->REScurrent / inst->RESm), model->RESfNexp)
|
|
||||||
/ (inst->RESeffNoiseArea * pow(data->freq, model->RESef));
|
|
||||||
lnNdens[RESFLNOIZ] = log(MAX(noizDens[RESFLNOIZ],N_MINLOG));
|
|
||||||
|
|
||||||
noizDens[RESTOTNOIZ] = noizDens[RESTHNOIZ] + noizDens[RESFLNOIZ];
|
NevalSrcInstanceTemp(&noizDens[RESFLNOIZ], NULL, ckt,
|
||||||
lnNdens[RESTOTNOIZ] = log(noizDens[RESTOTNOIZ]);
|
N_GAIN, inst->RESposNode, inst->RESnegNode,
|
||||||
|
(double) 0.0, (double) 0.0);
|
||||||
|
|
||||||
*OnDens += noizDens[RESTOTNOIZ];
|
#if 0
|
||||||
|
printf("DC current in resistor %s: %e\n", inst->RESname, inst->REScurrent);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (data->delFreq == 0.0) {
|
noizDens[RESFLNOIZ] *= inst->RESm * model->RESfNcoef *
|
||||||
|
pow(fabs(inst->REScurrent / inst->RESm), model->RESfNexp) /
|
||||||
|
(inst->RESeffNoiseArea * pow(data->freq, model->RESef));
|
||||||
|
lnNdens[RESFLNOIZ] = log(MAX(noizDens[RESFLNOIZ], N_MINLOG));
|
||||||
|
|
||||||
|
noizDens[RESTOTNOIZ] = noizDens[RESTHNOIZ] + noizDens[RESFLNOIZ];
|
||||||
|
lnNdens[RESTOTNOIZ] = log(noizDens[RESTOTNOIZ]);
|
||||||
|
|
||||||
|
*OnDens += noizDens[RESTOTNOIZ];
|
||||||
|
|
||||||
|
if (data->delFreq == 0.0) {
|
||||||
|
|
||||||
/* if we haven't done any previous integration, we need to */
|
/* if we haven't done any previous integration, we need to */
|
||||||
/* initialize our "history" variables */
|
/* initialize our "history" variables */
|
||||||
|
|
||||||
for (i=0; i < RESNSRCS; i++) {
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
|
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear out our integration variable if it's the first pass */
|
/* clear out our integration variable if it's the first pass */
|
||||||
|
|
||||||
if (data->freq == job->NstartFreq) {
|
if (data->freq == job->NstartFreq) {
|
||||||
for (i=0; i < RESNSRCS; i++) {
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
inst->RESnVar[OUTNOIZ][i] = 0.0; /* Clear output noise */
|
inst->RESnVar[OUTNOIZ][i] = 0.0; /* Clear output noise */
|
||||||
inst->RESnVar[INNOIZ][i] = 0.0; /* Clear input noise */
|
inst->RESnVar[INNOIZ][i] = 0.0; /* Clear input noise */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* data->delFreq != 0.0 (we have to integrate) */
|
} else {
|
||||||
|
/* data->delFreq != 0.0 (we have to integrate) */
|
||||||
/* In order to get the best curve fit, we have to integrate each component separately */
|
|
||||||
|
|
||||||
for (i = 0; i < RESNSRCS; i++) {
|
/* In order to get the best curve fit, we have to integrate each component separately */
|
||||||
if (i != RESTOTNOIZ) {
|
|
||||||
tempOutNoise = Nintegrate(noizDens[i], lnNdens[i],
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
inst->RESnVar[LNLSTDENS][i], data);
|
if (i != RESTOTNOIZ) {
|
||||||
tempInNoise = Nintegrate(noizDens[i] *
|
tempOutNoise = Nintegrate(noizDens[i], lnNdens[i],
|
||||||
data->GainSqInv ,lnNdens[i]
|
inst->RESnVar[LNLSTDENS][i], data);
|
||||||
+ data->lnGainInv,
|
tempInNoise = Nintegrate(noizDens[i] *
|
||||||
inst->RESnVar[LNLSTDENS][i]
|
data->GainSqInv, lnNdens[i] +
|
||||||
+ data->lnGainInv,
|
data->lnGainInv,
|
||||||
data);
|
inst->RESnVar[LNLSTDENS][i] +
|
||||||
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
|
data->lnGainInv,
|
||||||
data->outNoiz += tempOutNoise;
|
data);
|
||||||
data->inNoise += tempInNoise;
|
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
|
||||||
if (job->NStpsSm != 0) {
|
data->outNoiz += tempOutNoise;
|
||||||
inst->RESnVar[OUTNOIZ][i] += tempOutNoise;
|
data->inNoise += tempInNoise;
|
||||||
inst->RESnVar[OUTNOIZ][RESTOTNOIZ] += tempOutNoise;
|
if (job->NStpsSm != 0) {
|
||||||
inst->RESnVar[INNOIZ][i] += tempInNoise;
|
inst->RESnVar[OUTNOIZ][i] += tempOutNoise;
|
||||||
inst->RESnVar[INNOIZ][RESTOTNOIZ] += tempInNoise;
|
inst->RESnVar[OUTNOIZ][RESTOTNOIZ] += tempOutNoise;
|
||||||
|
inst->RESnVar[INNOIZ][i] += tempInNoise;
|
||||||
|
inst->RESnVar[INNOIZ][RESTOTNOIZ] += tempInNoise;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
if (data->prtSummary) {
|
if (data->prtSummary) {
|
||||||
for (i=0; i < RESNSRCS; i++) { /* print a summary report */
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
|
/* print a summary report */
|
||||||
data->outpVector[data->outNumber++] = noizDens[i];
|
data->outpVector[data->outNumber++] = noizDens[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT_NOIZ: /* already calculated, just output */
|
case INT_NOIZ:
|
||||||
|
/* already calculated, just output */
|
||||||
if (job->NStpsSm != 0) {
|
if (job->NStpsSm != 0) {
|
||||||
for (i=0; i < RESNSRCS; i++) {
|
for (i = 0; i < RESNSRCS; i++) {
|
||||||
data->outpVector[data->outNumber++] = inst->RESnVar[OUTNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->RESnVar[OUTNOIZ][i];
|
||||||
data->outpVector[data->outNumber++] = inst->RESnVar[INNOIZ][i];
|
data->outpVector[data->outNumber++] = inst->RESnVar[INNOIZ][i];
|
||||||
}
|
}
|
||||||
} /* if */
|
} /* if */
|
||||||
break;
|
break;
|
||||||
} /* switch (mode) */
|
} /* switch (mode) */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case N_CLOSE:
|
case N_CLOSE:
|
||||||
return (OK); /* do nothing, the main calling routine will close */
|
return (OK); /* do nothing, the main calling routine will close */
|
||||||
break; /* the plots */
|
break; /* the plots */
|
||||||
} /* switch (operation) */
|
} /* switch (operation) */
|
||||||
} /* for inst */
|
} /* for inst */
|
||||||
} /* for model */
|
} /* for model */
|
||||||
|
|
||||||
return(OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue