diff --git a/src/spicelib/devices/sw/swacload.c b/src/spicelib/devices/sw/swacload.c index 5b6e71e82..a1d2e7edd 100644 --- a/src/spicelib/devices/sw/swacload.c +++ b/src/spicelib/devices/sw/swacload.c @@ -33,7 +33,7 @@ SWacLoad(GENmodel *inModel, CKTcircuit *ckt) /* In AC analysis, just propogate the state... */ - current_state = (int)*(ckt->CKTstate0 + here->SWstate); + current_state = (int) ckt->CKTstate0[here->SWswitchstate]; g_now = current_state?(model->SWonConduct):(model->SWoffConduct); diff --git a/src/spicelib/devices/sw/swdefs.h b/src/spicelib/devices/sw/swdefs.h index 4e73cc4e4..a98a8b530 100644 --- a/src/spicelib/devices/sw/swdefs.h +++ b/src/spicelib/devices/sw/swdefs.h @@ -57,6 +57,10 @@ typedef struct sSWinstance { #define SW_OFF_CONDUCTANCE ckt->CKTgmin /* default off conductance */ #define SW_NUM_STATES 2 +#define SWswitchstate SWstate+0 +#define SWctrlvalue SWstate+1 + + typedef struct sSWmodel { /* model structure for a switch */ struct GENmodel gen; diff --git a/src/spicelib/devices/sw/swload.c b/src/spicelib/devices/sw/swload.c index b146219d5..06216a987 100644 --- a/src/spicelib/devices/sw/swload.c +++ b/src/spicelib/devices/sw/swload.c @@ -31,8 +31,8 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) for (; model; model = SWnextModel(model)) { for (here = SWinstances(model); here; here=SWnextInstance(here)) { - old_current_state = ckt->CKTstates[0][here->SWstate + 0]; - previous_state = ckt->CKTstates[1][here->SWstate + 0]; + old_current_state = ckt->CKTstate0[here->SWswitchstate]; + previous_state = ckt->CKTstate1[here->SWswitchstate]; v_ctrl = ckt->CKTrhsOld [here->SWposCntrlNode] - @@ -132,8 +132,8 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) // After analyzing the transient code, it seems that this is not a problem because state updating // occurs before the convergence loop in transient processing. - ckt->CKTstates[0][here->SWstate + 0] = current_state; - ckt->CKTstates[0][here->SWstate + 1] = v_ctrl; + ckt->CKTstate0[here->SWswitchstate] = current_state; + ckt->CKTstate0[here->SWctrlvalue] = v_ctrl; if ((current_state == REALLY_ON) || (current_state == HYST_ON)) g_now = model->SWonConduct; diff --git a/src/spicelib/devices/sw/swnoise.c b/src/spicelib/devices/sw/swnoise.c index 1e429a2e1..1b8332033 100644 --- a/src/spicelib/devices/sw/swnoise.c +++ b/src/spicelib/devices/sw/swnoise.c @@ -65,7 +65,7 @@ SWnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *da switch (mode) { case N_DENS: - current_state = (int)*(ckt->CKTstate0 + inst->SWstate); + current_state = (int) ckt->CKTstate0[inst->SWswitchstate]; NevalSrc(&noizDens,&lnNdens,ckt,THERMNOISE, inst->SWposNode,inst->SWnegNode, current_state?(model->SWonConduct):(model->SWoffConduct)); diff --git a/src/spicelib/devices/sw/swpzload.c b/src/spicelib/devices/sw/swpzload.c index ddcd08dc0..4640473f2 100644 --- a/src/spicelib/devices/sw/swpzload.c +++ b/src/spicelib/devices/sw/swpzload.c @@ -37,7 +37,7 @@ SWpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) /* In AC analysis, just propogate the state... */ - current_state = (int)*(ckt->CKTstate0 + here->SWstate); + current_state = (int) ckt->CKTstate0[here->SWswitchstate]; g_now = current_state?(model->SWonConduct):(model->SWoffConduct); diff --git a/src/spicelib/devices/sw/swtrunc.c b/src/spicelib/devices/sw/swtrunc.c index 453f89d6e..a873a64d4 100644 --- a/src/spicelib/devices/sw/swtrunc.c +++ b/src/spicelib/devices/sw/swtrunc.c @@ -21,14 +21,14 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) for (; model; model = SWnextModel(model)) { for (here = SWinstances(model); here; here = SWnextInstance(here)) { lastChange = - ckt->CKTstates[0][here->SWstate + 1] - - ckt->CKTstates[1][here->SWstate + 1]; - if (ckt->CKTstates[0][here->SWstate + 0] == 0) { + ckt->CKTstate0[here->SWctrlvalue] - + ckt->CKTstate1[here->SWctrlvalue]; + if (ckt->CKTstate0[here->SWswitchstate] == 0) { ref = (model->SWvThreshold + model->SWvHysteresis); - if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 1e-3) + if (ckt->CKTstate0[here->SWctrlvalue] < ref && lastChange > 1e-3) { maxChange = - (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 + 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (maxStep < ckt->CKTdelmin) @@ -38,10 +38,10 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) } } else { ref = model->SWvThreshold - model->SWvHysteresis; - if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < -1e-3) + if (ckt->CKTstate0[here->SWctrlvalue] > ref && lastChange < -1e-3) { maxChange = - (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 - 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (maxStep < ckt->CKTdelmin)