My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
photodiode.core.cpp
Go to the documentation of this file.
1 /*
2  * photodiode.core.cpp - device implementations for photodiode module
3  *
4  * This is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  */
10 
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
16 #include "component.h"
17 #include "device.h"
18 #include "photodiode.core.h"
19 
20 #ifndef CIR_photodiode
21 #define CIR_photodiode -1
22 #endif
23 
24 // external nodes
25 #define Anode 0
26 #define Cathode 1
27 #define Light 2
28 // internal nodes
29 #define n1 3
30 
31 // useful macro definitions
32 #define NP(node) real (getV (node))
33 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
34 #define _load_static_residual2(pnode,nnode,current)\
35  _rhs[pnode] -= current;\
36  _rhs[nnode] += current;
37 #define _load_static_augmented_residual2(pnode,nnode,current)\
38  _rhs[pnode] -= current;\
39  _rhs[nnode] += current;
40 #define _load_static_residual1(node,current)\
41  _rhs[node] -= current;
42 #define _load_static_augmented_residual1(node,current)\
43  _rhs[node] -= current;
44 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
45  _jstat[pnode][vpnode] += conductance;\
46  _jstat[nnode][vnnode] += conductance;\
47  _jstat[pnode][vnnode] -= conductance;\
48  _jstat[nnode][vpnode] -= conductance;\
49  if (doHB) {\
50  _ghs[pnode] += conductance * BP(vpnode,vnnode);\
51  _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
52  } else {\
53  _rhs[pnode] += conductance * BP(vpnode,vnnode);\
54  _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
55  }
56 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
57  _jstat[node][vpnode] += conductance;\
58  _jstat[node][vnnode] -= conductance;\
59  if (doHB) {\
60  _ghs[node] += conductance * BP(vpnode,vnnode);\
61  } else {\
62  _rhs[node] += conductance * BP(vpnode,vnnode);\
63  }
64 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
65  _jstat[pnode][node] += conductance;\
66  _jstat[nnode][node] -= conductance;\
67  if (doHB) {\
68  _ghs[pnode] += conductance * NP(node);\
69  _ghs[nnode] -= conductance * NP(node);\
70  } else {\
71  _rhs[pnode] += conductance * NP(node);\
72  _rhs[nnode] -= conductance * NP(node);\
73  }
74 #define _load_static_jacobian1(node,vnode,conductance)\
75  _jstat[node][vnode] += conductance;\
76  if (doHB) {\
77  _ghs[node] += conductance * NP(vnode);\
78  } else {\
79  _rhs[node] += conductance * NP(vnode);\
80  }
81 #define _load_dynamic_residual2(pnode,nnode,charge)\
82  if (doTR) _charges[pnode][nnode] += charge;\
83  if (doHB) {\
84  _qhs[pnode] -= charge;\
85  _qhs[nnode] += charge;\
86  }
87 #define _load_dynamic_residual1(node,charge)\
88  if (doTR) _charges[node][node] += charge;\
89  if (doHB) {\
90  _qhs[node] -= charge;\
91  }
92 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
93  if (doAC) {\
94  _jdyna[pnode][vpnode] += capacitance;\
95  _jdyna[nnode][vnnode] += capacitance;\
96  _jdyna[pnode][vnnode] -= capacitance;\
97  _jdyna[nnode][vpnode] -= capacitance;\
98  }\
99  if (doTR) {\
100  _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
101  }\
102  if (doHB) {\
103  _chs[pnode] += capacitance * BP(vpnode,vnnode);\
104  _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
105  }
106 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
107  if (doAC) {\
108  _jdyna[pnode][vnode] += capacitance;\
109  _jdyna[nnode][vnode] -= capacitance;\
110  }\
111  if (doTR) {\
112  _caps[pnode][nnode][vnode][vnode] += capacitance;\
113  }\
114  if (doHB) {\
115  _chs[pnode] += capacitance * NP(vnode);\
116  _chs[nnode] -= capacitance * NP(vnode);\
117  }
118 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
119  if (doAC) {\
120  _jdyna[node][vpnode] += capacitance;\
121  _jdyna[node][vnnode] -= capacitance;\
122  }\
123  if (doTR) {\
124  _caps[node][node][vpnode][vnnode] += capacitance;\
125  }\
126  if (doHB) {\
127  _chs[node] += capacitance * BP(vpnode,vnnode);\
128  }
129 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
130  if (doAC) {\
131  _jdyna[node][vnode] += capacitance;\
132  }\
133  if (doTR) {\
134  _caps[node][node][vnode][vnode] += capacitance;\
135  }\
136  if (doHB) {\
137  _chs[node] += capacitance * NP(vnode);\
138  }
139 
140 #define _save_whitenoise1(n1,pwr,type)\
141  _white_pwr[n1][n1] += pwr;
142 #define _save_whitenoise2(n1,n2,pwr,type)\
143  _white_pwr[n1][n2] += pwr;
144 #define _save_flickernoise1(n1,pwr,exp,type)\
145  _flicker_pwr[n1][n1] += pwr;\
146  _flicker_exp[n1][n1] += exp;
147 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
148  _flicker_pwr[n1][n2] += pwr;\
149  _flicker_exp[n1][n2] += exp;
150 #define _load_whitenoise2(n1,n2,pwr)\
151  cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
152  cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
153 #define _load_whitenoise1(n1,pwr)\
154  cy (n1,n1) += pwr/kB/T0;
155 #define _load_flickernoise2(n1,n2,pwr,exp)\
156  cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
157  cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
158  cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
159  cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
160 #define _load_flickernoise1(n1,pwr,exp)\
161  cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
162 
163 // derivative helper macros
164 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
165 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
166 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
167 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
168 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
169 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
170 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
171 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
172 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
173 #define m00_pow(v00,x,y) v00 = pow(x,y);
174 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
175 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
176 
177 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
178 #define m10_div(v10,v00,vv,x,y)
179 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
180 
181 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
182 #define m00_add(v00,x,y) double v00=(x)+(y);
183 
184 #define m00_cos(v00,x) v00 = cos(x);
185 #define m10_cos(v10,v00,x) v10 = (-sin(x));
186 #define m00_sin(v00,x) v00 = sin(x);
187 #define m10_sin(v10,v00,x) v10 = (cos(x));
188 #define m00_tan(v00,x) v00 = tan(x);
189 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
190 #define m00_cosh(v00,x) v00 = cosh(x);
191 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
192 #define m00_sinh(v00,x) v00 = sinh(x);
193 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
194 #define m00_tanh(v00,x) v00 = tanh(x);
195 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
196 #define m00_acos(v00,x) v00 = acos(x);
197 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
198 #define m00_asin(v00,x) v00 = asin(x);
199 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
200 #define m00_atan(v00,x) v00 = atan(x);
201 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
202 #define m00_atanh(v00,x) v00 = atanh(x);
203 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
204 #define m00_logE(v00,x) v00 = log(x);
205 #define m10_logE(v10,v00,x) v10 = (1.0/x);
206 #define m00_log10(v00,x) v00 = log10(x);
207 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
208 #define m00_sqrt(v00,x) v00 = sqrt(x);
209 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
210 #define m00_fabs(v00,x) v00 = fabs(x);
211 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
212 
213 #define m00_exp(v00,x) v00 = exp(x);
214 #define m10_exp(v10,v00,x) v10 = v00;
215 
216 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
217 #define m00_floor(v00,x) v00 = floor(x);
218 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
219 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
220 
221 #define m20_logE(v00) (-1.0/v00/v00)
222 #define m20_exp(v00) exp(v00)
223 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
224 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
225 #define m20_fabs(v00) 0.0
226 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
227 #define m00_vt(x) (kBoverQ*(x))
228 #define m10_vt(x) (kBoverQ)
229 
230 // simulator specific definitions
231 #define _modelname "photodiode"
232 #define _instancename getName()
233 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
234 #define _param_given(p) (isPropertyGiven(p)?1:0)
235 
236 
237 // $vt and $vt() functions
238 #define _vt_nom (kBoverQ*_circuit_temp)
239 
240 using namespace device;
241 
242 /* Device constructor. */
244 {
245  type = CIR_photodiode;
246 }
247 
248 /* Initialization of model. */
249 void photodiode::initModel (void)
250 {
251  // create internal nodes
252  setInternalNode (n1, "n1");
253 
254  // get device model parameters
255  loadVariables ();
256  // evaluate global model equations
257  initializeModel ();
258  // evaluate initial step equations
259  initialStep ();
260  // evaluate global instance equations
261  initializeInstance ();
262 }
263 
264 /* Initialization of DC analysis. */
266 {
267  allocMatrixMNA ();
268  initModel ();
269  pol = 1;
270  restartDC ();
271  doAC = 1;
272  doTR = 0;
273  doHB = 0;
274 }
275 
276 /* Run when DC is restarted (fallback algorithms). */
278 {
279 }
280 
281 /* Initialize Verilog-AMS code. */
282 void photodiode::initVerilog (void)
283 {
284  // initialization of noise variables
285  _white_pwr[Anode][n1] = 0.0;
286  _white_pwr[n1][Cathode] = 0.0;
287  _flicker_pwr[n1][Cathode] = 0.0;
288  _flicker_exp[n1][Cathode] = 0.0;
289 
290  int i1, i2, i3, i4;
291 
292  // zero charges
293  for (i1 = 0; i1 < 4; i1++) {
294  for (i2 = 0; i2 < 4; i2++) {
295  _charges[i1][i2] = 0.0;
296  } }
297 
298  // zero capacitances
299  for (i1 = 0; i1 < 4; i1++) {
300  for (i2 = 0; i2 < 4; i2++) {
301  for (i3 = 0; i3 < 4; i3++) {
302  for (i4 = 0; i4 < 4; i4++) {
303  _caps[i1][i2][i3][i4] = 0.0;
304  } } } }
305 
306  // zero right hand side, static and dynamic jacobian
307  for (i1 = 0; i1 < 4; i1++) {
308  _rhs[i1] = 0.0;
309  _qhs[i1] = 0.0;
310  _chs[i1] = 0.0;
311  _ghs[i1] = 0.0;
312  for (i2 = 0; i2 < 4; i2++) {
313  _jstat[i1][i2] = 0.0;
314  _jdyna[i1][i2] = 0.0;
315  }
316  }
317 }
318 
319 /* Load device model input parameters. */
320 void photodiode::loadVariables (void)
321 {
322  N = getPropertyDouble ("N");
323  Rseries = getPropertyDouble ("Rseries");
324  Is = getPropertyDouble ("Is");
325  Bv = getPropertyDouble ("Bv");
326  Ibv = getPropertyDouble ("Ibv");
327  Vj = getPropertyDouble ("Vj");
328  Cj0 = getPropertyDouble ("Cj0");
329  M = getPropertyDouble ("M");
330  Area = getPropertyDouble ("Area");
331  Tnom = getPropertyDouble ("Tnom");
332  Fc = getPropertyDouble ("Fc");
333  Tt = getPropertyDouble ("Tt");
334  Xti = getPropertyDouble ("Xti");
335  Eg = getPropertyDouble ("Eg");
336  Responsivity = getPropertyDouble ("Responsivity");
337  Rsh = getPropertyDouble ("Rsh");
338  QEpercent = getPropertyDouble ("QEpercent");
339  Lambda = getPropertyDouble ("Lambda");
340  LEVEL = getPropertyInteger ("LEVEL");
341  Kf = getPropertyDouble ("Kf");
342  Af = getPropertyDouble ("Af");
343  Ffe = getPropertyDouble ("Ffe");
344 }
345 
346 /* #define's for translated code */
347 #undef _DDT
348 #define _DDT(q) q
349 #define _DYNAMIC
350 #define _DERIVATE
351 #define _DDX
352 #define _DERIVATEFORDDX
353 
354 /* Evaluate Verilog-AMS equations in model initialization. */
355 void photodiode::initializeModel (void)
356 {
357 }
358 
359 /* Evaluate Verilog-AMS equations in instance initialization. */
360 void photodiode::initializeInstance (void)
361 {
362 }
363 
364 /* Evaluate Verilog-AMS equations in initial step. */
365 void photodiode::initialStep (void)
366 {
367 #if defined(_DYNAMIC)
368 #endif
369 #if defined(_DYNAMIC)
370 #endif
371 #if defined(_DYNAMIC)
372 #endif
373 double Res2;
374 double Res1;
375 double Is_T2;
376 #if defined(_DYNAMIC)
377 double Cj0_T2;
378 #endif
379 #if defined(_DYNAMIC)
380 #endif
381 #if defined(_DYNAMIC)
382 double Eg_T2;
383 #endif
384 double Eg_T1;
385 #if defined(_DYNAMIC)
386 #endif
387 #if defined(_DYNAMIC)
388 #endif
389 #if defined(_DYNAMIC)
390 #endif
391 double Vt;
392 double T2;
393 double T1;
394 double B;
395 double A;
396 {
397 Rseries_Area=((Rseries+1e-10)/Area);
398 A=7.02e-4;
399 B=1108.0;
400 T1=(Tnom+273.15);
401 T2=_circuit_temp;
402 Vt=((1.3806503e-23*300.0)/1.602176462e-19);
403 Vt_T2=((1.3806503e-23*T2)/1.602176462e-19);
404 #if defined(_DYNAMIC)
405 {
406 double m00_pow(d00_pow0,(1-Fc),(1-M))
407 F1=((Vj/(1-M))*(1-d00_pow0));
408 }
409 #endif
410 #if defined(_DYNAMIC)
411 {
412 double m00_pow(d00_pow0,(1-Fc),(1+M))
413 F2=d00_pow0;
414 }
415 #endif
416 #if defined(_DYNAMIC)
417 F3=(1-(Fc*(1+M)));
418 #endif
419 Eg_T1=(Eg-(((A*T1)*T1)/(B+T1)));
420 #if defined(_DYNAMIC)
421 Eg_T2=(Eg-(((A*T2)*T2)/(B+T2)));
422 #endif
423 #if defined(_DYNAMIC)
424 {
425 double m00_pow(d00_pow0,(T2/T1),1.5)
426 double m00_logE(d00_logE1,d00_pow0)
427 Vj_T2=((((T2/T1)*Vj)-((2*_vt_nom)*d00_logE1))-(((T2/T1)*Eg_T1)-Eg_T2));
428 }
429 #endif
430 GMIN=1e-12;
431 #if defined(_DYNAMIC)
432 Cj0_T2=(Cj0*(1+(M*((400e-6*(T2-T1))-((Vj_T2-Vj)/Vj)))));
433 #endif
434 {
435 double m00_pow(d00_pow0,(T2/T1),(Xti/N))
436 double m00_limexp(d00_limexp1,(((-Eg_T1)/_vt_nom)*(1-(T2/T1))))
437 Is_T2=((Is*d00_pow0)*d00_limexp1);
438 }
439 Res1=((QEpercent!=0)?((QEpercent*Lambda)/1.2398e5):Responsivity);
440 Res2=((QEpercent*Lambda)/1.2938e5);
441 Res=((LEVEL==1)?Res1:Res2);
442 con1=(((-5.0)*N)*Vt);
443 con2=(Area*Is_T2);
444 #if defined(_DYNAMIC)
445 con3=(Area*Cj0_T2);
446 #endif
447 #if defined(_DYNAMIC)
448 con4=(Fc*Vj);
449 #endif
450 #if defined(_DYNAMIC)
451 con5=(Fc*Vj_T2);
452 #endif
453 con6=(Bv/Vt_T2);
454 }
455 }
456 
457 /* Evaluate Verilog-AMS equations in final step. */
458 void photodiode::finalStep (void)
459 {
460 }
461 
462 /* Evaluate Verilog-AMS equations in analog block. */
463 void photodiode::calcVerilog (void)
464 {
465 
466 /* ----------------- evaluate verilog analog equations -------------------- */
467 double I_flicker;
468 #if defined(_DERIVATE)
469 double I_flicker_Vn1_Cathode;
470 #endif
471 double TwoQ;
472 double fourkt;
473 double Id;
474 #if defined(_DERIVATE)
475 double Id_Vn1_Cathode;
476 #endif
477 double I5;
478 #if defined(_DERIVATE)
479 double I5_VLight_GND;
480 #endif
481 #if defined(_DYNAMIC)
482 double Q2;
483 #if defined(_DERIVATE)
484 double Q2_Vn1_Cathode;
485 #endif
486 #endif
487 #if defined(_DYNAMIC)
488 double Q1;
489 #if defined(_DERIVATE)
490 double Q1_Vn1_Cathode;
491 #endif
492 #endif
493 double I4;
494 #if defined(_DERIVATE)
495 double I4_Vn1_Cathode;
496 #endif
497 double I3;
498 #if defined(_DERIVATE)
499 double I3_Vn1_Cathode;
500 #endif
501 double I2;
502 #if defined(_DERIVATE)
503 double I2_Vn1_Cathode;
504 #endif
505 double I1;
506 #if defined(_DERIVATE)
507 double I1_Vn1_Cathode;
508 #endif
509 double V1;
510 #if defined(_DERIVATE)
511 double V1_Vn1_Cathode;
512 #endif
513 #if defined(_DERIVATE)
514 V1_Vn1_Cathode=1.0;
515 #endif
516 V1=BP(n1,Cathode);
517 {
518 double m00_limexp(d00_limexp0,(V1/(N*Vt_T2)))
519 #if defined(_DERIVATE)
520 double m10_limexp(d10_limexp0,d00_limexp0,(V1/(N*Vt_T2)))
521 #endif
522 #if defined(_DERIVATE)
523 I1_Vn1_Cathode=((V1>con1)?((con2*(V1_Vn1_Cathode/(N*Vt_T2))*d10_limexp0)+(GMIN*V1_Vn1_Cathode)):0.0);
524 #endif
525 I1=((V1>con1)?((con2*(d00_limexp0-1.0))+(GMIN*V1)):0);
526 }
527 #if defined(_DERIVATE)
528 I2_Vn1_Cathode=((V1<=con1)?(GMIN*V1_Vn1_Cathode):0.0);
529 #endif
530 I2=((V1<=con1)?((-con2)+(GMIN*V1)):0);
531 #if defined(_DERIVATE)
532 I3_Vn1_Cathode=((V1==(-Bv))?0.0:0.0);
533 #endif
534 I3=((V1==(-Bv))?(-Ibv):0);
535 {
536 double m00_limexp(d00_limexp0,((-(Bv+V1))/Vt_T2))
537 #if defined(_DERIVATE)
538 double m10_limexp(d10_limexp0,d00_limexp0,((-(Bv+V1))/Vt_T2))
539 #endif
540 #if defined(_DERIVATE)
541 I4_Vn1_Cathode=((V1<(-Bv))?((-con2)*((-V1_Vn1_Cathode)/Vt_T2)*d10_limexp0):0.0);
542 #endif
543 I4=((V1<(-Bv))?((-con2)*((d00_limexp0-1.0)+con6)):0);
544 }
545 #if defined(_DYNAMIC)
546 {
547 double m00_pow(d00_pow0,(1-(V1/Vj_T2)),(1-M))
548 #if defined(_DERIVATE)
549 double m10_pow(d10_pow0,d00_pow0,(1-(V1/Vj_T2)),(1-M))
550 #endif
551 #if defined(_DERIVATE)
552 Q1_Vn1_Cathode=((V1<con4)?((Tt*I1_Vn1_Cathode)+((con3*(Vj_T2/(1-M)))*(-(d10_pow0*(-(V1_Vn1_Cathode/Vj_T2)))))):0.0);
553 #endif
554 Q1=((V1<con4)?((Tt*I1)+((con3*(Vj_T2/(1-M)))*(1-d00_pow0))):0);
555 }
556 #endif
557 #if defined(_DYNAMIC)
558 #if defined(_DERIVATE)
559 Q2_Vn1_Cathode=((V1>=con4)?((Tt*I1_Vn1_Cathode)+(con3*((1/F2)*((F3*V1_Vn1_Cathode)+((M/(2.0*Vj_T2))*((V1_Vn1_Cathode*V1)+(V1*V1_Vn1_Cathode))))))):0.0);
560 #endif
561 Q2=((V1>=con4)?((Tt*I1)+(con3*(F1+((1/F2)*((F3*(V1-con5))+((M/(2.0*Vj_T2))*((V1*V1)-(con5*con5)))))))):0);
562 #endif
563 #if defined(_DERIVATE)
564 I5_VLight_GND=(Res);
565 #endif
566 I5=(NP(Light)*Res);
567 #if defined(_DERIVATE)
568 Id_Vn1_Cathode=(((I1_Vn1_Cathode+I2_Vn1_Cathode)+I3_Vn1_Cathode)+I4_Vn1_Cathode);
569 #endif
570 Id=(((I1+I2)+I3)+I4);
572 #if defined(_DERIVATE)
573 _load_static_jacobian2s(n1,Cathode,Light,(-I5_VLight_GND));
574 #endif
576 #if defined(_DERIVATE)
578 #endif
579 _load_static_residual2(Anode,n1,(BP(Anode,n1)/Rseries_Area));
580 #if defined(_DERIVATE)
581 _load_static_jacobian4(Anode,n1,Anode,n1,(1/Rseries_Area));
582 #endif
584 #if defined(_DERIVATE)
585 _load_static_jacobian4(n1,Cathode,n1,Cathode,Id_Vn1_Cathode);
586 #endif
587 #if defined(_DYNAMIC)
589 #if defined(_DERIVATE)
590 _load_dynamic_jacobian4(n1,Cathode,n1,Cathode,(Q1_Vn1_Cathode+Q2_Vn1_Cathode));
591 #endif
592 #endif
594 #if defined(_DERIVATE)
596 #endif
597 fourkt=((4.0*1.3806503e-23)*_circuit_temp);
598 TwoQ=(2.0*1.602176462e-19);
599 {
600 double m00_pow(d00_pow0,Id,Af)
601 #if defined(_DERIVATE)
602 double m10_pow(d10_pow0,d00_pow0,Id,Af)
603 #endif
604 #if defined(_DERIVATE)
605 I_flicker_Vn1_Cathode=(d10_pow0*Id_Vn1_Cathode);
606 #endif
607 I_flicker=d00_pow0;
608 }
609 _save_whitenoise2(Anode,n1,(fourkt/Rseries_Area),"thermal");
610 _save_whitenoise2(n1,Cathode,(fourkt/Rsh),"thermal");
611 _save_whitenoise2(n1,Cathode,(TwoQ*Id),"shot");
612 _save_flickernoise2(n1,Cathode,(Kf*I_flicker),Ffe,"flicker");
613 _save_whitenoise2(n1,Cathode,(TwoQ*I5),"shot");
614 
615 /* ------------------ end of verilog analog equations --------------------- */
616 
617 /* ------------------ evaluate verilog noise equations -------------------- */
618 
619 /* ------------------- end of verilog noise equations --------------------- */
620 }
621 
622 /* Perform DC iteration. */
624 {
625  // evaluate Verilog code
626  initVerilog ();
627  calcVerilog ();
628 
629  // fill right hand side and static jacobian
630  for (int i1 = 0; i1 < 4; i1++) {
631  setI (i1, _rhs[i1]);
632  for (int i2 = 0; i2 < 4; i2++) {
633  setY (i1, i2, _jstat[i1][i2]);
634  }
635  }
636 }
637 
638 /* Save operating points. */
640 {
641  // save global instance operating points
642  setOperatingPoint ("F1", F1);
643  setOperatingPoint ("F2", F2);
644  setOperatingPoint ("F3", F3);
645  setOperatingPoint ("Rseries_Area", Rseries_Area);
646  setOperatingPoint ("Vt_T2", Vt_T2);
647  setOperatingPoint ("Vj_T2", Vj_T2);
648  setOperatingPoint ("GMIN", GMIN);
649  setOperatingPoint ("Res", Res);
650  setOperatingPoint ("con1", con1);
651  setOperatingPoint ("con2", con2);
652  setOperatingPoint ("con3", con3);
653  setOperatingPoint ("con4", con4);
654  setOperatingPoint ("con5", con5);
655  setOperatingPoint ("con6", con6);
656 }
657 
658 /* Load operating points. */
660 {
661 }
662 
663 /* Calculate operating points. */
665 {
666 }
667 
668 /* Initialization of AC analysis. */
670 {
671  allocMatrixMNA ();
672 }
673 
674 /* Perform AC calculations. */
675 void photodiode::calcAC (nr_double_t frequency)
676 {
677  setMatrixY (calcMatrixY (frequency));
678 }
679 
680 /* Compute Y-matrix for AC analysis. */
681 matrix photodiode::calcMatrixY (nr_double_t frequency)
682 {
683  _freq = frequency;
685  matrix y (4);
686 
687  for (int i1 = 0; i1 < 4; i1++) {
688  for (int i2 = 0; i2 < 4; i2++) {
689  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
690  }
691  }
692 
693  return y;
694 }
695 
696 /* Initialization of S-parameter analysis. */
698 {
699  allocMatrixS ();
700 }
701 
702 /* Perform S-parameter calculations. */
703 void photodiode::calcSP (nr_double_t frequency)
704 {
705  setMatrixS (ytos (calcMatrixY (frequency)));
706 }
707 
708 /* Initialization of transient analysis. */
710 {
711  setStates (2 * 4 * 4);
712  initDC ();
713 }
714 
715 /* Perform transient analysis iteration step. */
716 void photodiode::calcTR (nr_double_t)
717 {
718  doHB = 0;
719  doAC = 1;
720  doTR = 1;
721  calcDC ();
722 
723  int i1, i2, i3, i4, state;
724 
725  // 2-node charge integrations
726  for (i1 = 0; i1 < 4; i1++) {
727  for (i2 = 0; i2 < 4; i2++) {
728  state = 2 * (i2 + 4 * i1);
729  if (i1 != i2)
730  if (_charges[i1][i2] != 0.0)
731  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
732  } }
733 
734  // 1-node charge integrations
735  for (i1 = 0; i1 < 4; i1++) {
736  state = 2 * (i1 + 4 * i1);
737  if (_charges[i1][i1] != 0.0)
738  transientCapacitanceQ (state, i1, _charges[i1][i1]);
739  }
740 
741  // charge: 2-node, voltage: 2-node
742  for (i1 = 0; i1 < 4; i1++) {
743  for (i2 = 0; i2 < 4; i2++) {
744  if (i1 != i2)
745  for (i3 = 0; i3 < 4; i3++) {
746  for (i4 = 0; i4 < 4; i4++) {
747  if (i3 != i4)
748  if (_caps[i1][i2][i3][i4] != 0.0)
749  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
750  } } } }
751 
752  // charge: 2-node, voltage: 1-node
753  for (i1 = 0; i1 < 4; i1++) {
754  for (i2 = 0; i2 < 4; i2++) {
755  if (i1 != i2)
756  for (i3 = 0; i3 < 4; i3++) {
757  if (_caps[i1][i2][i3][i3] != 0.0)
758  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
759  } } }
760 
761  // charge: 1-node, voltage: 2-node
762  for (i1 = 0; i1 < 4; i1++) {
763  for (i3 = 0; i3 < 4; i3++) {
764  for (i4 = 0; i4 < 4; i4++) {
765  if (i3 != i4)
766  if (_caps[i1][i1][i3][i4] != 0.0)
767  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
768  } } }
769 
770  // charge: 1-node, voltage: 1-node
771  for (i1 = 0; i1 < 4; i1++) {
772  for (i3 = 0; i3 < 4; i3++) {
773  if (_caps[i1][i1][i3][i3] != 0.0)
774  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
775  } }
776 }
777 
778 /* Compute Cy-matrix for AC noise analysis. */
779 matrix photodiode::calcMatrixCy (nr_double_t frequency)
780 {
781  _freq = frequency;
782  matrix cy (4);
783 
784  _load_flickernoise2 (n1,Cathode,_flicker_pwr[n1][Cathode],_flicker_exp[n1][Cathode]);
785  _load_whitenoise2 (Anode,n1,_white_pwr[Anode][n1]);
786  _load_whitenoise2 (n1,Cathode,_white_pwr[n1][Cathode]);
787 
788  return cy;
789 }
790 
791 /* Perform AC noise computations. */
792 void photodiode::calcNoiseAC (nr_double_t frequency)
793 {
794  setMatrixN (calcMatrixCy (frequency));
795 }
796 
797 /* Perform S-parameter noise computations. */
798 void photodiode::calcNoiseSP (nr_double_t frequency)
799 {
800  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
801 }
802 
803 /* Initialization of HB analysis. */
805 {
806  initDC ();
807  allocMatrixHB ();
808 }
809 
810 /* Perform HB analysis. */
812 {
813  doHB = 1;
814  doAC = 1;
815  doTR = 0;
816 
817  // jacobian dI/dV and currents get filled
818  calcDC ();
820 
821  // fill in HB matrices
822  for (int i1 = 0; i1 < 4; i1++) {
823  setQ (i1, _qhs[i1]); // charges
824  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
825  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
826  for (int i2 = 0; i2 < 4; i2++) {
827  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
828  }
829  }
830 }
831 
832 #include "photodiode.defs.h"