From f073fb5c0555d1202c32e5905946190a9920c914 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 8 Jul 2022 09:31:07 +0200 Subject: [PATCH] Consecutive tran and ac simulation may lead to gross errors when TC or scale is used on the instance line of C and L. Reason is the missing reset when CKTtemp is called once during each simulation command. TC or scale is then applied again and again, a reset is missing. This patch adds a reset, i.e. the capacitance or inductance is reset to its instance value in a call to *temp. It fixes bug#594. Command 'alter' has been tested. Resistance has not been tackled by this bug, because the line here->RESconduct = here->RESm / (here->RESresist * factor * here->RESscale); differs from here->CAPcapac = here->CAPcapac * factor * here->CAPscale; in that there is no accumulation of correction factors with here->RESconduct --- src/spicelib/devices/cap/capdefs.h | 1 + src/spicelib/devices/cap/capparam.c | 2 +- src/spicelib/devices/cap/captemp.c | 9 ++++++--- src/spicelib/devices/ind/inddefs.h | 1 + src/spicelib/devices/ind/indparam.c | 2 +- src/spicelib/devices/ind/indtemp.c | 3 +++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/spicelib/devices/cap/capdefs.h b/src/spicelib/devices/cap/capdefs.h index b7c0e5854..1b188ceda 100644 --- a/src/spicelib/devices/cap/capdefs.h +++ b/src/spicelib/devices/cap/capdefs.h @@ -33,6 +33,7 @@ typedef struct sCAPinstance { double CAPtemp; /* temperature at which this capacitor operates */ double CAPdtemp; /* delta-temperature of this instance */ double CAPcapac; /* capacitance */ + double CAPcapacinst;/* capacitance on instance line */ double CAPinitCond; /* initial capacitor voltage if specified */ double CAPwidth; /* width of the capacitor */ double CAPlength; /* length of the capacitor */ diff --git a/src/spicelib/devices/cap/capparam.c b/src/spicelib/devices/cap/capparam.c index 0e030ceef..ea5ca9f35 100644 --- a/src/spicelib/devices/cap/capparam.c +++ b/src/spicelib/devices/cap/capparam.c @@ -29,7 +29,7 @@ CAPparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) switch(param) { case CAP_CAP: - here->CAPcapac = value->rValue; + here->CAPcapacinst = here->CAPcapac = value->rValue; if (!here->CAPmGiven) here->CAPm = 1.0; here->CAPcapGiven = TRUE; diff --git a/src/spicelib/devices/cap/captemp.c b/src/spicelib/devices/cap/captemp.c index 926a3c666..319188f07 100644 --- a/src/spicelib/devices/cap/captemp.c +++ b/src/spicelib/devices/cap/captemp.c @@ -52,7 +52,7 @@ CAPtemp(GENmodel *inModel, CKTcircuit *ckt) if (!here->CAPscaleGiven) here->CAPscale = 1.0; if (!here->CAPmGiven) here->CAPm = 1.0; - if (!here->CAPcapGiven) { /* No instance capacitance given */ + if (!here->CAPcapGiven) { /* No instance capacitance given */ if (!model->CAPmCapGiven) { /* No model capacitange given */ here->CAPcapac = model->CAPcj * @@ -60,11 +60,14 @@ CAPtemp(GENmodel *inModel, CKTcircuit *ckt) (here->CAPlength - model->CAPshort) + model->CAPcjsw * 2 * ( (here->CAPlength - model->CAPshort) + - (here->CAPwidth - model->CAPnarrow) ); - } else { + (here->CAPwidth - model->CAPnarrow)); + } + else { here->CAPcapac = model->CAPmCap; } } + else + here->CAPcapac = here->CAPcapacinst; /* reset capacitance to instance value */ difference = (here->CAPtemp + here->CAPdtemp) - model->CAPtnom; diff --git a/src/spicelib/devices/ind/inddefs.h b/src/spicelib/devices/ind/inddefs.h index f39d152ed..41ef790de 100644 --- a/src/spicelib/devices/ind/inddefs.h +++ b/src/spicelib/devices/ind/inddefs.h @@ -36,6 +36,7 @@ struct sINDinstance { int INDbrEq; /* number of the branch equation added for current */ double INDinduct; /* inductance */ + double INDinductinst;/* inductance on instance line */ double INDm; /* Parallel multiplier */ double INDtc1; /* first temperature coefficient of resistors */ double INDtc2; /* second temperature coefficient of resistors */ diff --git a/src/spicelib/devices/ind/indparam.c b/src/spicelib/devices/ind/indparam.c index e39584c6f..23f776dcf 100644 --- a/src/spicelib/devices/ind/indparam.c +++ b/src/spicelib/devices/ind/indparam.c @@ -22,7 +22,7 @@ INDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) switch(param) { case IND_IND: - here->INDinduct = value->rValue; + here->INDinductinst = here->INDinduct = value->rValue; if (!here->INDmGiven) here->INDm =1.0; here->INDindGiven = TRUE; diff --git a/src/spicelib/devices/ind/indtemp.c b/src/spicelib/devices/ind/indtemp.c index c355e03d8..40149955b 100644 --- a/src/spicelib/devices/ind/indtemp.c +++ b/src/spicelib/devices/ind/indtemp.c @@ -52,6 +52,9 @@ INDtemp(GENmodel *inModel, CKTcircuit *ckt) else here->INDinduct = model->INDmInd; } + else + here->INDinduct = here->INDinductinst; /* reset inductance to instance value */ + difference = (here->INDtemp + here->INDdtemp) - model->INDtnom; /* instance parameters tc1 and tc2 will override