1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1985 Thomas L. Quarles
4 Modified by Paolo Nenzi 2003 and Dietmar Warning 2012
5 **********/
6 #ifndef DIO
7 #define DIO
8 
9 #include "ngspice/ifsim.h"
10 #include "ngspice/gendefs.h"
11 #include "ngspice/cktdefs.h"
12 #include "ngspice/complex.h"
13 #include "ngspice/noisedef.h"
14 
15             /* data structures used to describe diodes */
16 
17 /* indices to array of diode noise  sources */
18 
19 enum {
20     DIORSNOIZ = 0,
21     DIOIDNOIZ,
22     DIOFLNOIZ,
23     DIOTOTNOIZ,
24     /* finally, the number of noise sources */
25     DIONSRCS
26 };
27 
28 /* information needed per instance */
29 
30 typedef struct sDIOinstance {
31 
32     struct GENinstance gen;
33 
34 #define DIOmodPtr(inst) ((struct sDIOmodel *)((inst)->gen.GENmodPtr))
35 #define DIOnextInstance(inst) ((struct sDIOinstance *)((inst)->gen.GENnextInstance))
36 #define DIOname gen.GENname
37 #define DIOstate gen.GENstate
38 
39     const int DIOposNode;     /* number of positive node of diode */
40     const int DIOnegNode;     /* number of negative node of diode */
41     const int DIOtempNode;    /* number of the temperature node of the diode */
42     int DIOposPrimeNode;      /* number of positive prime node of diode */
43 
44     double *DIOposPosPrimePtr;      /* pointer to sparse matrix at
45                                      * (positive,positive prime) */
46     double *DIOnegPosPrimePtr;      /* pointer to sparse matrix at
47                                      * (negative,positive prime) */
48     double *DIOposPrimePosPtr;      /* pointer to sparse matrix at
49                                      * (positive prime,positive) */
50     double *DIOposPrimeNegPtr;      /* pointer to sparse matrix at
51                                      * (positive prime,negative) */
52     double *DIOposPosPtr;   /* pointer to sparse matrix at
53                              * (positive,positive) */
54     double *DIOnegNegPtr;   /* pointer to sparse matrix at
55                              * (negative,negative) */
56     double *DIOposPrimePosPrimePtr; /* pointer to sparse matrix at
57                                      * (positive prime,positive prime) */
58 
59     /* self heating */
60     double *DIOtempPosPtr;
61     double *DIOtempPosPrimePtr;
62     double *DIOtempNegPtr;
63     double *DIOtempTempPtr;
64     double *DIOposTempPtr;
65     double *DIOposPrimeTempPtr;
66     double *DIOnegTempPtr;
67 
68     double DIOcap;   /* stores the diode capacitance */
69 
70     double *DIOsens; /* stores the perturbed values of geq and ceq in ac
71                          sensitivity analyis */
72 
73     int DIOsenParmNo ;   /* parameter # for sensitivity use;
74                           * set equal to  0 if not a design parameter*/
75 
76     unsigned DIOoff : 1;   /* 'off' flag for diode */
77     unsigned DIOareaGiven : 1;   /* flag to indicate area was specified */
78     unsigned DIOpjGiven : 1;   /* flag to indicate perimeter was specified */
79     unsigned DIOwGiven : 1;   /* flag to indicate width was specified */
80     unsigned DIOlGiven : 1;   /* flag to indicate length was specified */
81     unsigned DIOmGiven : 1;   /* flag to indicate multiplier was specified */
82 
83     unsigned DIOinitCondGiven : 1;  /* flag to indicate ic was specified */
84     unsigned DIOsenPertFlag :1; /* indictes whether the the parameter of
85                                the particular instance is to be perturbed */
86     unsigned DIOtempGiven : 1;  /* flag to indicate temperature was specified */
87     unsigned DIOdtempGiven : 1; /* flag to indicate dtemp given */
88 
89     unsigned DIOlengthMetalGiven : 1; /* Length of metal capacitor (level=3) */
90     unsigned DIOlengthPolyGiven : 1;  /* Length of polysilicon capacitor (level=3) */
91     unsigned DIOwidthMetalGiven : 1;  /* Width of metal capacitor (level=3) */
92     unsigned DIOwidthPolyGiven : 1;   /* Width of polysilicon capacitor (level=3) */
93 
94     double DIOarea;     /* area factor for the diode */
95     double DIOpj;       /* perimeter for the diode */
96     double DIOw;        /* width for the diode */
97     double DIOl;        /* length for the diode */
98     double DIOm;        /* multiplier for the diode */
99     int    DIOthermal;  /* flag indicate self heating on */
100 
101     double DIOlengthMetal;   /* Length of metal capacitor (level=3) */
102     double DIOlengthPoly;    /* Length of polysilicon capacitor (level=3) */
103     double DIOwidthMetal;    /* Width of metal capacitor (level=3) */
104     double DIOwidthPoly;     /* Width of polysilicon capacitor (level=3) */
105 
106     double DIOinitCond;      /* initial condition */
107     double DIOtemp;          /* temperature of the instance */
108     double DIOdtemp;         /* delta temperature of instance */
109     double DIOtJctPot;       /* temperature adjusted junction potential */
110     double DIOtJctCap;       /* temperature adjusted junction capacitance */
111     double DIOtJctSWPot;     /* temperature adjusted sidewall junction potential */
112     double DIOtJctSWCap;     /* temperature adjusted sidewall junction capacitance */
113     double DIOtTransitTime;  /* temperature adjusted transit time */
114     double DIOtGradingCoeff; /* temperature adjusted grading coefficient (MJ) */
115     double DIOtConductance;    /* temperature adjusted series conductance */
116     double DIOtConductance_dT; /* temperature adjusted series conductance temperature derivative */
117 
118     double DIOtDepCap;       /* temperature adjusted transition point in */
119                              /* the curve matching (Fc * Vj ) */
120     double DIOtDepSWCap;     /* temperature adjusted transition point in */
121                              /* the curve matching (Fcs * Vjs ) */
122     double DIOtSatCur;         /* temperature adjusted saturation current */
123     double DIOtSatCur_dT;      /* temperature adjusted saturation current temperature derivative */
124     double DIOtSatSWCur;       /* temperature adjusted side wall saturation current */
125     double DIOtSatSWCur_dT;    /* temperature adjusted side wall saturation current temperature derivative */
126     double DIOtTunSatCur;      /* tunneling saturation current */
127     double DIOtTunSatCur_dT;   /* tunneling saturation current temperature derivative */
128     double DIOtTunSatSWCur;    /* sidewall tunneling saturation current */
129     double DIOtTunSatSWCur_dT; /* sidewall tunneling saturation current temperature derivative */
130 
131     double DIOtVcrit;   /* temperature adjusted V crit */
132     double DIOtF1;      /* temperature adjusted f1 */
133     double DIOtBrkdwnV; /* temperature adjusted breakdown voltage */
134 
135     double DIOtF2;     /* coeff. for capacitance equation precomputation */
136     double DIOtF3;     /* coeff. for capacitance equation precomputation */
137     double DIOtF2SW;   /* coeff. for capacitance equation precomputation */
138     double DIOtF3SW;   /* coeff. for capacitance equation precomputation */
139 
140     double DIOforwardKneeCurrent; /* Forward Knee current */
141     double DIOreverseKneeCurrent; /* Reverse Knee current */
142     double DIOjunctionCap;        /* geometry adjusted junction capacitance */
143     double DIOjunctionSWCap;      /* geometry adjusted junction sidewall capacitance */
144     double DIOtRecSatCur;         /* temperature adjusted recombination saturation current */
145     double DIOtRecSatCur_dT;      /* temperature adjusted recombination saturation current */
146 
147     double DIOdIth_dVrs;
148     double DIOdIth_dVdio;
149     double DIOdIth_dT;
150     double DIOgcTt;
151     double DIOdIrs_dT;
152     double DIOdIdio_dT;
153 
154     double DIOcmetal; /* parasitic metal overlap capacitance */
155     double DIOcpoly;  /* parasitic polysilicon overlap capacitance */
156 
157 /*
158  * naming convention:
159  * x = vdiode
160  */
161 
162 /* the following are relevant to s.s. sinusoidal distortion analysis */
163 
164 #define DIONDCOEFFS        6
165 
166 #ifndef NODISTO
167         double DIOdCoeffs[DIONDCOEFFS];
168 #else /* NODISTO */
169         double *DIOdCoeffs;
170 #endif /* NODISTO */
171 
172 #ifndef CONFIG
173 
174 #define        id_x2                DIOdCoeffs[0]
175 #define        id_x3                DIOdCoeffs[1]
176 #define        cdif_x2                DIOdCoeffs[2]
177 #define        cdif_x3                DIOdCoeffs[3]
178 #define        cjnc_x2                DIOdCoeffs[4]
179 #define        cjnc_x3                DIOdCoeffs[5]
180 
181 #endif
182 
183 #ifndef NONOISE
184      double DIOnVar[NSTATVARS][DIONSRCS];
185 #else /* NONOISE */
186         double **DIOnVar;
187 #endif /* NONOISE */
188 
189 } DIOinstance ;
190 
191 #define DIOsenGeq DIOsens /* stores the perturbed values of geq */
192 #define DIOsenCeq DIOsens + 3 /* stores the perturbed values of ceq */
193 #define DIOdphidp DIOsens + 6
194 
195 
196 #define DIOvoltage DIOstate
197 #define DIOcurrent DIOstate+1
198 #define DIOconduct DIOstate+2
199 #define DIOcapCharge DIOstate+3
200 #define DIOcapCurrent DIOstate+4
201 
202 #define DIOqth DIOstate+5     /* thermal capacitor charge */
203 #define DIOcqth DIOstate+6    /* thermal capacitor current */
204 
205 #define DIOdeltemp DIOstate+7 /* thermal voltage over rth0 */
206 #define DIOdIdio_dT DIOstate+8
207 
208 #define DIOnumStates 9
209 
210 #define DIOsensxp DIOstate+9    /* charge sensitivities and their derivatives.
211                                  * +10 for the derivatives - pointer to the
212                                  * beginning of the array */
213 
214 #define DIOnumSenStates 2
215 
216 
217 /* per model data */
218 
219 typedef struct sDIOmodel {       /* model structure for a diode */
220 
221     struct GENmodel gen;
222 
223 #define DIOmodType gen.GENmodType
224 #define DIOnextModel(inst) ((struct sDIOmodel *)((inst)->gen.GENnextModel))
225 #define DIOinstances(inst) ((DIOinstance *)((inst)->gen.GENinstances))
226 #define DIOmodName gen.GENmodName
227 
228     unsigned DIOlevelGiven : 1;
229     unsigned DIOsatCurGiven : 1;
230     unsigned DIOsatSWCurGiven : 1;
231 
232     unsigned DIOresistGiven : 1;
233     unsigned DIOresistTemp1Given : 1;
234     unsigned DIOresistTemp2Given : 1;
235     unsigned DIOemissionCoeffGiven : 1;
236     unsigned DIOswEmissionCoeffGiven : 1;
237     unsigned DIObrkdEmissionCoeffGiven : 1;
238     unsigned DIOtransitTimeGiven : 1;
239     unsigned DIOtranTimeTemp1Given : 1;
240     unsigned DIOtranTimeTemp2Given : 1;
241     unsigned DIOjunctionCapGiven : 1;
242     unsigned DIOjunctionPotGiven : 1;
243     unsigned DIOgradingCoeffGiven : 1;
244     unsigned DIOgradCoeffTemp1Given : 1;
245     unsigned DIOgradCoeffTemp2Given : 1;
246     unsigned DIOjunctionSWCapGiven : 1;
247     unsigned DIOjunctionSWPotGiven : 1;
248     unsigned DIOgradingSWCoeffGiven : 1;
249     unsigned DIOforwardKneeCurrentGiven : 1;
250     unsigned DIOreverseKneeCurrentGiven : 1;
251 
252     unsigned DIOtlevGiven : 1;
253     unsigned DIOtlevcGiven : 1;
254     unsigned DIOactivationEnergyGiven : 1;
255     unsigned DIOsaturationCurrentExpGiven : 1;
256     unsigned DIOctaGiven : 1;
257     unsigned DIOctpGiven : 1;
258     unsigned DIOtpbGiven : 1;
259     unsigned DIOtphpGiven : 1;
260     unsigned DIOdepletionCapCoeffGiven : 1;
261     unsigned DIOdepletionSWcapCoeffGiven :1;
262     unsigned DIObreakdownVoltageGiven : 1;
263     unsigned DIObreakdownCurrentGiven : 1;
264     unsigned DIOtcvGiven : 1;
265     unsigned DIOnomTempGiven : 1;
266     unsigned DIOfNcoefGiven : 1;
267     unsigned DIOfNexpGiven : 1;
268     unsigned DIOareaGiven : 1;
269     unsigned DIOpjGiven : 1;
270 
271     unsigned DIOtunSatCurGiven : 1;
272     unsigned DIOtunSatSWCurGiven : 1;
273     unsigned DIOtunEmissionCoeffGiven : 1;
274     unsigned DIOtunSaturationCurrentExpGiven : 1;
275     unsigned DIOtunEGcorrectionFactorGiven : 1;
276     unsigned DIOfv_maxGiven : 1;
277     unsigned DIObv_maxGiven : 1;
278     unsigned DIOrecSatCurGiven : 1;
279     unsigned DIOrecEmissionCoeffGiven : 1;
280 
281     unsigned DIOrth0Given :1;
282     unsigned DIOcth0Given :1;
283 
284     unsigned DIOlengthMetalGiven : 1;     /* Length of metal capacitor (level=3) */
285     unsigned DIOlengthPolyGiven : 1;      /* Length of polysilicon capacitor (level=3) */
286     unsigned DIOwidthMetalGiven : 1;      /* Width of metal capacitor (level=3) */
287     unsigned DIOwidthPolyGiven : 1;       /* Width of polysilicon capacitor (level=3) */
288     unsigned DIOmetalOxideThickGiven : 1; /* Thickness of the metal to bulk oxide (level=3) */
289     unsigned DIOpolyOxideThickGiven : 1;  /* Thickness of the polysilicon to bulk oxide (level=3) */
290     unsigned DIOmetalMaskOffsetGiven : 1; /* Masking and etching effects in metal (level=3)") */
291     unsigned DIOpolyMaskOffsetGiven : 1;  /* Masking and etching effects in polysilicon (level=3) */
292 
293     int    DIOlevel;   /* level selector */
294     double DIOsatCur;   /* saturation current */
295     double DIOsatSWCur;   /* Sidewall saturation current */
296 
297     double DIOresist;             /* ohmic series resistance */
298     double DIOresistTemp1;        /* series resistance 1st order temp. coeff. */
299     double DIOresistTemp2;        /* series resistance 2nd order temp. coeff. */
300     double DIOconductance;        /* conductance corresponding to ohmic R */
301     double DIOemissionCoeff;      /* emission coefficient (N) */
302     double DIOswEmissionCoeff;    /* Sidewall emission coefficient (NS) */
303     double DIObrkdEmissionCoeff;  /* Breakdown emission coefficient (NBV) */
304     double DIOtransitTime;        /* transit time (TT) */
305     double DIOtranTimeTemp1;      /* transit time 1st order coefficient */
306     double DIOtranTimeTemp2;      /* transit time 2nd order coefficient */
307     double DIOjunctionCap;        /* Junction Capacitance (Cj0) */
308     double DIOjunctionPot;        /* Junction Potential (Vj) or (PB) */
309     double DIOgradingCoeff;       /* grading coefficient (m) or (mj) */
310     double DIOgradCoeffTemp1;     /* grading coefficient 1st order temp. coeff.*/
311     double DIOgradCoeffTemp2;     /* grading coefficient 2nd order temp. coeff.*/
312     double DIOjunctionSWCap;      /* Sidewall Junction Capacitance (Cjsw) */
313     double DIOjunctionSWPot;      /* Sidewall Junction Potential (Vjsw) or (PBSW) */
314     double DIOgradingSWCoeff;     /* Sidewall grading coefficient (mjsw) */
315     double DIOforwardKneeCurrent; /* Forward Knee current (IKF) */
316     double DIOreverseKneeCurrent; /* Reverse Knee current (IKR) */
317 
318     int    DIOtlev; /* Diode temperature equation selector */
319     int    DIOtlevc; /* Diode temperature equation selector */
320     double DIOactivationEnergy; /* activation energy (EG) */
321     double DIOsaturationCurrentExp; /* Saturation current exponential (XTI) */
322     double DIOcta; /* Area junction temperature coefficient */
323     double DIOctp; /* Perimeter junction temperature coefficient */
324     double DIOtpb; /* Area junction potential temperature coefficient */
325     double DIOtphp; /* Perimeter junction potential temperature coefficient */
326     double DIOdepletionCapCoeff;    /* Depletion Cap fraction coefficient (FC)*/
327     double DIOdepletionSWcapCoeff;    /* Depletion sw-Cap fraction coefficient (FCS)*/
328     double DIObreakdownVoltage; /* Voltage at reverse breakdown */
329     double DIObreakdownCurrent; /* Current at above voltage */
330     double DIOtcv; /* Reverse breakdown voltage temperature coefficient */
331     double DIOarea;     /* area factor for the diode */
332     double DIOpj;       /* perimeter for the diode */
333 
334     double DIOnomTemp;  /* nominal temperature at which parms measured */
335     double DIOfNcoef;
336     double DIOfNexp;
337 
338     double DIOtunSatCur;        /* tunneling saturation current (JTUN) */
339     double DIOtunSatSWCur;      /* sidewall tunneling saturation current (JTUNSW) */
340     double DIOtunEmissionCoeff; /* tunneling emission coefficient (NTUN) */
341     double DIOtunSaturationCurrentExp; /* exponent for the tunneling current temperature (XTITUN) */
342     double DIOtunEGcorrectionFactor; /* EG correction factor for tunneling (KEG) */
343     double DIOfv_max; /* maximum voltage in forward direction */
344     double DIObv_max; /* maximum voltage in reverse direction */
345     double DIOrecSatCur; /* Recombination saturation current */
346     double DIOrecEmissionCoeff; /* Recombination emission coefficient */
347 
348     double DIOrth0;
349     double DIOcth0;
350 
351     double DIOlengthMetal;     /* Length of metal capacitor (level=3) */
352     double DIOlengthPoly;      /* Length of polysilicon capacitor (level=3) */
353     double DIOwidthMetal;      /* Width of metal capacitor (level=3) */
354     double DIOwidthPoly;       /* Width of polysilicon capacitor (level=3) */
355     double DIOmetalOxideThick; /* Thickness of the metal to bulk oxide (level=3) */
356     double DIOpolyOxideThick;  /* Thickness of the polysilicon to bulk oxide (level=3) */
357     double DIOmetalMaskOffset; /* Masking and etching effects in metal (level=3)") */
358     double DIOpolyMaskOffset;  /* Masking and etching effects in polysilicon (level=3) */
359 
360 } DIOmodel;
361 
362 /* device parameters */
363 enum {
364     DIO_AREA = 1,
365     DIO_IC,
366     DIO_OFF,
367     DIO_CURRENT,
368     DIO_VOLTAGE,
369     DIO_CHARGE,
370     DIO_CAPCUR,
371     DIO_CONDUCT,
372     DIO_AREA_SENS,
373     DIO_POWER,
374     DIO_TEMP,
375     DIO_QUEST_SENS_REAL,
376     DIO_QUEST_SENS_IMAG,
377     DIO_QUEST_SENS_MAG,
378     DIO_QUEST_SENS_PH,
379     DIO_QUEST_SENS_CPLX,
380     DIO_QUEST_SENS_DC,
381     DIO_CAP,
382     DIO_PJ,
383     DIO_W,
384     DIO_L,
385     DIO_M,
386     DIO_DTEMP,
387     DIO_THERMAL,
388     DIO_LM,
389     DIO_LP,
390     DIO_WM,
391     DIO_WP,
392 };
393 
394 /* model parameters */
395 enum {
396     DIO_MOD_LEVEL = 100,
397     DIO_MOD_IS,
398     DIO_MOD_RS,
399     DIO_MOD_N,
400     DIO_MOD_TT,
401     DIO_MOD_CJO,
402     DIO_MOD_VJ,
403     DIO_MOD_M,
404     DIO_MOD_EG,
405     DIO_MOD_XTI,
406     DIO_MOD_FC,
407     DIO_MOD_BV,
408     DIO_MOD_IBV,
409     DIO_MOD_D,
410     DIO_MOD_COND,
411     DIO_MOD_TNOM,
412     DIO_MOD_KF,
413     DIO_MOD_AF,
414     DIO_MOD_JSW,
415     DIO_MOD_CJSW,
416     DIO_MOD_VJSW,
417     DIO_MOD_MJSW,
418     DIO_MOD_IKF,
419     DIO_MOD_IKR,
420     DIO_MOD_FCS,
421     DIO_MOD_TTT1,
422     DIO_MOD_TTT2,
423     DIO_MOD_TM1,
424     DIO_MOD_TM2,
425     DIO_MOD_TRS,
426     DIO_MOD_TRS2,
427     DIO_MOD_TLEV,
428     DIO_MOD_TLEVC,
429     DIO_MOD_CTA,
430     DIO_MOD_CTP,
431     DIO_MOD_TPB,
432     DIO_MOD_TPHP,
433     DIO_MOD_TCV,
434     DIO_MOD_NBV,
435     DIO_MOD_AREA,
436     DIO_MOD_PJ,
437     DIO_MOD_NS,
438     DIO_MOD_JTUN,
439     DIO_MOD_JTUNSW,
440     DIO_MOD_NTUN,
441     DIO_MOD_XTITUN,
442     DIO_MOD_KEG,
443     DIO_MOD_FV_MAX,
444     DIO_MOD_BV_MAX,
445     DIO_MOD_ISR,
446     DIO_MOD_NR,
447     DIO_MOD_RTH0,
448     DIO_MOD_CTH0,
449 
450     DIO_MOD_LM,
451     DIO_MOD_LP,
452     DIO_MOD_WM,
453     DIO_MOD_WP,
454     DIO_MOD_XOM,
455     DIO_MOD_XOI,
456     DIO_MOD_XM,
457     DIO_MOD_XP,
458 };
459 
460 void DIOtempUpdate(DIOmodel *inModel, DIOinstance *here, double Temp, CKTcircuit *ckt);
461 
462 #include "dioext.h"
463 #endif /*DIO*/
464