//
// VBIC95 Model Definition
//
// Release 1.1.5, Jul 28, 1996
//
//	1.1.5 updates:	Jul 28, 1996
//			Dependence of Irbp on Vbci added to "branch currents"
//			Itf/Itr renamed Itfi/Itri to avoid name conflicts
//			Resistor collapse and code bypass condition
//				changed from par==0 to par<=0
//			Branch current and charge dependencies separated
//				for self-heating and no self-heating
//			Depletion charge and avalanche routines that provide
//				derivatives for self-heating added
//			Self-heating solver and examples added (HBT)
//			Extra external node added for self-heating to allow
//				coupling of thermal models between devices
//
//	1.1.4 updates:	Qbe diffusion term made equivalent to SGP (divide by qb)
//			Solver example including excess phase added
//				(Icc separated into Itzf|Itxf and Itzr for this)
//			Error in sgp_to_vbic95 in PTF to TD translation fixed
//
//	1.1.3 updates:	Ith bug fixed and Igc term added
//			BFN exponent added to 1/f noise
//			RTH default changed to zero
//			parameter aliases added
//
//	1.1.2 updates:	EAI bug fixed in PE/PC/PStemperature mapping
//			single->double precision in decomp/solve/vbict/QCDEPL
//			scale changed to vscale in solver to avoid name conflict
//			avalanche model added, element Igc
//			initialization changed in solver
//			AC solver and AC and temperature tests added
//			missing term in derf_Vrci added
//			potential numerical problem in Irci fixed
//
//	1.1.1 updates:	VJ->V bug fixed in qj definition
//			potential numerical problems with ITF fixed
//			typo derf_Vcci fixed to derf_Vrci in FORTRAN code
//
//
// Equivalent Circuit Network:
//
//          |       |
// -(->)-  (^) and (v)   are voltage controlled current sources (arrow gives
//          |       |        reference direction for current flow), key letter I
//
// +  -             | +
// -||-        and  =    are voltage controlled charge sources (+/- signs
//                  | -      give reference polarity), key ketter Q
//
// -(=>)-                are current controlled flux sources (arrow gives
//                           reference direction for flux), key letter F
//
// o             are nodes
//
// resistors are depicted as voltage controlled current sources for
// generality (also, this is true if self-heating is modeled)
//
//
// -----------------------------------------------------------------------------
// |                                                                           |
// | BE/BC extrinsic         o s                                   o c         |
// | overlap capacitances    |                                     |           |
// | not shown               |                                     |           |
// |                        (v) Irs                               (v) Ircx     |
// |                         |                                     |           |
// |                         |                                     |           |
// |                ---------o---- si                              |           |
// |                |        |   |                                 |           |
// |                |      + |   |                                 |           |
// |                |   Qbcp =  (v) Ibcp                           |           |
// |                |      - |   |                                 |           |
// |                |        |   |                                 |           |
// |          Iccp (^)    bp o---+----(<-)----+--------------------o cx        |
// |                |        |   |    Irbp    |                    |           |
// |                |      - |   |            |                    |           |
// |                |   Qbep =  (^) Ibep      |                   (v) Irci     |
// |                |      + |   |            |                    |           |
// |                |        |   |            |                    |           |
// |                ---------+----            |       ----+--------o ci        |
// |                         |                |       |   |        |           |
// |                         |              - |       |   | -      |           |
// |                         |           Qbcx =  Ibc (^)  = Qbc    |           |
// |                         |              + | -Igc  |   | +      |           |
// |                       bx|                |       |   |        |           |
// |          b o----(->)----o---+----(->)----+-------+---o bi    (v) Itzf|Itxf|
// |                 Irbx    |   |     Irbi           |   |        |  -Itzr    |
// |                         |   | +                  |   | +      |           |
// |                   Ibex (v)  = Qbex          Ibe (v)  = Qbe    |           |
// |  Thermal Network        |   | -                  |   | -      |           |
// |           dt            |   |                    |   |        |           |
// |  ---------o---------    ----+--------------------+---+--------o ei        |
// |  |        |        |                                          |           |
// |  |        |        | +                                        |           |
// | (^) Ith  (v) Irth  = Qcth                                    (^) Ire      |
// |  |        |        | -                                        |           |
// |  |        |        |                                          |           |
// |  ---------o---------                                          o e         |
// |           tl                                                              |
// |                                                                           |
// |  Excess Phase Network                                                     |
// |           xf1                                                             |
// |  ---------o----(=>)----o xf2                                              |
// |  |        |    Flxf    |                                                  |
// |  |        | +          |                                                  |
// | (^) Itzf  = Qcxf      (v) Itxf                                            |
// |  |        | -          |                                                  |
// |  |        |            |                                                  |
// |  ---------o-------------                                                  |
// |          gnd                                                              |
// |                                                                           |
// -----------------------------------------------------------------------------
//
//
// NOTES:
//	Below the underscore character ("_") means partial differentiation,
//	so y_x means the partial derivative of y(x,...) with respect to x.
//	Comments are C++ style, from // to end of line.
//	Continuation is \ as last non-white space character on a line
//	(except comments).
//	cpp directives are included, process with "cpp -B -P".
//	Blocks are delimited by {} brackets for clarity.
//	"fwd" and "rev" are for forward and reverse, respectively.
//	"b-e", "b-c" and "s-c" are for base-emitter, base-collector and
//	substrate-collector, respectively.
//	All temperatures are in C.
//	Units are volts, amperes, ohms, farads, seconds.
//	Conditionals are added as
//		if ( expression ) {
//		} elif ( expression ) {
//		} else {
//		}
//	and are used to detect node collapse and to bypass
//	calculations for efficiency. Node collapse is identified by the
//	construct "collapse(n1,n2)". The actual handling of this will be
//	simulator specific.
//	Temperature mappings are written as being from TNOM to the device
//	temperature. Parameters that are temperature dependent are written
//	at TNOM as XXX@TNOM where XXX is the "usual" parameter name.
//
// Macros:	qj(V,P,M,FC,A)	normalized junction depletion charge
//			V  = junction applied voltage
//			P  = junction built-in potential
//			M  = junction grading coefficient
//			FC = fraction of P at which numerical switch is made
//			A  = corner/smoothing coefficient for single piece model
//			Note: the qj model is used in the base charge qb
//			formulation, and so must have a reference such that
//			qj(V=0)=0.
//	psibi(P,EA,Vtv,rT)	built-in potential as a function of temperature
//			P   = built-in potential at TNOM
//			EA  = activation energy (can differ from bandgap)
//			Vtv = thermal voltage
//			rT  = ratio Tdev/TNOM in K
//			The SPICE model is in error for high temperatures
//			as it can give negative psibi. The model below has the
//			proper physical behavior.
//	avalm(V,P,M,AV1,AV2)	(weak) avalanche multiplication factor
//			V  = junction applied voltage
//			P  = junction built-in potential
//			M  = junction grading coefficient
//			AV1  = avalanche paramater 1
//			AV2  = avalanche parameter 2
//
// **********
// ********** Implementation Notes:
// **********
// **********    1. In SABER log is log10, so use ln for log below
// **********    2. In simulators that use SPICE-like algorithms, initialize
// **********       as per SGP (SPICE Gummel-Poon) model for Vbei and Vbci,
// **********       and with zero for other branches. Use pnjlim for all
// **********       junctions (including parasitic), and also for Vbcx,
// **********       which must me calculated from Vbci-Vrci.
// **********    3. For simplicity and efficiency, the Igc and Ibc elements
// **********       can be combined, but to do this the combined element
// **********       depends on Vbei and Vbci, not just the latter as
// **********       Ibc does, so the appropriate entries must be stamped.
// **********	 4. For the self-heating version, limiting should be used
// **********	    for the change in local temperature between NR iterations.
// **********	    The local temperature rise should also not be less than
// **********	    zero, and values that drive the absolute temperature
// **********	    of a device to a low value (or negative, in K) will cause
// **********	    numerical problems. There is no standard pnjlim-like
// **********	    function for limiting self-heating, so you will need to
// **********	    provide one.
// **********
//
begin macro psibi ( P, EA, Vtv, rT ) {
	psiio = 2.0 * Vtv * log \
			( exp ( 0.5 * P / Vtv ) - exp ( - 0.5 * P / Vtv ) )
	psiin = psiio * rT - 3.0 * Vtv * log ( rT ) - EA * ( rT - 1.0 )
	psibi = psiin + 2.0 * Vtv * log ( 0.5 * \
			( 1.0 + sqrt ( 1.0 + 4.0 * exp ( - psiin / Vtv ) ) ) )
}
begin macro qj ( V, P, M, FC, A ) {
	if ( A <= 0.0 ) {
//
//		SPICE regional depletion capacitance model
//
	   dvh  = V - FC * P
	   if ( dvh > 0.0 ) {
	      qlo  = P * ( 1.0 - ( 1.0 - FC ) ^ ( 1.0 - M ) ) / ( 1.0 - M )
	      qhi  = dvh * ( 1.0 - FC + 0.5 * M * dvh / P ) / \
			( ( 1.0 - FC ) ^ ( 1.0 + M ) )
	   } else {
	      qlo  = P * ( 1.0 - ( 1.0 - V / P ) ^ ( 1.0 - M ) ) / ( 1.0 - M )
	      qhi  = 0.0
	   }
	   qj   = qlo + qhi
	} else {
//
//		Single piece depletion capacitance model
//
//		Based on c=1/(1-V/P)^M, with sqrt limiting to make it
//		C-inf continuous (and computationally efficient), with
//		added terms to make it monotonically increasing (which
//		is physically incorrect, but avoids numerical problems
//		and kinks near where the depletion and diffusion
//		capacitances are of similar magnitude), and with appropriate
//		offsets added to that qj(V=0)=0.
//
	   dv0  =   - P * FC
	   mv0  = sqrt  ( dv0 * dv0   + A )
	   vl0  = 0.5 * ( dv0 - mv0 ) + P * FC
	   q0   = - P * ( 1.0 - vl0 / P ) ^ ( 1.0 - M ) / ( 1.0 - M )
	   dv   = V - P * FC
	   mv   = sqrt  ( dv  * dv    + A )
	   vl   = 0.5 * ( dv  - mv  ) + P * FC
	   qlo  = - P * ( 1.0 - vl  / P ) ^ ( 1.0 - M ) / ( 1.0 - M )
	   qj   = qlo + ( 1.0 - FC ) ^ ( - M ) * ( V - vl + vl0 ) - q0
	}
}
begin macro avalm ( V, P, M, AV1, AV2) {
//
//		Kloosterman/de Graaff weak avalanche model
//
	vl    = 0.5 * ( sqrt ( ( P - V ) ^ 2 + 0.01 ) + ( P - V ) )
	avalm = AV1 * vl * exp ( - AV2 * vl ^ ( M - 1.0 ) )
}

