spicelib/devices/{sw,csw}, #4/, clean up negative hysteresis
Rewrite special behaviour for negative hysteresis.
This is a functional invariant cleanup of commit:
> commit 0dae4607a0
> Date: Wed Apr 25 18:28:20 2001 +0000
>
> Added a patch to csw and sw from Jon Engelbert dealing with negative histeresys
This commit is contained in:
parent
b4db438731
commit
56d1d3901d
|
|
@ -56,21 +56,17 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
current_state = previous_state;
|
||||
|
||||
} else if (ckt->CKTmode & (MODEINITFLOAT)) {
|
||||
/* fixme, missleading comment: */
|
||||
/* use state0 since INITTRAN or INITPRED already called */
|
||||
|
||||
if (model->CSWiHysteresis > 0) {
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (model->CSWiHysteresis > 0) {
|
||||
current_state = previous_state;
|
||||
} else {
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else {
|
||||
} else {
|
||||
/* in hysteresis... change value if going from low to hysteresis,
|
||||
* or from hi to hysteresis. */
|
||||
|
||||
|
|
@ -84,7 +80,6 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
else
|
||||
internalerror("bad value for previous region in swload");
|
||||
}
|
||||
}
|
||||
|
||||
if (current_state != old_current_state) {
|
||||
ckt->CKTnoncon++; /* ensure one more iteration */
|
||||
|
|
@ -93,19 +88,14 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
|
||||
} else if (ckt->CKTmode & (MODEINITTRAN | MODEINITPRED)) {
|
||||
|
||||
if (model->CSWiHysteresis > 0) {
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (model->CSWiHysteresis > 0) {
|
||||
current_state = previous_state;
|
||||
} else {
|
||||
if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else {
|
||||
} else {
|
||||
/* in hysteresis... change value if going from low to hysteresis,
|
||||
* or from hi to hysteresis. */
|
||||
|
||||
|
|
@ -119,7 +109,6 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
else
|
||||
internalerror("bad value for previous region in cswload");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ckt->CKTstate0[here->CSWswitchstate] = current_state;
|
||||
|
|
|
|||
|
|
@ -61,20 +61,17 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
|
||||
} else if (ckt->CKTmode & (MODEINITFLOAT)) {
|
||||
|
||||
/* fixme, missleading comment: */
|
||||
/* use state0 since INITTRAN or INITPRED already called */
|
||||
if (model->SWvHysteresis > 0) {
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (model->SWvHysteresis > 0) {
|
||||
current_state = old_current_state;
|
||||
} else { // negative hysteresis case.
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else { // in hysteresis... change value if going from low to hysteresis, or from hi to hysteresis.
|
||||
} else {
|
||||
// in hysteresis... change value if going from low to hysteresis, or from hi to hysteresis.
|
||||
// if previous state was in hysteresis, then don't change the state..
|
||||
if (previous_state == HYST_OFF || previous_state == HYST_ON)
|
||||
current_state = previous_state;
|
||||
|
|
@ -85,7 +82,6 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
else
|
||||
internalerror("bad value for previous state in swload");
|
||||
}
|
||||
}
|
||||
|
||||
if (current_state != old_current_state) {
|
||||
ckt->CKTnoncon++; /* ensure one more iteration */
|
||||
|
|
@ -94,19 +90,14 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
|
||||
} else if (ckt->CKTmode & (MODEINITTRAN | MODEINITPRED)) {
|
||||
|
||||
if (model->SWvHysteresis > 0) {
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else
|
||||
if (model->SWvHysteresis > 0) {
|
||||
current_state = previous_state;
|
||||
} else { // negative hysteresis case.
|
||||
if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_ON;
|
||||
else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis)))
|
||||
current_state = REALLY_OFF;
|
||||
else {
|
||||
} else {
|
||||
if (previous_state == HYST_ON || previous_state == HYST_OFF)
|
||||
current_state = previous_state;
|
||||
else if (previous_state == REALLY_ON)
|
||||
|
|
@ -114,7 +105,6 @@ SWload(GENmodel *inModel, CKTcircuit *ckt)
|
|||
else if (previous_state == REALLY_OFF)
|
||||
current_state = REALLY_ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// code added to force the state to be updated.
|
||||
|
|
|
|||
Loading…
Reference in New Issue