diff --git a/src/spicelib/devices/res/res.c b/src/spicelib/devices/res/res.c index f1aa474a6..693489766 100644 --- a/src/spicelib/devices/res/res.c +++ b/src/spicelib/devices/res/res.c @@ -10,51 +10,51 @@ Modified: 2000 AlansFixes #include "ngspice/devdefs.h" #include "ngspice/ifsim.h" -IFparm RESpTable[] = { /* parameters */ - IOPP( "resistance", RES_RESIST, IF_REAL, "Resistance"), - IOPAA( "ac", RES_ACRESIST, IF_REAL, "AC resistance value"), - IOPZU( "temp", RES_TEMP, IF_REAL, "Instance operating temperature"), - IOPZ( "dtemp", RES_DTEMP, IF_REAL, - "Instance temperature difference with the rest of the circuit"), - IOPQU( "l", RES_LENGTH, IF_REAL, "Length"), - IOPZU( "w", RES_WIDTH, IF_REAL, "Width"), - IOPU( "m", RES_M, IF_REAL, "Multiplication factor"), - IOPU( "tc", RES_TC1, IF_REAL, "First order temp. coefficient"), - IOPU( "tc1", RES_TC1, IF_REAL, "First order temp. coefficient"), - IOPU( "tc2", RES_TC2, IF_REAL, "Second order temp. coefficient"), - IOPU( "scale", RES_SCALE, IF_REAL, "Scale factor"), - IOP( "noisy", RES_NOISY, IF_INTEGER, "Resistor generate noise"), - IP( "sens_resist", RES_RESIST_SENS, IF_FLAG, - "flag to request sensitivity WRT resistance"), - OP( "i", RES_CURRENT, IF_REAL, "Current"), - OP( "p", RES_POWER, IF_REAL, "Power"), - OPU( "sens_dc", RES_QUEST_SENS_DC, IF_REAL, "dc sensitivity "), - OPU( "sens_real", RES_QUEST_SENS_REAL, IF_REAL, - "dc sensitivity and real part of ac sensitivity"), - OPU( "sens_imag", RES_QUEST_SENS_IMAG, IF_REAL, - "dc sensitivity and imag part of ac sensitivity"), - OPU( "sens_mag", RES_QUEST_SENS_MAG, IF_REAL, "ac sensitivity of magnitude"), - OPU( "sens_ph", RES_QUEST_SENS_PH, IF_REAL, "ac sensitivity of phase"), - OPU( "sens_cplx", RES_QUEST_SENS_CPLX, IF_COMPLEX, "ac sensitivity") +IFparm RESpTable[] = { /* parameters */ + IOPP( "resistance", RES_RESIST, IF_REAL, "Resistance"), + IOPAA( "ac", RES_ACRESIST, IF_REAL, "AC resistance value"), + IOPZU( "temp", RES_TEMP, IF_REAL, "Instance operating temperature"), + IOPZ( "dtemp", RES_DTEMP, IF_REAL, + "Instance temperature difference with the rest of the circuit"), + IOPQU( "l", RES_LENGTH, IF_REAL, "Length"), + IOPZU( "w", RES_WIDTH, IF_REAL, "Width"), + IOPU( "m", RES_M, IF_REAL, "Multiplication factor"), + IOPU( "tc", RES_TC1, IF_REAL, "First order temp. coefficient"), + IOPU( "tc1", RES_TC1, IF_REAL, "First order temp. coefficient"), + IOPU( "tc2", RES_TC2, IF_REAL, "Second order temp. coefficient"), + IOPU( "scale", RES_SCALE, IF_REAL, "Scale factor"), + IOP( "noisy", RES_NOISY, IF_INTEGER, "Resistor generate noise"), + IP( "sens_resist", RES_RESIST_SENS, IF_FLAG, + "flag to request sensitivity WRT resistance"), + OP( "i", RES_CURRENT, IF_REAL, "Current"), + OP( "p", RES_POWER, IF_REAL, "Power"), + OPU( "sens_dc", RES_QUEST_SENS_DC, IF_REAL, "dc sensitivity "), + OPU( "sens_real", RES_QUEST_SENS_REAL, IF_REAL, + "dc sensitivity and real part of ac sensitivity"), + OPU( "sens_imag", RES_QUEST_SENS_IMAG, IF_REAL, + "dc sensitivity and imag part of ac sensitivity"), + OPU( "sens_mag", RES_QUEST_SENS_MAG, IF_REAL, "ac sensitivity of magnitude"), + OPU( "sens_ph", RES_QUEST_SENS_PH, IF_REAL, "ac sensitivity of phase"), + OPU( "sens_cplx", RES_QUEST_SENS_CPLX, IF_COMPLEX, "ac sensitivity") }; IFparm RESmPTable[] = { /* model parameters */ - IOPQ( "rsh", RES_MOD_RSH, IF_REAL,"Sheet resistance"), - IOPZ( "narrow", RES_MOD_NARROW, IF_REAL,"Narrowing of resistor"), - IOPR( "dw", RES_MOD_NARROW, IF_REAL,"Narrowing of resistor"), - IOPZ( "short", RES_MOD_SHORT, IF_REAL,"Shortening of resistor"), - IOPR( "dlr", RES_MOD_SHORT, IF_REAL,"Shortening of resistor"), - IOPQ( "tc1", RES_MOD_TC1, IF_REAL,"First order temp. coefficient"), - IOPR( "tc1r", RES_MOD_TC1, IF_REAL,"First order temp. coefficient"), - IOPQO( "tc2", RES_MOD_TC2, IF_REAL,"Second order temp. coefficient"), - IOPR( "tc2r", RES_MOD_TC2, IF_REAL,"Second order temp. coefficient"), - IOPX( "defw", RES_MOD_DEFWIDTH, IF_REAL,"Default device width"), - IOPR( "w", RES_MOD_DEFWIDTH, IF_REAL,"Default device width"), - IOPX( "l", RES_MOD_DEFLENGTH,IF_REAL,"Default device length"), - IOPQ( "kf", RES_MOD_KF, IF_REAL,"Flicker noise coefficient"), - IOPQ( "af", RES_MOD_AF, IF_REAL,"Flicker noise exponent"), - IOPXU( "tnom", RES_MOD_TNOM, IF_REAL,"Parameter measurement temperature"), - IP( "r", RES_MOD_R, IF_FLAG,"Device is a resistor model") + IOPQ( "rsh", RES_MOD_RSH, IF_REAL,"Sheet resistance"), + IOPZ( "narrow", RES_MOD_NARROW, IF_REAL,"Narrowing of resistor"), + IOPR( "dw", RES_MOD_NARROW, IF_REAL,"Narrowing of resistor"), + IOPZ( "short", RES_MOD_SHORT, IF_REAL,"Shortening of resistor"), + IOPR( "dlr", RES_MOD_SHORT, IF_REAL,"Shortening of resistor"), + IOPQ( "tc1", RES_MOD_TC1, IF_REAL,"First order temp. coefficient"), + IOPR( "tc1r", RES_MOD_TC1, IF_REAL,"First order temp. coefficient"), + IOPQO( "tc2", RES_MOD_TC2, IF_REAL,"Second order temp. coefficient"), + IOPR( "tc2r", RES_MOD_TC2, IF_REAL,"Second order temp. coefficient"), + IOPX( "defw", RES_MOD_DEFWIDTH, IF_REAL,"Default device width"), + IOPR( "w", RES_MOD_DEFWIDTH, IF_REAL,"Default device width"), + IOPX( "l", RES_MOD_DEFLENGTH,IF_REAL,"Default device length"), + IOPQ( "kf", RES_MOD_KF, IF_REAL,"Flicker noise coefficient"), + IOPQ( "af", RES_MOD_AF, IF_REAL,"Flicker noise exponent"), + IOPXU( "tnom", RES_MOD_TNOM, IF_REAL,"Parameter measurement temperature"), + IP( "r", RES_MOD_R, IF_FLAG,"Device is a resistor model") }; char *RESnames[] = { diff --git a/src/spicelib/devices/res/resdefs.h b/src/spicelib/devices/res/resdefs.h index eebda4793..3aaec4fb1 100644 --- a/src/spicelib/devices/res/resdefs.h +++ b/src/spicelib/devices/res/resdefs.h @@ -13,14 +13,14 @@ Modified: 2000 AlansFixes #include "ngspice/complex.h" #include "ngspice/noisedef.h" - /* definitions used to describe resistors */ +/* definitions used to describe resistors */ /* information used to describe a single instance */ typedef struct sRESinstance { struct sRESmodel *RESmodPtr; /* backpointer to model */ - struct sRESinstance *RESnextInstance; /* pointer to next instance of + struct sRESinstance *RESnextInstance; /* pointer to next instance of * current model*/ IFuid RESname; /* pointer to character string naming this instance */ @@ -33,7 +33,7 @@ typedef struct sRESinstance { double RESconduct; /* conductance at current analysis temperature */ double RESresist; /* resistance at temperature Tnom */ double REScurrent; /* The dc current in the resistor */ -/* serban */ + /* serban */ double RESacResist; /* AC resistance, useful for fancy .ac analyses */ double RESacConduct; /* AC conductance */ double RESwidth; /* width of the resistor */ @@ -43,13 +43,13 @@ typedef struct sRESinstance { double REStc1; /* first temperature coefficient of resistors */ double REStc2; /* second temperature coefficient of resistors */ int RESnoisy; /* Set if the resistor generates noise */ - double *RESposPosptr; /* pointer to sparse matrix diagonal at + double *RESposPosptr; /* pointer to sparse matrix diagonal at * (positive,positive) */ - double *RESnegNegptr; /* pointer to sparse matrix diagonal at + double *RESnegNegptr; /* pointer to sparse matrix diagonal at * (negative,negative) */ - double *RESposNegptr; /* pointer to sparse matrix offdiagonal at + double *RESposNegptr; /* pointer to sparse matrix offdiagonal at * (positive,negative) */ - double *RESnegPosptr; /* pointer to sparse matrix offdiagonal at + double *RESnegPosptr; /* pointer to sparse matrix offdiagonal at * (negative,positive) */ unsigned RESresGiven : 1; /* flag to indicate resistance was specified */ unsigned RESwidthGiven : 1; /* flag to indicate width given */ @@ -57,7 +57,7 @@ typedef struct sRESinstance { unsigned RESscaleGiven : 1; /* flag to indicate scale given */ unsigned REStempGiven : 1; /* indicates temperature specified */ unsigned RESdtempGiven : 1; /* indicates delta-temp specified */ -/* serban */ + /* serban */ unsigned RESacresGiven : 1; /* indicates AC value specified */ unsigned RESmGiven : 1; /* indicates M parameter specified */ unsigned REStc1Given : 1; /* indicates tc1 parameter specified */ @@ -66,7 +66,7 @@ typedef struct sRESinstance { int RESsenParmNo; /* parameter # for sensitivity use; * set equal to 0 if not a design parameter*/ -/* indices to array of RES noise sources */ + /* indices to array of RES noise sources */ #define RESTHNOIZ 0 /* Thermal noise source */ #define RESFLNOIZ 1 /* Flicker noise source */ @@ -88,7 +88,7 @@ typedef struct sRESinstance { typedef struct sRESmodel { /* model structure for a resistor */ int RESmodType; /* type index of this device type */ - struct sRESmodel *RESnextModel; /* pointer to next possible model in + struct sRESmodel *RESnextModel; /* pointer to next possible model in * linked list */ RESinstance * RESinstances; /* pointer to list of instances that have this * model */ diff --git a/src/spicelib/devices/res/resload.c b/src/spicelib/devices/res/resload.c index 5720661ba..65cf44fbe 100644 --- a/src/spicelib/devices/res/resload.c +++ b/src/spicelib/devices/res/resload.c @@ -17,23 +17,23 @@ RESload(GENmodel *inModel, CKTcircuit *ckt) { RESmodel *model = (RESmodel *)inModel; double m; - + /* loop through all the resistor models */ for( ; model != NULL; model = model->RESnextModel ) { RESinstance *here; /* loop through all the instances of the model */ for (here = model->RESinstances; here != NULL ; - here = here->RESnextInstance) { - - here->REScurrent = (*(ckt->CKTrhsOld+here->RESposNode) - - *(ckt->CKTrhsOld+here->RESnegNode)) * here->RESconduct; + here = here->RESnextInstance) { - m = (here->RESm); - *(here->RESposPosptr) += m * here->RESconduct; - *(here->RESnegNegptr) += m * here->RESconduct; - *(here->RESposNegptr) -= m * here->RESconduct; - *(here->RESnegPosptr) -= m * here->RESconduct; + here->REScurrent = (*(ckt->CKTrhsOld+here->RESposNode) - + *(ckt->CKTrhsOld+here->RESnegNode)) * here->RESconduct; + + m = (here->RESm); + *(here->RESposPosptr) += m * here->RESconduct; + *(here->RESnegNegptr) += m * here->RESconduct; + *(here->RESposNegptr) -= m * here->RESconduct; + *(here->RESnegPosptr) -= m * here->RESconduct; } } return(OK); @@ -56,9 +56,9 @@ RESacload(GENmodel *inModel, CKTcircuit *ckt) /* loop through all the instances of the model */ for (here = model->RESinstances; here != NULL ; - here = here->RESnextInstance) { - - if(!here->RESmGiven) + here = here->RESnextInstance) { + + if(!here->RESmGiven) here->RESm = 1.0; m = (here->RESm); diff --git a/src/spicelib/devices/res/resmpar.c b/src/spicelib/devices/res/resmpar.c index 172d01247..c5c5896e4 100644 --- a/src/spicelib/devices/res/resmpar.c +++ b/src/spicelib/devices/res/resmpar.c @@ -16,55 +16,55 @@ int RESmParam(int param, IFvalue *value, GENmodel *inModel) { RESmodel *model = (RESmodel *)inModel; - + switch(param) { - case RES_MOD_TNOM: - model->REStnom = value->rValue+CONSTCtoK; - model->REStnomGiven = TRUE; - break; - case RES_MOD_TC1: - model->REStempCoeff1 = value->rValue; - model->REStc1Given = TRUE; - break; - case RES_MOD_TC2: - model->REStempCoeff2 = value->rValue; - model->REStc2Given = TRUE; - break; - case RES_MOD_RSH: - model->RESsheetRes = value->rValue; - model->RESsheetResGiven = TRUE; - break; - case RES_MOD_DEFWIDTH: - model->RESdefWidth = value->rValue; - model->RESdefWidthGiven = TRUE; - break; - case RES_MOD_DEFLENGTH: - model->RESdefLength = value->rValue; - model->RESdefLengthGiven = TRUE; - break; - case RES_MOD_NARROW: - model->RESnarrow = value->rValue; - model->RESnarrowGiven = TRUE; - break; - case RES_MOD_SHORT: - model->RESshort = value->rValue; - model->RESshortGiven = TRUE; - break; - case RES_MOD_KF: - model->RESfNcoef = value->rValue; - model->RESfNcoefGiven = TRUE; - break; - case RES_MOD_AF: - model->RESfNexp = value->rValue; - model->RESfNexpGiven = TRUE; - break; - - case RES_MOD_R: - /* just being reassured by user that this is a resistor model */ - /* no-op */ - break; - default: - return(E_BADPARM); + case RES_MOD_TNOM: + model->REStnom = value->rValue+CONSTCtoK; + model->REStnomGiven = TRUE; + break; + case RES_MOD_TC1: + model->REStempCoeff1 = value->rValue; + model->REStc1Given = TRUE; + break; + case RES_MOD_TC2: + model->REStempCoeff2 = value->rValue; + model->REStc2Given = TRUE; + break; + case RES_MOD_RSH: + model->RESsheetRes = value->rValue; + model->RESsheetResGiven = TRUE; + break; + case RES_MOD_DEFWIDTH: + model->RESdefWidth = value->rValue; + model->RESdefWidthGiven = TRUE; + break; + case RES_MOD_DEFLENGTH: + model->RESdefLength = value->rValue; + model->RESdefLengthGiven = TRUE; + break; + case RES_MOD_NARROW: + model->RESnarrow = value->rValue; + model->RESnarrowGiven = TRUE; + break; + case RES_MOD_SHORT: + model->RESshort = value->rValue; + model->RESshortGiven = TRUE; + break; + case RES_MOD_KF: + model->RESfNcoef = value->rValue; + model->RESfNcoefGiven = TRUE; + break; + case RES_MOD_AF: + model->RESfNexp = value->rValue; + model->RESfNexpGiven = TRUE; + break; + + case RES_MOD_R: + /* just being reassured by user that this is a resistor model */ + /* no-op */ + break; + default: + return(E_BADPARM); } return(OK); } diff --git a/src/spicelib/devices/res/resparam.c b/src/spicelib/devices/res/resparam.c index 8156a8160..a11505f2e 100644 --- a/src/spicelib/devices/res/resparam.c +++ b/src/spicelib/devices/res/resparam.c @@ -19,59 +19,59 @@ RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); switch(param) { - case RES_TEMP: - here->REStemp = value->rValue + CONSTCtoK; - here->REStempGiven = TRUE; - break; - case RES_DTEMP: - here->RESdtemp = value->rValue; - here->RESdtempGiven = TRUE; - break; - case RES_RESIST: - /* 0 valued resistor causes ngspice to hang -- can't solve for initial voltage */ - if ( AlmostEqualUlps( value->rValue, 0, 3 ) ) value->rValue = 0.001; /* 0.0001 should be sufficiently small */ - /* it's the value that smartspice uses */ + case RES_TEMP: + here->REStemp = value->rValue + CONSTCtoK; + here->REStempGiven = TRUE; + break; + case RES_DTEMP: + here->RESdtemp = value->rValue; + here->RESdtempGiven = TRUE; + break; + case RES_RESIST: + /* 0 valued resistor causes ngspice to hang -- can't solve for initial voltage */ + if ( AlmostEqualUlps( value->rValue, 0, 3 ) ) value->rValue = 0.001; /* 0.0001 should be sufficiently small */ + /* it's the value that smartspice uses */ - here->RESresist = value->rValue; - here->RESresGiven = TRUE; - break; - case RES_ACRESIST: - here->RESacResist = value->rValue; - here->RESacresGiven = TRUE; - break; - case RES_WIDTH: - here->RESwidth = value->rValue; - here->RESwidthGiven = TRUE; - break; - case RES_LENGTH: - here->RESlength = value->rValue; - here->RESlengthGiven = TRUE; - break; - case RES_SCALE: - here->RESscale = value->rValue; - here->RESscaleGiven = TRUE; - break; - case RES_RESIST_SENS: - here->RESsenParmNo = value->iValue; - break; - case RES_M: - here->RESm = value->rValue; - here->RESmGiven = TRUE; - break; - case RES_TC1: - here->REStc1 = value->rValue; - here->REStc1Given = TRUE; - break; - case RES_TC2: - here->REStc2 = value->rValue; - here->REStc2Given = TRUE; - break; - case RES_NOISY: - here->RESnoisy = value->iValue; - here->RESnoisyGiven = TRUE; - break; - default: - return(E_BADPARM); + here->RESresist = value->rValue; + here->RESresGiven = TRUE; + break; + case RES_ACRESIST: + here->RESacResist = value->rValue; + here->RESacresGiven = TRUE; + break; + case RES_WIDTH: + here->RESwidth = value->rValue; + here->RESwidthGiven = TRUE; + break; + case RES_LENGTH: + here->RESlength = value->rValue; + here->RESlengthGiven = TRUE; + break; + case RES_SCALE: + here->RESscale = value->rValue; + here->RESscaleGiven = TRUE; + break; + case RES_RESIST_SENS: + here->RESsenParmNo = value->iValue; + break; + case RES_M: + here->RESm = value->rValue; + here->RESmGiven = TRUE; + break; + case RES_TC1: + here->REStc1 = value->rValue; + here->REStc1Given = TRUE; + break; + case RES_TC2: + here->REStc2 = value->rValue; + here->REStc2Given = TRUE; + break; + case RES_NOISY: + here->RESnoisy = value->iValue; + here->RESnoisyGiven = TRUE; + break; + default: + return(E_BADPARM); } return(OK); } diff --git a/src/spicelib/devices/res/restemp.c b/src/spicelib/devices/res/restemp.c index 64b091c3b..bd19bd03b 100644 --- a/src/spicelib/devices/res/restemp.c +++ b/src/spicelib/devices/res/restemp.c @@ -1,7 +1,7 @@ /********** Copyright 1990 Regents of the University of California. All rights reserved. Author: 1985 Thomas L. Quarles -Modified Apr 2000 - Paolo Nenzi +Modified Apr 2000 - Paolo Nenzi Modified: 2000 AlanSfixes **********/ @@ -12,12 +12,12 @@ Modified: 2000 AlanSfixes int REStemp(GENmodel *inModel, CKTcircuit *ckt) - /* perform the temperature update to the resistors - * calculate the conductance as a function of the - * given nominal and current temperatures - the - * resistance given in the struct is the nominal - * temperature resistance - */ +/* perform the temperature update to the resistors + * calculate the conductance as a function of the + * given nominal and current temperatures - the + * resistance given in the struct is the nominal + * temperature resistance + */ { RESmodel *model = (RESmodel *)inModel; RESinstance *here; @@ -46,16 +46,16 @@ REStemp(GENmodel *inModel, CKTcircuit *ckt) here=here->RESnextInstance) { /* Default Value Processing for Resistor Instance */ - - if(!here->REStempGiven) { - here->REStemp = ckt->CKTtemp; - if(!here->RESdtempGiven) here->RESdtemp = 0.0; - } else { /* REStempGiven */ - here->RESdtemp = 0.0; - if (here->RESdtempGiven) - printf("%s: Instance temperature specified, dtemp ignored\n", here->RESname); - } - + + if(!here->REStempGiven) { + here->REStemp = ckt->CKTtemp; + if(!here->RESdtempGiven) here->RESdtemp = 0.0; + } else { /* REStempGiven */ + here->RESdtemp = 0.0; + if (here->RESdtempGiven) + printf("%s: Instance temperature specified, dtemp ignored\n", here->RESname); + } + if(!here->RESwidthGiven) here->RESwidth = model->RESdefWidth; if(!here->RESlengthGiven) here->RESlength = model->RESdefLength; if(!here->RESscaleGiven) here->RESscale = 1.0; @@ -65,16 +65,16 @@ REStemp(GENmodel *inModel, CKTcircuit *ckt) if(model->RESsheetResGiven && (model->RESsheetRes != 0) && (here->RESlength != 0)) { here->RESresist = model->RESsheetRes * (here->RESlength - - model->RESshort) / (here->RESwidth - model->RESnarrow); + model->RESshort) / (here->RESwidth - model->RESnarrow); } else { SPfrontEnd->IFerror (ERR_WARNING, - "%s: resistance = 0 ohm, set to 1000 ohm",&(here->RESname)); + "%s: resistance = 0 ohm, set to 1000 ohm",&(here->RESname)); here->RESresist=1000; } } difference = (here->REStemp + here->RESdtemp) - model->REStnom; - + /* instance parameters tc1 and tc2 will override model parameters tc1 and tc2 */ if (here->REStc1Given) @@ -88,17 +88,17 @@ REStemp(GENmodel *inModel, CKTcircuit *ckt) tc2 = model->REStempCoeff2; factor = 1.0 + tc1*difference + - tc2*difference*difference; + tc2*difference*difference; here -> RESconduct = (1.0/(here->RESresist * factor * here->RESscale)); - + /* Paolo Nenzi: AC value */ - if(here->RESacresGiven) - here->RESacConduct = (1.0/(here->RESacResist * factor * here->RESscale)); + if(here->RESacresGiven) + here->RESacConduct = (1.0/(here->RESacResist * factor * here->RESscale)); else { - here -> RESacConduct = here -> RESconduct; - here -> RESacResist = here -> RESresist; - } + here -> RESacConduct = here -> RESconduct; + here -> RESacResist = here -> RESresist; + } } } return(OK);