begin model definition {

// cpp definitions for constants and switches

#undef 	SELF-HEATING			// use undef to switch off SELF-HEATING
#undef 	EXCESS-PHASE			// use undef to switch off EXCESS-PHASE
#define	KB		1.380662E-23	// Boltzmann's constant, J/K
#define	QQ		1.602189E-19	// magnitude of electronic charge, C
#define	TABS		2.731500E+02	// 0 degrees C in degrees K

// extern definitions, for variables from simulator

extern	{
	TAMB		// ambient temperature of chip
	FREQ		// frequency, for AC and noise analyses
	SCALE		// scaling factor (default=1.0)
}


// external nodes that must be connected in circuit netlist

external nodes {
#ifdef SELF-HEATING
	c b e s dt tl	// Local temperature nodes added for SELF-HEATING.
			// dt is local temperature rise, tl is local
			// temperature, for single device self-heating
			// connect tl to ground in the netlist.
			// For wafer-level multi-device coupled electrothermal
			// simulation connect tl nodes with thermal resistances
			// that model heat flow between adjacent devices and to
			// ambient. For more than single-pole thermal
			// impedance model set CTH to zero, RTH to a large
			// value, and connect the more complex local thermal
			// network model between dt and tl.
#else
	c b e s
#endif
}

// internal nodes, this information is implicit in branch
//                 voltage/current/charge/flux definitions below

internal nodes {
#ifdef EXCESS-PHASE
	cx ci bx bi ei si bp xf1 xf2
#else
	cx ci bx bi ei si bp
#endif
}

branch voltages {

//	name = V(n1) - V(n2) where voltage is measured from node n1 to node n2

	Vbe  = V(b  ) - V(e  )	// extrinsic b-e voltage
	Vbc  = V(b  ) - V(c  )	// extrinsic b-c voltage
	Vbei = V(bi ) - V(ei )	// intrinsic b-e voltage
	Vbex = V(bx ) - V(ei )	// side      b-e voltage
	Vbci = V(bi ) - V(ci )	// intrinsic b-c voltage
	Vrcx = V(c  ) - V(cx )	// voltage across RCX
	Vrci = V(cx ) - V(ci )	// voltage across RCI
	Vrbx = V(b  ) - V(bx )	// voltage across RBX
	Vrbi = V(bx ) - V(bi )	// voltage across RBI
	Vre  = V(e  ) - V(ei )	// voltage across RE
	Vrs  = V(s  ) - V(si )	// voltage across RS
	Vbep = V(bx ) - V(bp )	// parasitic b-e voltage (pnp polarity)
	Vbcp = V(si ) - V(bp )	// parasitic b-c voltage (pnp polarity)
	Vrbp = V(cx ) - V(bp )	// voltage across RBP
#ifdef SELF-HEATING
	delT = V(dt ) - V(tl )	// voltage across RTH, local temperature rise
				// measured with respect to ground (ambient)
#endif
#ifdef EXCESS-PHASE
	Vcxf = V(xf1) - V(0  )	// voltage across excess-phase capacitor
	Vrxf = V(xf2) - V(0  )	// voltage across excess-phase resistor Itxf
#endif
}

branch currents {

//	NOTE: the dependencies listed below are for convenience, they are in
//	fact implicit in the equations for the branch currents and charges of
//	the model. If the SELF-HEATING model is used, then all branch
//	currents and charges depend on all branch voltages, through the local
//	temperature rise delT. This is not shown below. Of course, the matrix
//	stamp becomes much more dense (less sparse) with SELF-HEATING.

//	name from n1  to  n2	dependencies on branch voltages

#ifdef SELF-HEATING
#ifdef EXCESS-PHASE
	Itxf from ci  to  ei	Vrxf,delT	// forward   transport current
#else
	Itzf from ci  to  ei	Vbei,Vbci,delT	// forward   transport current
#endif
	Itzr from ei  to  ci	Vbei,Vbci,delT	// reverse   transport current
	Ibe  from bi  to  ei	Vbei,delT	// intrinsic b-e current
	Ibex from bx  to  ei	Vbex,delT	// side      b-e current
	Ibc  from bi  to  ci	Vbci,delT	// intrinsic b-c current
	Igc  from ci  to  bi	Vbei,Vbci,delT	// c-b weak avalanche current
	Ircx from c   to  cx	Vrcx,delT	// RCX  element
	Irci from cx  to  ci	Vbci,Vrci,delT	// RCI  element
	Irbx from b   to  bx	Vrbx,delT	// RBX  element
	Irbi from bx  to  bi	Vrbi,Vbei,Vbci,delT	// RBI  element
	Ire  from e   to  ei	Vre,delT	// RE   element
	Irs  from s   to  si	Vrs,delT	// RS   element
	Iccp from bx  to  si	Vbep,Vbcp,Vbci,delT	// parasitic transprt I
	Ibep from bx  to  bp	Vbep,delT	// parasitic b-e current
	Ibcp from si  to  bp	Vbcp,delT	// parasitic b-c current
	Irbp from cx  to  bp	Vrbp,Vbep,Vbci,delT	// RBP element
	Ith  from tl  to  dt	Vbei,Vbci,Vrcx,Vrci,Vrbx,Vrbi,Vre,Vbep,Vbcp \
				Vrbp,Vrs,Vbex,delT
						// thermal power generation
	Irth from dt  to  tl	delT		// thermal resistance RTH
#else
#ifdef EXCESS-PHASE
	Itxf from ci  to  ei	Vrxf		// forward   transport current
#else
	Itzf from ci  to  ei	Vbei,Vbci	// forward   transport current
#endif
	Itzr from ei  to  ci	Vbei,Vbci	// reverse   transport current
	Ibe  from bi  to  ei	Vbei		// intrinsic b-e current
	Ibex from bx  to  ei	Vbex		// side      b-e current
	Ibc  from bi  to  ci	Vbci		// intrinsic b-c current
	Igc  from ci  to  bi	Vbei,Vbci	// c-b weak avalanche current
	Ircx from c   to  cx	Vrcx		// RCX  element
	Irci from cx  to  ci	Vbci,Vrci	// RCI  element
	Irbx from b   to  bx	Vrbx		// RBX  element
	Irbi from bx  to  bi	Vrbi,Vbei,Vbci	// RBI  element, it gets the
						//  Vbe/ci dependence through qb
	Ire  from e   to  ei	Vre		// RE   element
	Irs  from s   to  si	Vrs		// RS   element
	Iccp from bx  to  si	Vbep,Vbcp,Vbci	// parasitic transport current
	Ibep from bx  to  bp	Vbep		// parasitic b-e current
	Ibcp from si  to  bp	Vbcp		// parasitic b-c current
	Irbp from cx  to  bp	Vrbp,Vbep,Vbci	// RBP element, it gets the
						//  Vbep and Vbci dependence
						//  through qbp
#endif
#ifdef EXCESS-PHASE
	Itzf from 0   to  xf1 	Vbei,Vbci	// fwd transport zero phase
	Itxf from xf2 to  0 	Vrxf		// fwd transport excess-phase
	Ilxf from xf1 to  xf2 			// excess-phase inductor, which
						// is the formulation variable
						// for this element and so is
						// not dependent on any branch
						// voltages
#endif
}

branch charges {		// charges give currents Q_t

//	name from n1  to  n2	dependencies on branch voltages

	Qbeo from b   to  e 	Vbe		// extrinsic b-e overlap charge
	Qbco from b   to  c 	Vbc		// extrinsic b-c overlap charge
#ifdef SELF-HEATING
	Qbe  from bi  to  ei	Vbei,Vbci,delT	// intrinsic b-e charge
	Qbex from bx  to  ei	Vbex,delT	// side      b-e charge
	Qbc  from bi  to  ci	Vbci,delT	// intrinsic b-c charge
	Qbcx from bi  to  cx	Vbci,Vrci,delT	// b-c/epi charge
	Qbep from bx  to  bp	Vbep,Vbci,delT	// parasitic b-e charge
	Qbcp from si  to  bp	Vbcp,delT	// parasitic b-c charge
	Qcth from dt  to  tl	delT		// thermal capacitance CTH
#else
	Qbe  from bi  to  ei	Vbei,Vbci	// intrinsic b-e charge
	Qbex from bx  to  ei	Vbex		// side      b-e charge
	Qbc  from bi  to  ci	Vbci		// intrinsic b-c charge
	Qbcx from bi  to  cx	Vbci,Vrci	// b-c/epi charge
	Qbep from bx  to  bp	Vbep,Vbci	// parasitic b-e charge
	Qbcp from si  to  bp	Vbcp		// parasitic b-c charge
#endif
#ifdef EXCESS-PHASE
	Qcxf from xf1 to  0	Vcxf		// excess-phase capacitance
#endif
}

#ifdef EXCESS-PHASE
branch fluxes {			// fluxes give voltages F_t

//	name from n1  to  n2	dependencies on branch currents

	Flxf from xf1 to xf2	Ilxf		// excess-phase inductor
}
#endif

parameter list {

//	name		default

	TNOM		2.7E+01	// nominal measurement temperature of parameters
	RCX@TNOM	0.0	// extrinsic coll resistance
	RCI@TNOM	0.0	// intrinsic coll resistance
	VO@TNOM		0.0	// epi drift saturation voltage
	GAMM@TNOM	0.0	// epi doping parameter
	HRCF		1.0	// high current RC factor
	RBX@TNOM	0.0	// extrinsic base resistance
	RBI@TNOM	0.0	// intrinsic base resistance
	RE@TNOM		0.0	//           emit resistance
	RS@TNOM		0.0	//           subs resistance
	RBP@TNOM	0.0	// parasitic base resistance
	IS@TNOM		1.0E-16	// transport saturation current
	NF@TNOM		1.0	// fwd emission coefficient
	NR@TNOM		1.0	// rev emission coefficient
	FC		0.9	// fwd bias depletion capacitance limit
	CBEO		0.0	// extrinsic b-e overlap capacitance
	CJE@TNOM	0.0	// b-e zero bias capacitance
	PE@TNOM		0.75	// b-e built-in potential
	ME		0.33	// b-e grading coefficient
	AJE		-.5	// b-e capacitance smoothing factor
	CBCO		0.0	// extrinsic b-c overlap capacitance
	CJC@TNOM	0.0	// b-c intrinsic zero bias capacitance
	QCO		0.0	// epi charge parameter
	CJEP@TNOM	0.0	// b-c extrinsic zero bias capacitance
	PC@TNOM		0.75	// b-c built-in potential
	MC		0.33	// b-c grading coefficient
	AJC		-.5	// b-c capacitance smoothing factor
	CJCP@TNOM	0.0	// s-c zero bias capacitance
	PS@TNOM		0.75	// s-c built-in potential
	MS		0.33	// s-c grading coefficient
	AJS		-.5	// s-c capacitance smoothing factor
	IBEI@TNOM	1.0E-18	// ideal     b-e saturation current
	WBE		1.0	// portion of IBEI from Vbei, 1-WBE from Vbex
	NEI		1.0	// ideal     b-e emission coefficient
	IBEN@TNOM	0.0	// non-ideal b-e saturation current
	NEN		2.0	// non-ideal b-e emission coefficient
	IBCI@TNOM	1.0E-16	// ideal     b-c saturation current
	NCI		1.0	// ideal     b-c emission coefficient
	IBCN@TNOM	0.0	// non-ideal b-c saturation current
	NCN		2.0	// non-ideal b-c emission coefficient
	AVC1		0.0	// b-c weak avalanche parameter 1
	AVC2@TNOM	0.0	// b-c weak avalanche parameter 2
	ISP@TNOM	0.0	// parasitic transport saturation current
	WSP		1.0	// portion of ICCP from Vbep, 1-WSP from Vbci
	NFP		1.0	// parasitic fwd emission coefficient
	IBEIP@TNOM	0.0	// ideal     parasitic b-e saturation current
	IBENP@TNOM	0.0	// non-ideal parasitic b-e saturation current
	IBCIP@TNOM	0.0	// ideal     parasitic b-c saturation current
	NCIP		1.0	// ideal     parasitic b-c emission coefficient
	IBCNP@TNOM	0.0	// non-ideal parasitic b-c saturation current
	NCNP		2.0	// non-ideal parasitic b-c emission coefficient
	VEF		0.0	// fwd Early voltage, zero means infinity
	VER		0.0	// rev Early voltage, zero means infinity
	IKF		0.0	// fwd knee current, zero means infinity
	IKR		0.0	// rev knee current, zero means infinity
	IKP		0.0	// parasitic knee current, zero means infinity
	TF		0.0	// fwd transit time
	QTF		0.0	// variation of TF with base-width modulation
	XTF		0.0	// coeff. of TF bias dependence
	VTF		0.0	// coeff. of TF dependence on Vbc
	ITF		0.0	// coeff. of TF dependence in Ic
	TR		0.0	// rev transit time
	TD		0.0	// fwd excess-phase delay time
	KFN		0.0	// b-e flicker noise constant
	AFN		1.0	// b-e flicker noise exponent
	BFN		1.0	// b-e flicker noise 1/f dependence
	XRE		0.0	// temperature exponent of emit resistance
	XRB		0.0	// temperature exponent of base resistance
	XRC		0.0	// temperature exponent of coll resistance
	XRS		0.0	// temperature exponent of subs resistance
	XVO		0.0	// temperature exponent of VO
	EA		1.12	// activation energy   for IS
	EAIE		1.12	// activation energy   for IBEI
	EAIC		1.12	// activation energy   for IBCI/IBEIP
	EAIS		1.12	// activation energy   for IBCIP
	EANE		1.12	// activation energy   for IBEN
	EANC		1.12	// activation energy   for IBCN/IBENP
	EANS		1.12	// activation energy   for IBCNP
	XIS		3.0	// temperature exponent of IS
	XII		3.0	// temperature exponent of IBEI/IBCI/IBEIP/IBCIP
	XIN		3.0	// temperature exponent of IBEN/IBCN/IBENP/IBCNP
	TNF		0.0	// temperature coefficient of NF
	TAVC		0.0	// temperature coefficient of AVC2
	RTH		0.0	// thermal resistance
	CTH		0.0	// thermal capacitance

//	End of parameter list.
}

parameter aliases {

//	This section lists parameter aliases, primarily for paramaters
//	that contain the number 0 (zero) or the letter O.

	TNOM:	TN0M, TREF
	VO:	V0
	CBEO:	CBE0
	CBCO:	CBC0
	QCO:	QC0
	XVO:	XV0

//	End of parameter aliases.
}

temperature mappings {

//	This section defines mappings of temperature dependent parameters.
//	Note that with SELF-HEATING these mappings must be done at each
//	bias calculation, and cannot be relegated to preprocessing, because
//	the "voltage" for the local temperature rise delT must be taken
//	into account.

#ifdef SELF-HEATING
	Tdev  = TAMB + TABS + delT	// device temperature (K), with delT
#else
	Tdev  = TAMB + TABS		// device temperature (K)
#endif
	Tini  = TNOM + TABS		// TNOM in K

	Vtv   = KB * Tdev / QQ		// thermal voltage
	rT    = Tdev / Tini		// ratio Tdev/TNOM in K

	RCX   = RCX@TNOM * rT ^ XRC	// temperature mapping
	RCI   = RCI@TNOM * rT ^ XRC	// of resistances is
	RBX   = RBX@TNOM * rT ^ XRB	// according to mobility
	RBI   = RBI@TNOM * rT ^ XRB	// variation, which
	RE    = RE@TNOM  * rT ^ XRE	// should be same in
	RS    = RS@TNOM  * rT ^ XRS	// emit/coll & base/subs
	RBP   = RBP@TNOM * rT ^ XRC	// Note: RBP is in coll

//	Note: the following differs from the standard SPICE temperature
//	mappings for IS/ISE/BF. This is for two reasons. First, 
//	the base current is formulated directly in terms
//	of ideal and non-ideal currents rather than in terms of current
//	gain BF/transport current and non-ideal current. Second,
//	particularly for HBTs, using the bandgap in the first-order
//	theory expression for how IS should change with temperature often
//	gives a poor model. To properly track IS and beta (both low and
//	moderate bias) over temperature there is an activation energy
//	in the first-order model that is (slightly) different from the bandgap,
//	and is different for all of IS, IBEI and IBEN.
//	01/26/94: the b-e and b-c components show slightly different behavior
//	over temperature, so "activation energies" have been introduced for
//	ideal and non-ideal components of b-e, b-c and s-c junctions. This
//	allows separate fitting of forward and reverse beta curves over
//	temperature.

	IS    = IS@TNOM    * ( rT ^ XIS * exp ( - EA   * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NF@TNOM )
	ISP   = ISP@TNOM   * ( rT ^ XIS * exp ( - EA   * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NFP  )
	IBEI  = IBEI@TNOM  * ( rT ^ XII * exp ( - EAIE * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NEI  )
	IBEN  = IBEN@TNOM  * ( rT ^ XIN * exp ( - EANE * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NEN  )
	IBCI  = IBCI@TNOM  * ( rT ^ XII * exp ( - EAIC * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCI  )
	IBCN  = IBCN@TNOM  * ( rT ^ XIN * exp ( - EANC * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCN  )
	IBEIP = IBEIP@TNOM * ( rT ^ XII * exp ( - EAIC * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCI  )
	IBENP = IBENP@TNOM * ( rT ^ XIN * exp ( - EANC * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCN  )
	IBCIP = IBCIP@TNOM * ( rT ^ XII * exp ( - EAIS * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCIP )
	IBCNP = IBCNP@TNOM * ( rT ^ XIN * exp ( - EANS * ( 1.0 - rT ) / Vtv ) )\
			^ ( 1.0 / NCNP )

//	Linear temperature mappings for NF/NR and AVC2
//		Note: this is an undesirable type of temperature mapping,
//		as it cannot be done "in-place" because it does not have the
//		properties P(T1->T2->T3)=P(T1->T3) and P(T1->T2->T1)=P(T1).
//		For this model it is best to always map from P@TNOM.

	NF    =   NF@TNOM   * ( 1.0 + TNF   * ( Tdev - Tini ) ) 
	NR    =   NR@TNOM   * ( 1.0 + TNF   * ( Tdev - Tini ) ) 
	AVC2  = AVC2@TNOM   * ( 1.0 + TAVC  * ( Tdev - Tini ) ) 

//	Temperature mappings for built-in potentials

	PE    = psibi ( PE@TNOM, EAIE, Vtv, rT )
	PC    = psibi ( PC@TNOM, EAIC, Vtv, rT )
	PS    = psibi ( PS@TNOM, EAIS, Vtv, rT )

//	zero-bias capacitance temperature mappings come directly from the
//	first-order theory for p-n junction capacitance as:

	CJE   = CJE@TNOM  * ( PE@TNOM / PE ) ^ ME
	CJC   = CJC@TNOM  * ( PC@TNOM / PC ) ^ MC
	CJEP  = CJEP@TNOM * ( PC@TNOM / PC ) ^ MC
	CJCP  = CJCP@TNOM * ( PS@TNOM / PS ) ^ MS

//	Temperature mappings for epi parameters

	GAMM  = GAMM@TNOM * ( rT ^ XIS * exp ( - EA   * ( 1.0 - rT ) / Vtv ) )
	VO    = VO@TNOM   * rT ^ XVO

//	End of temperature mappings.
}

parameter checks {

//	This section defines constraints on model parameters. This is not
//	done in SPICE at present, but it should be an integral part
//	of a model, so is included here. This does not mean it can or will
//	be enforced/implemented in any particular simulator.

	0.0	<=	RCX
	0.0	<=	RCI
	0.0	<=	VO
	0.0	<=	GAMM
	0.0	<=	HRCF
	0.0	<=	RBX
	0.0	<=	RBI
	0.0	<=	RE
	0.0	<=	RBP
	0.0	<=	IS
	0.0	<	NF
	0.0	<	NR
	0.0	<=	CBEO
	0.0	<=	CJE
	0.0	<	PE
	0.0	<=	CBCO
	0.0	<=	CJC
	0.0	<=	CJEP
	0.0	<	PC
	0.0	<=	CJCP
	0.0	<	PS
	0.0	<=	IBEI
	0.0	<=	WBE	<=	1.0
	0.0	<	NEI	<	NEN
	0.0	<=	IBEN
	0.0	<=	IBCI
	0.0	<	NCI	<	NCN
	0.0	<=	IBCN
	0.0	<=	AVC1
	0.0	<=	AVC2
	0.0	<=	ISP
	0.0	<=	WSP	<=	1.0
	0.0	<	NFP
	0.0	<=	IBEIP
	0.0	<=	IBENP
	0.0	<=	IBCIP
	0.0	<	NCIP	<	NCNP
	0.0	<=	IBCNP
	0.0	<=	VEF
	0.0	<=	VER
	0.0	<=	IKF
	0.0	<=	IKR
	0.0	<=	IKP
	0.0	<=	TF
	0.0	<=	TR
#ifdef EXCESS-PHASE
	0.0	<	TD
#endif
	0.0	<=	KFN
	0.0	< 	AFN
	0.0	< 	BFN
	0.0	<=	XRE
	0.0	<=	XRB
	0.0	<=	XRC
	0.0	<=	XRS
#ifdef SELF-HEATING
	0.0	<=	RTH
	0.0	<=	CTH
#endif

//	End of parameter checks.
}

equations {

//	This section defines branch currents, charges. and fluxes as functions
//	of the branch voltages, currents, and model parameters.

//	First some bias-independent calculations

	if ( VEF <= 0.0 ) {
		IVEF = 0.0
	} else {
		IVEF = 1.0 / VEF
	}
	if ( VER <= 0.0 ) {
		IVER = 0.0
	} else {
		IVER = 1.0 / VER
	}
	if ( IKF <= 0.0 ) {
		IIKF = 0.0
	} else {
		IIKF = 1.0 / IKF
	}
	if ( IKR <= 0.0 ) {
		IIKR = 0.0
	} else {
		IIKR = 1.0 / IKR
	}
	if ( IKP <= 0.0 ) {
		IIKP = 0.0
	} else {
		IIKP = 1.0 / IKP
	}
	if ( VO  <= 0.0 ) {
		IVO  = 0.0
	} else {
		IVO  = 1.0 / VO
	}
	if ( HRCF <= 0.0 ) {
		IHRCF = 0.0
	} else {
		IHRCF = 1.0 / HRCF
	}
	if ( VTF <= 0.0 ) {
		IVTF = 0.0
	} else {
		IVTF = 1.0 / VTF
	}
	if ( ITF <= 0.0 ) {
		IITF = 0.0
		slTF = 1.0
	} else {
		IITF = 1.0 / ITF
		slTF = 0.0
	}
#ifdef EXCESS-PHASE
	if ( TD  <= 0.0 ) {
		LEP  = 0.0
		CEP  = 0.0
	} else {
		LEP  = TD / 3.0
		CEP  = TD
	}
#endif

//	Calculate normalized depletion charges

	qdbe  = qj ( Vbei, PE, ME, FC, AJE )	// b-e depletion charge
	qdbex = qj ( Vbex, PE, ME, FC, AJE )	// b-e depletion charge (side)
	qdbc  = qj ( Vbci, PC, MC, FC, AJC )	// b-c depletion charge
	qdbep = qj ( Vbep, PC, MC, FC, AJC )	// parasitic b-e deplt'n charge
					// Note that b-c and parasitic b-e
					// junctions are taken to have same
					// built-in potential and grading coeff.
	qdbcp = qj ( Vbcp, PS, MS, FC, AJS )	// parasitic b-c deplt'n charge

//	Transport currents and qb

	Itfi  = IS * ( exp ( Vbei / ( NF * Vtv ) ) - 1.0 )	// fwd ideal
	Itri  = IS * ( exp ( Vbci / ( NR * Vtv ) ) - 1.0 )	// rev ideal
	q1z   = 1.0 + qdbe * IVER + qdbc * IVEF			// proper q1
	q1    = 0.5 * ( sqrt ( ( q1z - 0.0001 ) ^ 2 + 0.0001 * 0.0001 ) \
			+ q1z - 0.0001 ) + 0.0001		// 1e-4 limit
	q2    = Itfi * IIKF + Itri * IIKR
	qb    = 0.5 * ( q1 + sqrt ( q1 * q1 + 4.0 * q2 ) )	// no limiting
	Itzr  = Itri / qb					// static rev
	Itzf  = Itfi / qb					// static fwd
#ifdef EXCESS-PHASE
	Flxf  = LEP * Ilxf					// flux in Lxf
	Qcxf  = CEP * Vcxf					// charge in Cxf
	Itxf  = Vrxf						// ex-ph fwd
#endif

//	Transport currents and qb of the parasitic, to give Iccp

	Itfp  = ISP * ( WSP * exp ( Vbep / ( NFP * Vtv ) ) \
			+ ( 1.0 - WSP ) * exp ( Vbci / ( NFP * Vtv ) ) - 1.0 )
	Itrp  = ISP * ( exp ( Vbcp / ( NFP * Vtv ) ) - 1.0 )
	q2p   = Itfp * IIKP				// only fwd part
	qbp   = 0.5 * ( 1.0 + sqrt ( 1.0 + 4.0 * q2p ) )// no Early effect
	Iccp  = ( Itfp - Itrp ) / qbp			// parasitic transport I

//	Currents in resistors, with nodes collapsed for zero resistance
//	Note that RBI, RCI and RBP are modulated

	if ( RCX  <= 0.0 ) {
		collapse ( c , cx )
	} else {
		Ircx  = Vrcx / RCX
	}

	if ( RCI  <= 0.0 ) {
		collapse ( cx, ci )
		Kbci  = 0.0
		Kbcx  = 0.0
	} else {			// modified Kull quasi-sat model
		Vbcx  = Vbci - Vrci
		Kbci  = sqrt ( 1.0 + GAMM * exp ( Vbci / Vtv ) )
		Kbcx  = sqrt ( 1.0 + GAMM * exp ( Vbcx / Vtv ) )
		rKp1  = ( Kbci + 1.0 ) / ( Kbcx + 1.0 )
		Iohm  = ( Vrci + Vtv * ( Kbci - Kbcx - log ( rKp1 ) ) ) / RCI
		derf  = IVO * RCI * Iohm / ( 1.0 + 0.5 * IVO * IHRCF * \
			sqrt ( Vrci * Vrci +  0.01 ) )
		Irci  = Iohm / sqrt ( 1.0 + derf * derf  )
	}

	if ( RBX  <= 0.0 ) {
		collapse ( b , bx )
	} else {
		Irbx  = Vrbx / RBX
	}

	if ( RBI  <= 0.0 ) {
		collapse ( bx, bi )
	} else {
		Irbi  = Vrbi * qb / RBI	// simple qb modulation model for now,
					// other models to be defined.
					// Irbi=Irbi(Vrbi,Vbei,Vbci) because
					// qb  =qb  (     Vbei,Vbci)
	}

	if ( RE   <= 0.0 ) {
		collapse ( e , ei )
	} else {
		Ire   = Vre  / RE
	}

	if ( RS   <= 0.0 ) {
		collapse ( s , si )
	} else {
		Irs   = Vrs  / RS
	}

	if ( RBP <= 0.0 ) {
		collapse ( cx, bp )
	} else {
		Irbp  = Vrbp * qbp / RBP	// Irbp=Irbp(Vrbp,Vbep) because
						// qbp = qbp(     Vbep)
	}

//	b-e and b-c components of base current of intrinsic device

	Ibe   = WBE * \
		(   IBEI  * ( exp ( Vbei / ( NEI  * Vtv ) ) - 1.0 ) \
		  + IBEN  * ( exp ( Vbei / ( NEN  * Vtv ) ) - 1.0 ) )
	Ibex  = ( 1.0 - WBE ) * \
		(   IBEI  * ( exp ( Vbex / ( NEI  * Vtv ) ) - 1.0 ) \
		  + IBEN  * ( exp ( Vbex / ( NEN  * Vtv ) ) - 1.0 ) )
	Ibc   = (   IBCI  * ( exp ( Vbci / ( NCI  * Vtv ) ) - 1.0 ) \
		  + IBCN  * ( exp ( Vbci / ( NCN  * Vtv ) ) - 1.0 ) )

//	Parasitic b-e current, with calculation bypass for efficiency
//	Emission coefficients are same as for intrinsic b-c, as they
//	are the same junction

	if ( IBEIP <= 0.0 && IBENP <= 0.0 ) {
		Ibep  =   0.0
	} else {
		Ibep  =   IBEIP * ( exp ( Vbep / ( NCI * Vtv ) ) - 1.0 ) \
			+ IBENP * ( exp ( Vbep / ( NCN * Vtv ) ) - 1.0 )
	}

//	Parasitic b-c current, with calculation bypass for efficiency.
//	This element should normally never be of importance, but is
//	included to detect incorrect biasing, a useful task.

	if ( IBCIP <= 0.0 && IBCNP <= 0.0 ) {
		Ibcp  =   0.0
	} else {
		Ibcp  =   IBCIP * ( exp ( Vbcp / ( NCIP * Vtv ) ) - 1.0 ) \
			+ IBCNP * ( exp ( Vbcp / ( NCNP * Vtv ) ) - 1.0 )
	}

//	b-c weak avalanche current

	if ( AVC1 <= 0.0 ) {
		Igc   = 0.0
	} else {
		Igc = ( Itzf - Itzr - Ibc ) * avalm ( Vbci, PC, MC, AVC1, AVC2 )
	}

//	Charge elements, Qbe diffusion charge is not split at present

//	This is the only place where C-inf continuity is broken, as the
//	SPICE forward transit time bias dependence, which includes "if"
//	conditions, is used

	sgItf = 0.0
	if ( Itfi > 0.0 ) {
		sgItf = 1.0
	}
	rItf  = Itfi * sgItf * IITF
	tff   = TF * ( 1.0 + QTF * q1 ) * \
		( 1.0 + XTF * exp ( Vbci * IVTF / 1.44 ) \
			* ( slTF + ( rItf / ( rItf + 1.0 ) ) ^ 2 ) * sgItf )
	Qbe   = CJE  * qdbe  * WBE           + tff * Itfi / qb
	Qbex  = CJE  * qdbex * ( 1.0 - WBE )
	Qbc   = CJC  * qdbc                  + TR  * Itri      + QCO * Kbci
	Qbcx  =                                                  QCO * Kbcx
	Qbep  = CJEP * qdbep                 + TR  * Itfp
	Qbcp  = CJCP * qdbcp			// no diffusion charge
	Qbeo  = CBEO * Vbe			// extrinsic b-e overlap charge
	Qbco  = CBCO * Vbc			// extrinsic b-c overlap charge

#ifdef SELF-HEATING

//	Thermal power generation must be done by summing I*V over all
//	non-energy storage elements of the electrical model

	if ( RTH  <= 0.0 ) {
		collapse ( dt , tl )
	} else {
		Ith   =   Ibe  * Vbei + Ibc  * Vbci \
			+ ( Itzf - Itzr ) * ( Vbei - Vbci ) \
			+ Ibep * Vbep + Ibcp * Vbcp + Iccp * ( Vbep - Vbcp ) \
			+ Ircx * Vrcx + Irci * Vrci + Irbx * Vrbx \
			+ Irbi * Vrbi + Ire  * Vre  + Irbp * Vrbp \
			+ Irs  * Vrs  + Ibex * Vbex - Igc  * Vbci

//		Simple linear thermal resistance and capacitance, could be
//		made nonlinear if necessary

		Irth  = delT / RTH

		Qcth  = CTH  * delT
	}
#endif

//	End of equations.
}

noise {

//	This section defines noise current generators, in A^2/Hz, which
//	(for noise analyses) are connected in parallel with the linearized
//	(small-signal) element. NOTES: noise models are a function of
//	defined branch currents, and derivatives of branch currents w.r.t.
//	defined branch voltages, indicated by an underscore "_". Device
//	temperature "Tdev" and simulation frequency "FREQ" are from
//	temperature section and simulator (defined as extern), respectively.

	Itzf:	2.0 * QQ * Itzf				// Itzf  shot noise
	Ibe:	2.0 * QQ * Ibe \			// Ibe shot noise
		  + KFN * Ibe ^ AFN / FREQ ^ BFN	//   and 1/f noise
	Ircx:	4.0 * KB * Tdev * Ircx_Vrcx		// RCX  thermal noise
	Irci:	4.0 * KB * Tdev * Irci_Vrci		// RCI  thermal noise
	Irbx:	4.0 * KB * Tdev * Irbx_Vrbx		// RBX  thermal noise
	Irbi:	4.0 * KB * Tdev * Irbi_Vrbi		// RBI  thermal noise
	Ire:	4.0 * KB * Tdev * Ire_Vre		// RE   thermal noise
	Irs:	4.0 * KB * Tdev * Irs_Vrs		// RS   thermal noise
	Iccp:	2.0 * QQ * Iccp				// Iccp shot noise
	Ibep:	2.0 * QQ * Ibep \			// Ibep shot noise
		  + KFN * Ibep ^ AFN / FREQ ^ BFN	//   and 1/f noise
	Irbp:	4.0 * KB * Tdev * Irbp_Vrbp		// RBP thermal noise

//	End of noise equations.
}

//	End of model definition.
}