16 #include "component.h"
20 #ifndef CIR_photodiode
21 #define CIR_photodiode -1
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;\
50 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
51 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
53 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
54 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
56 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
57 _jstat[node][vpnode] += conductance;\
58 _jstat[node][vnnode] -= conductance;\
60 _ghs[node] += conductance * BP(vpnode,vnnode);\
62 _rhs[node] += conductance * BP(vpnode,vnnode);\
64 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
65 _jstat[pnode][node] += conductance;\
66 _jstat[nnode][node] -= conductance;\
68 _ghs[pnode] += conductance * NP(node);\
69 _ghs[nnode] -= conductance * NP(node);\
71 _rhs[pnode] += conductance * NP(node);\
72 _rhs[nnode] -= conductance * NP(node);\
74 #define _load_static_jacobian1(node,vnode,conductance)\
75 _jstat[node][vnode] += conductance;\
77 _ghs[node] += conductance * NP(vnode);\
79 _rhs[node] += conductance * NP(vnode);\
81 #define _load_dynamic_residual2(pnode,nnode,charge)\
82 if (doTR) _charges[pnode][nnode] += charge;\
84 _qhs[pnode] -= charge;\
85 _qhs[nnode] += charge;\
87 #define _load_dynamic_residual1(node,charge)\
88 if (doTR) _charges[node][node] += charge;\
90 _qhs[node] -= charge;\
92 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
94 _jdyna[pnode][vpnode] += capacitance;\
95 _jdyna[nnode][vnnode] += capacitance;\
96 _jdyna[pnode][vnnode] -= capacitance;\
97 _jdyna[nnode][vpnode] -= capacitance;\
100 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
103 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
104 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
106 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
108 _jdyna[pnode][vnode] += capacitance;\
109 _jdyna[nnode][vnode] -= capacitance;\
112 _caps[pnode][nnode][vnode][vnode] += capacitance;\
115 _chs[pnode] += capacitance * NP(vnode);\
116 _chs[nnode] -= capacitance * NP(vnode);\
118 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
120 _jdyna[node][vpnode] += capacitance;\
121 _jdyna[node][vnnode] -= capacitance;\
124 _caps[node][node][vpnode][vnnode] += capacitance;\
127 _chs[node] += capacitance * BP(vpnode,vnnode);\
129 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
131 _jdyna[node][vnode] += capacitance;\
134 _caps[node][node][vnode][vnode] += capacitance;\
137 _chs[node] += capacitance * NP(vnode);\
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;
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));
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;
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);
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));
213 #define m00_exp(v00,x) v00 = exp(x);
214 #define m10_exp(v10,v00,x) v10 = v00;
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));
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)
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)
238 #define _vt_nom (kBoverQ*_circuit_temp)
240 using namespace device;
249 void photodiode::initModel (
void)
261 initializeInstance ();
282 void photodiode::initVerilog (
void)
293 for (i1 = 0; i1 < 4; i1++) {
294 for (i2 = 0; i2 < 4; i2++) {
295 _charges[i1][i2] = 0.0;
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;
307 for (i1 = 0; i1 < 4; i1++) {
312 for (i2 = 0; i2 < 4; i2++) {
313 _jstat[i1][i2] = 0.0;
314 _jdyna[i1][i2] = 0.0;
320 void photodiode::loadVariables (
void)
352 #define _DERIVATEFORDDX
355 void photodiode::initializeModel (
void)
360 void photodiode::initializeInstance (
void)
365 void photodiode::initialStep (
void)
367 #if defined(_DYNAMIC)
369 #if defined(_DYNAMIC)
371 #if defined(_DYNAMIC)
376 #if defined(_DYNAMIC)
379 #if defined(_DYNAMIC)
381 #if defined(_DYNAMIC)
385 #if defined(_DYNAMIC)
387 #if defined(_DYNAMIC)
389 #if defined(_DYNAMIC)
397 Rseries_Area=((Rseries+1
e-10)/
Area);
402 Vt=((1.3806503e-23*300.0)/1.602176462e-19);
403 Vt_T2=((1.3806503e-23*T2)/1.602176462
e-19);
404 #if defined(_DYNAMIC)
406 double m00_pow(d00_pow0,(1-Fc),(1-M))
407 F1=((Vj/(1-M))*(1-d00_pow0));
410 #if defined(_DYNAMIC)
412 double m00_pow(d00_pow0,(1-Fc),(1+M))
416 #if defined(_DYNAMIC)
419 Eg_T1=(Eg-(((A*T1)*T1)/(B+T1)));
420 #if defined(_DYNAMIC)
421 Eg_T2=(Eg-(((A*T2)*T2)/(B+T2)));
423 #if defined(_DYNAMIC)
425 double m00_pow(d00_pow0,(T2/T1),1.5)
427 Vj_T2=((((T2/T1)*Vj)-((2*
_vt_nom)*d00_logE1))-(((T2/T1)*Eg_T1)-Eg_T2));
431 #if defined(_DYNAMIC)
432 Cj0_T2=(Cj0*(1+(M*((400
e-6*(T2-T1))-((Vj_T2-Vj)/Vj)))));
435 double m00_pow(d00_pow0,(T2/T1),(Xti/N))
437 Is_T2=((Is*d00_pow0)*d00_limexp1);
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);
444 #if defined(_DYNAMIC)
447 #if defined(_DYNAMIC)
450 #if defined(_DYNAMIC)
458 void photodiode::finalStep (
void)
463 void photodiode::calcVerilog (
void)
468 #if defined(_DERIVATE)
469 double I_flicker_Vn1_Cathode;
474 #if defined(_DERIVATE)
475 double Id_Vn1_Cathode;
478 #if defined(_DERIVATE)
479 double I5_VLight_GND;
481 #if defined(_DYNAMIC)
483 #if defined(_DERIVATE)
484 double Q2_Vn1_Cathode;
487 #if defined(_DYNAMIC)
489 #if defined(_DERIVATE)
490 double Q1_Vn1_Cathode;
494 #if defined(_DERIVATE)
495 double I4_Vn1_Cathode;
498 #if defined(_DERIVATE)
499 double I3_Vn1_Cathode;
502 #if defined(_DERIVATE)
503 double I2_Vn1_Cathode;
506 #if defined(_DERIVATE)
507 double I1_Vn1_Cathode;
510 #if defined(_DERIVATE)
511 double V1_Vn1_Cathode;
513 #if defined(_DERIVATE)
519 #if defined(_DERIVATE)
520 double m10_limexp(d10_limexp0,d00_limexp0,(V1/(N*Vt_T2)))
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);
525 I1=((V1>con1)?((con2*(d00_limexp0-1.0))+(GMIN*V1)):0);
527 #if defined(_DERIVATE)
528 I2_Vn1_Cathode=((V1<=con1)?(GMIN*V1_Vn1_Cathode):0.0);
530 I2=((V1<=con1)?((-con2)+(GMIN*V1)):0);
531 #if defined(_DERIVATE)
532 I3_Vn1_Cathode=((V1==(-Bv))?0.0:0.0);
534 I3=((V1==(-Bv))?(-Ibv):0);
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))
540 #if defined(_DERIVATE)
541 I4_Vn1_Cathode=((V1<(-Bv))?((-con2)*((-V1_Vn1_Cathode)/Vt_T2)*d10_limexp0):0.0);
543 I4=((V1<(-Bv))?((-con2)*((d00_limexp0-1.0)+con6)):0);
545 #if defined(_DYNAMIC)
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))
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);
554 Q1=((V1<con4)?((Tt*I1)+((con3*(Vj_T2/(1-M)))*(1-d00_pow0))):0);
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);
561 Q2=((V1>=con4)?((Tt*I1)+(con3*(F1+((1/F2)*((F3*(V1-con5))+((M/(2.0*Vj_T2))*((V1*V1)-(con5*con5)))))))):0);
563 #if defined(_DERIVATE)
567 #if defined(_DERIVATE)
568 Id_Vn1_Cathode=(((I1_Vn1_Cathode+I2_Vn1_Cathode)+I3_Vn1_Cathode)+I4_Vn1_Cathode);
570 Id=(((I1+I2)+I3)+I4);
572 #if defined(_DERIVATE)
576 #if defined(_DERIVATE)
580 #if defined(_DERIVATE)
584 #if defined(_DERIVATE)
587 #if defined(_DYNAMIC)
589 #if defined(_DERIVATE)
594 #if defined(_DERIVATE)
598 TwoQ=(2.0*1.602176462e-19);
601 #if defined(_DERIVATE)
602 double m10_pow(d10_pow0,d00_pow0,Id,Af)
604 #if defined(_DERIVATE)
605 I_flicker_Vn1_Cathode=(d10_pow0*Id_Vn1_Cathode);
630 for (
int i1 = 0; i1 < 4; i1++) {
632 for (
int i2 = 0; i2 < 4; i2++) {
633 setY (i1, i2, _jstat[i1][i2]);
681 matrix photodiode::calcMatrixY (nr_double_t frequency)
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);
723 int i1, i2, i3, i4, state;
726 for (i1 = 0; i1 < 4; i1++) {
727 for (i2 = 0; i2 < 4; i2++) {
728 state = 2 * (i2 + 4 * i1);
730 if (_charges[i1][i2] != 0.0)
735 for (i1 = 0; i1 < 4; i1++) {
736 state = 2 * (i1 + 4 * i1);
737 if (_charges[i1][i1] != 0.0)
742 for (i1 = 0; i1 < 4; i1++) {
743 for (i2 = 0; i2 < 4; i2++) {
745 for (i3 = 0; i3 < 4; i3++) {
746 for (i4 = 0; i4 < 4; i4++) {
748 if (_caps[i1][i2][i3][i4] != 0.0)
753 for (i1 = 0; i1 < 4; i1++) {
754 for (i2 = 0; i2 < 4; i2++) {
756 for (i3 = 0; i3 < 4; i3++) {
757 if (_caps[i1][i2][i3][i3] != 0.0)
762 for (i1 = 0; i1 < 4; i1++) {
763 for (i3 = 0; i3 < 4; i3++) {
764 for (i4 = 0; i4 < 4; i4++) {
766 if (_caps[i1][i1][i3][i4] != 0.0)
771 for (i1 = 0; i1 < 4; i1++) {
772 for (i3 = 0; i3 < 4; i3++) {
773 if (_caps[i1][i1][i3][i3] != 0.0)
779 matrix photodiode::calcMatrixCy (nr_double_t frequency)
822 for (
int i1 = 0; i1 < 4; i1++) {
824 setCV (i1, _chs[i1]);
825 setGV (i1, _ghs[i1]);
826 for (
int i2 = 0; i2 < 4; i2++) {
827 setQV (i1, i2, _jdyna[i1][i2]);