spicelib/devices/{sw,csw}, #7/, cleanup, HYST_ON/OFF
clean up the state transition from REALLY_ON/OFF to HYST_ON/OFF
This commit is contained in:
parent
50ad54e534
commit
91d4f74b2e
|
|
@ -12,6 +12,20 @@ Modified: 2001 Jon Engelbert
|
||||||
#include "ngspice/sperror.h"
|
#include "ngspice/sperror.h"
|
||||||
#include "ngspice/suffix.h"
|
#include "ngspice/suffix.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
verify(int state, char *msg)
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
case REALLY_ON:
|
||||||
|
case REALLY_OFF:
|
||||||
|
case HYST_ON:
|
||||||
|
case HYST_OFF:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
internalerror(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
|
|
@ -66,15 +80,15 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
/* in hysteresis... change value if going from low to hysteresis,
|
/* in hysteresis... change value if going from low to hysteresis,
|
||||||
* or from hi to hysteresis. */
|
* or from hi to hysteresis. */
|
||||||
|
|
||||||
|
verify(previous_state, "bad value for previous_state in swload");
|
||||||
|
|
||||||
/* if previous state was in hysteresis, then don't change the state.. */
|
/* if previous state was in hysteresis, then don't change the state.. */
|
||||||
if (previous_state == HYST_OFF || previous_state == HYST_ON)
|
if (previous_state == REALLY_ON)
|
||||||
current_state = previous_state;
|
current_state = HYST_ON;
|
||||||
else if (previous_state == REALLY_OFF)
|
else if (previous_state == REALLY_OFF)
|
||||||
current_state = HYST_OFF;
|
current_state = HYST_OFF;
|
||||||
else if (previous_state == REALLY_ON)
|
|
||||||
current_state = HYST_ON;
|
|
||||||
else
|
else
|
||||||
internalerror("bad value for previous region in swload");
|
current_state = previous_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) {
|
if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) {
|
||||||
|
|
@ -95,15 +109,15 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
/* in hysteresis... change value if going from low to hysteresis,
|
/* in hysteresis... change value if going from low to hysteresis,
|
||||||
* or from hi to hysteresis. */
|
* or from hi to hysteresis. */
|
||||||
|
|
||||||
|
verify(previous_state, "bad value for previous_state in cswload");
|
||||||
|
|
||||||
/* if previous state was in hysteresis, then don't change the state.. */
|
/* if previous state was in hysteresis, then don't change the state.. */
|
||||||
if (previous_state == HYST_OFF || previous_state == HYST_ON)
|
if (previous_state == REALLY_ON)
|
||||||
current_state = previous_state;
|
|
||||||
else if (previous_state == REALLY_ON)
|
|
||||||
current_state = HYST_ON;
|
current_state = HYST_ON;
|
||||||
else if (previous_state == REALLY_OFF)
|
else if (previous_state == REALLY_OFF)
|
||||||
current_state = HYST_OFF;
|
current_state = HYST_OFF;
|
||||||
else
|
else
|
||||||
internalerror("bad value for previous region in cswload");
|
current_state = previous_state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,20 @@ Modified: 2001 Jon Engelbert
|
||||||
#include "ngspice/sperror.h"
|
#include "ngspice/sperror.h"
|
||||||
#include "ngspice/suffix.h"
|
#include "ngspice/suffix.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
verify(int state, char *msg)
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
case REALLY_ON:
|
||||||
|
case REALLY_OFF:
|
||||||
|
case HYST_ON:
|
||||||
|
case HYST_OFF:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
internalerror(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
SWload(GENmodel *inModel, CKTcircuit *ckt)
|
SWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
|
|
@ -70,15 +84,16 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
current_state = old_current_state;
|
current_state = old_current_state;
|
||||||
} else {
|
} else {
|
||||||
// in hysteresis... change value if going from low to hysteresis, or from hi to hysteresis.
|
// in hysteresis... change value if going from low to hysteresis, or from hi to hysteresis.
|
||||||
|
|
||||||
|
verify(previous_state, "bad value for previous_state in swload");
|
||||||
|
|
||||||
// if previous state was in hysteresis, then don't change the state..
|
// if previous state was in hysteresis, then don't change the state..
|
||||||
if (previous_state == HYST_OFF || previous_state == HYST_ON)
|
if (previous_state == REALLY_ON)
|
||||||
current_state = previous_state;
|
|
||||||
else if (previous_state == REALLY_ON)
|
|
||||||
current_state = HYST_ON;
|
current_state = HYST_ON;
|
||||||
else if (previous_state == REALLY_OFF)
|
else if (previous_state == REALLY_OFF)
|
||||||
current_state = HYST_OFF;
|
current_state = HYST_OFF;
|
||||||
else
|
else
|
||||||
internalerror("bad value for previous state in swload");
|
current_state = previous_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) {
|
if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) {
|
||||||
|
|
@ -96,12 +111,15 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
||||||
if (model->SWvHysteresis > 0) {
|
if (model->SWvHysteresis > 0) {
|
||||||
current_state = previous_state;
|
current_state = previous_state;
|
||||||
} else {
|
} else {
|
||||||
if (previous_state == HYST_ON || previous_state == HYST_OFF)
|
|
||||||
current_state = previous_state;
|
verify(previous_state, "bad value for previous_state in swload");
|
||||||
else if (previous_state == REALLY_ON)
|
|
||||||
|
if (previous_state == REALLY_ON)
|
||||||
current_state = HYST_ON;
|
current_state = HYST_ON;
|
||||||
else if (previous_state == REALLY_OFF)
|
else if (previous_state == REALLY_OFF)
|
||||||
current_state = HYST_OFF;
|
current_state = HYST_OFF;
|
||||||
|
else
|
||||||
|
current_state = previous_state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue