Jspice3
Main Page
Data Structures
Files
File List
Globals
resnoise.c
Go to the documentation of this file.
1
/***************************************************************************
2
JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3
Copyright 1990 Regents of the University of California. All rights reserved.
4
Authors: 1987 Gary W. Ng
5
1993 Stephen R. Whiteley
6
****************************************************************************/
7
8
#include "
spice.h
"
9
#include <stdio.h>
10
#include <math.h>
11
#include "
resdefs.h
"
12
#include "
noisedef.h
"
13
#include "
fteconst.h
"
14
#include "
iferrmsg.h
"
15
#include "
util.h
"
16
17
/*
18
* RESnoise (mode, operation, firstModel, ckt, data, OnDens)
19
* This routine names and evaluates all of the noise sources
20
* associated with resistors. It starts with the model *firstModel
21
* and traverses all of its instances. It then proceeds to any other
22
* models on the linked list. The total output noise density
23
* generated by all the resistors is summed in the variable "OnDens".
24
*/
25
26
27
int
28
RESnoise
(mode, operation, genmodel, ckt, dataptr, OnDens)
29
30
int mode;
31
int
operation;
32
GENmodel
*genmodel;
33
CKTcircuit
*ckt;
34
GENERIC
*dataptr;
35
double
*OnDens;
36
{
37
Ndata
*data = (
Ndata
*)dataptr;
38
RESmodel
*
model
= (
RESmodel
*) genmodel;
39
RESinstance
*inst;
40
char
name[
N_MXVLNTH
];
41
double
tempOutNoise;
42
double
tempInNoise;
43
double
noizDens;
44
double
lnNdens;
45
int
error;
46
47
if
(operation ==
N_OPEN
) {
48
49
/* see if we have to to produce a summary report
50
* if so, name the noise generator
51
*/
52
53
if
(((
NOISEAN
*)ckt->
CKTcurJob
)->NStpsSm == 0)
54
return
(
OK
);
55
56
if
(mode ==
N_DENS
) {
57
58
for
( ;
model
; model = model->
RESnextModel
) {
59
for
(inst = model->
RESinstances
; inst;
60
inst = inst->
RESnextInstance
) {
61
62
(void)sprintf(name,
"onoise.%s"
,inst->
RESname
);
63
64
data->
namelist
=
65
(
IFuid
*)
trealloc
((
char
*)data->
namelist
,
66
(data->
numPlots
+ 1)*
sizeof
(
IFuid
));
67
68
if
(!data->
namelist
)
69
return
(
E_NOMEM
);
70
71
(*(
SPfrontEnd
->IFnewUid))(ckt,
72
&(data->
namelist
[data->
numPlots
++]),
73
(
IFuid
)
NULL
,name,
UID_OTHER
,(
GENERIC
**)
NULL
);
74
/* we've added one more plot */
75
}
76
}
77
return
(
OK
);
78
}
79
80
if
(mode ==
INT_NOIZ
) {
81
82
for
( ;
model
; model = model->
RESnextModel
) {
83
for
(inst = model->
RESinstances
; inst;
84
inst = inst->
RESnextInstance
) {
85
86
(void)sprintf(name,
"onoise_total.%s"
,inst->
RESname
);
87
88
data->
namelist
=
89
(
IFuid
*)
trealloc
((
char
*)data->
namelist
,
90
(data->
numPlots
+ 1)*
sizeof
(
IFuid
));
91
92
if
(!data->
namelist
)
93
return
(
E_NOMEM
);
94
95
(*(
SPfrontEnd
->IFnewUid))(ckt,
96
&(data->
namelist
[data->
numPlots
++]),
97
(
IFuid
)
NULL
,name,
UID_OTHER
,(
GENERIC
**)
NULL
);
98
/* we've added one more plot */
99
100
(void)sprintf(name,
"inoise_total.%s"
,inst->
RESname
);
101
102
data->
namelist
=
103
(
IFuid
*)
trealloc
((
char
*)data->
namelist
,
104
(data->
numPlots
+ 1)*
sizeof
(
IFuid
));
105
106
if
(!data->
namelist
)
107
return
(
E_NOMEM
);
108
109
(*(
SPfrontEnd
->IFnewUid))(ckt,
110
&(data->
namelist
[data->
numPlots
++]),
111
(
IFuid
)
NULL
,name,
UID_OTHER
,(
GENERIC
**)
NULL
);
112
/* we've added one more plot */
113
}
114
}
115
}
116
return
(
OK
);
117
}
118
119
if
(operation ==
N_CALC
) {
120
121
if
(mode ==
N_DENS
) {
122
123
for
( ;
model
; model = model->
RESnextModel
) {
124
for
(inst = model->
RESinstances
; inst;
125
inst = inst->
RESnextInstance
) {
126
127
NevalSrc
(&noizDens,&lnNdens,ckt,
THERMNOISE
,
128
inst->
RESposNode
,inst->
RESnegNode
,inst->
RESconduct
);
129
130
*OnDens += noizDens;
131
132
if
(data->
delFreq
== 0.0) {
133
134
/* if we haven't done any previous integration,
135
* we need to initialize our "history" variables
136
*/
137
138
inst->
RESnVar
[
LNLSTDENS
] = lnNdens;
139
140
/* clear out our integration variable if it's the
141
* first pass
142
*/
143
144
if
(data->
freq
==
145
((
NOISEAN
*)ckt->
CKTcurJob
)->AC.fstart) {
146
inst->
RESnVar
[
OUTNOIZ
] = 0.0;
147
}
148
}
149
else
{
150
/* data->delFreq != 0.0 (we have to integrate) */
151
tempOutNoise =
Nintegrate
(noizDens, lnNdens,
152
inst->
RESnVar
[
LNLSTDENS
], data);
153
tempInNoise =
Nintegrate
(noizDens *
154
data->
GainSqInv
,lnNdens + data->
lnGainInv
,
155
inst->
RESnVar
[
LNLSTDENS
] + data->
lnGainInv
,
156
data);
157
inst->
RESnVar
[
OUTNOIZ
] += tempOutNoise;
158
inst->
RESnVar
[
INNOIZ
] += tempInNoise;
159
data->
outNoiz
+= tempOutNoise;
160
data->
inNoise
+= tempInNoise;
161
inst->
RESnVar
[
LNLSTDENS
] = lnNdens;
162
}
163
if
(data->
prtSummary
) {
164
data->
outpVector
[data->
outNumber
++] = noizDens;
165
}
166
}
167
}
168
return
(
OK
);
169
}
170
171
if
(mode ==
INT_NOIZ
) {
172
173
if
(((
NOISEAN
*)ckt->
CKTcurJob
)->NStpsSm == 0)
174
return
(
OK
);
175
176
for
( ;
model
; model = model->
RESnextModel
) {
177
for
(inst = model->
RESinstances
; inst;
178
inst = inst->
RESnextInstance
) {
179
180
/* already calculated, just output */
181
data->
outpVector
[data->
outNumber
++] =
182
inst->
RESnVar
[
OUTNOIZ
];
183
data->
outpVector
[data->
outNumber
++] =
184
inst->
RESnVar
[
INNOIZ
];
185
}
186
}
187
}
188
}
189
return
(
OK
);
190
}
191
192
sRESinstance::RESnegNode
int RESnegNode
Definition:
resdefs.h:26
N_MXVLNTH
#define N_MXVLNTH
Definition:
noisedef.h:124
N_OPEN
#define N_OPEN
Definition:
noisedef.h:85
Ndata::outpVector
double * outpVector
Definition:
noisedef.h:33
sRESmodel::RESnextModel
struct sRESmodel * RESnextModel
Definition:
resdefs.h:56
LNLSTDENS
#define LNLSTDENS
Definition:
noisedef.h:62
CKTcircuit
Definition:
cktdefs.h:62
resdefs.h
Ndata::namelist
IFuid * namelist
Definition:
noisedef.h:35
sRESinstance
Definition:
resdefs.h:18
NevalSrc
void NevalSrc()
SPfrontEnd
IFfrontEnd * SPfrontEnd
Definition:
main.c:917
noisedef.h
Ndata::lnGainInv
double lnGainInv
Definition:
noisedef.h:25
INNOIZ
#define INNOIZ
Definition:
noisedef.h:64
sRESinstance::RESposNode
int RESposNode
Definition:
resdefs.h:25
OK
#define OK
Definition:
iferrmsg.h:17
IFuid
GENERIC * IFuid
Definition:
ifsim.h:72
Ndata::prtSummary
unsigned int prtSummary
Definition:
noisedef.h:32
sRESinstance::RESconduct
double RESconduct
Definition:
resdefs.h:29
sRESinstance::RESnVar
double RESnVar[NSTATVARS]
Definition:
resdefs.h:47
NULL
#define NULL
Definition:
spdefs.h:121
INT_NOIZ
#define INT_NOIZ
Definition:
noisedef.h:84
sRESinstance::RESname
IFuid RESname
Definition:
resdefs.h:22
NOISEAN
Definition:
noisedef.h:41
E_NOMEM
#define E_NOMEM
Definition:
iferrmsg.h:27
N_DENS
#define N_DENS
Definition:
noisedef.h:83
util.h
Nintegrate
double Nintegrate()
fteconst.h
spice.h
iferrmsg.h
sGENmodel
Definition:
gendefs.h:39
Ndata::GainSqInv
double GainSqInv
Definition:
noisedef.h:24
sRESmodel
Definition:
resdefs.h:54
model
static char model[32]
Definition:
subckt.c:76
Ndata::outNumber
int outNumber
Definition:
noisedef.h:29
THERMNOISE
#define THERMNOISE
Definition:
noisedef.h:89
UID_OTHER
#define UID_OTHER
Definition:
ifsim.h:85
Ndata::numPlots
int numPlots
Definition:
noisedef.h:30
sRESmodel::RESinstances
RESinstance * RESinstances
Definition:
resdefs.h:58
Ndata::delFreq
double delFreq
Definition:
noisedef.h:21
Ndata::outNoiz
double outNoiz
Definition:
noisedef.h:22
sRESinstance::RESnextInstance
struct sRESinstance * RESnextInstance
Definition:
resdefs.h:20
Ndata::inNoise
double inNoise
Definition:
noisedef.h:23
Ndata::freq
double freq
Definition:
noisedef.h:19
N_CALC
#define N_CALC
Definition:
noisedef.h:86
RESnoise
int RESnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, GENERIC *dataptr, double *OnDens)
Definition:
resnoise.c:28
CKTcircuit::CKTcurJob
JOB * CKTcurJob
Definition:
cktdefs.h:216
OUTNOIZ
#define OUTNOIZ
Definition:
noisedef.h:63
trealloc
char * trealloc()
GENERIC
char GENERIC
Definition:
ifsim.h:27
Ndata
Definition:
noisedef.h:18
src
lib
dev
res
resnoise.c
Generated by
1.8.11