diff --git a/src/spicelib/devices/csw/cswload.c b/src/spicelib/devices/csw/cswload.c index f77c3a43f..dddbc9169 100644 --- a/src/spicelib/devices/csw/cswload.c +++ b/src/spicelib/devices/csw/cswload.c @@ -40,16 +40,12 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) if (here->CSWzero_stateGiven) { /* switch specified "on" */ - if (model->CSWiHysteresis >= 0 && i_ctrl > model->CSWiThreshold + model->CSWiHysteresis) - current_state = REALLY_ON; - else if (model->CSWiHysteresis < 0 && i_ctrl > model->CSWiThreshold - model->CSWiHysteresis) + if (i_ctrl > model->CSWiThreshold + fabs(model->CSWiHysteresis)) current_state = REALLY_ON; else current_state = HYST_ON; } else { - if (model->CSWiHysteresis >= 0 && i_ctrl < model->CSWiThreshold - model->CSWiHysteresis) - current_state = REALLY_OFF; - else if (model->CSWiHysteresis < 0 && i_ctrl < model->CSWiThreshold + model->CSWiHysteresis) + if (i_ctrl < model->CSWiThreshold - fabs(model->CSWiHysteresis)) current_state = REALLY_OFF; else current_state = HYST_OFF; @@ -63,16 +59,16 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) /* use state0 since INITTRAN or INITPRED already called */ if (model->CSWiHysteresis > 0) { - if (i_ctrl > (model->CSWiThreshold + model->CSWiHysteresis)) + if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis))) current_state = REALLY_ON; - else if (i_ctrl < (model->CSWiThreshold - model->CSWiHysteresis)) + else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis))) current_state = REALLY_OFF; else current_state = previous_state; } else { - if (i_ctrl > (model->CSWiThreshold - model->CSWiHysteresis)) + if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis))) current_state = REALLY_ON; - else if (i_ctrl < (model->CSWiThreshold + model->CSWiHysteresis)) + else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis))) current_state = REALLY_OFF; else { /* in hysteresis... change value if going from low to hysteresis, @@ -98,16 +94,16 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) } else if (ckt->CKTmode & (MODEINITTRAN | MODEINITPRED)) { if (model->CSWiHysteresis > 0) { - if (i_ctrl > (model->CSWiThreshold + model->CSWiHysteresis)) + if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis))) current_state = REALLY_ON; - else if (i_ctrl < (model->CSWiThreshold - model->CSWiHysteresis)) + else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis))) current_state = REALLY_OFF; else current_state = previous_state; } else { - if (i_ctrl > (model->CSWiThreshold - model->CSWiHysteresis)) + if (i_ctrl > (model->CSWiThreshold + fabs(model->CSWiHysteresis))) current_state = REALLY_ON; - else if (i_ctrl < (model->CSWiThreshold + model->CSWiHysteresis)) + else if (i_ctrl < (model->CSWiThreshold - fabs(model->CSWiHysteresis))) current_state = REALLY_OFF; else { /* in hysteresis... change value if going from low to hysteresis, diff --git a/src/spicelib/devices/sw/swload.c b/src/spicelib/devices/sw/swload.c index 2f5dc6cb0..44e73a517 100644 --- a/src/spicelib/devices/sw/swload.c +++ b/src/spicelib/devices/sw/swload.c @@ -44,16 +44,12 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) if (here->SWzero_stateGiven) { /* switch specified "on" */ - if (model->SWvHysteresis >= 0 && v_ctrl > model->SWvThreshold + model->SWvHysteresis) - current_state = REALLY_ON; - else if (model->SWvHysteresis < 0 && v_ctrl > model->SWvThreshold - model->SWvHysteresis) + if (v_ctrl > model->SWvThreshold + fabs(model->SWvHysteresis)) current_state = REALLY_ON; else current_state = HYST_ON; } else { - if (model->SWvHysteresis >= 0 && v_ctrl < model->SWvThreshold - model->SWvHysteresis) - current_state = REALLY_OFF; - else if (model->SWvHysteresis < 0 && v_ctrl < model->SWvThreshold + model->SWvHysteresis) + if (v_ctrl < model->SWvThreshold - fabs(model->SWvHysteresis)) current_state = REALLY_OFF; else current_state = HYST_OFF; @@ -67,16 +63,16 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) /* use state0 since INITTRAN or INITPRED already called */ if (model->SWvHysteresis > 0) { - if (v_ctrl > (model->SWvThreshold + model->SWvHysteresis)) + if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis))) current_state = REALLY_ON; - else if (v_ctrl < (model->SWvThreshold - model->SWvHysteresis)) + else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis))) current_state = REALLY_OFF; else current_state = old_current_state; } else { // negative hysteresis case. - if (v_ctrl > (model->SWvThreshold - model->SWvHysteresis)) + if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis))) current_state = REALLY_ON; - else if (v_ctrl < (model->SWvThreshold + model->SWvHysteresis)) + 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. // if previous state was in hysteresis, then don't change the state.. @@ -99,16 +95,16 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) } else if (ckt->CKTmode & (MODEINITTRAN | MODEINITPRED)) { if (model->SWvHysteresis > 0) { - if (v_ctrl > (model->SWvThreshold + model->SWvHysteresis)) + if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis))) current_state = REALLY_ON; - else if (v_ctrl < (model->SWvThreshold - model->SWvHysteresis)) + else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis))) current_state = REALLY_OFF; else current_state = previous_state; } else { // negative hysteresis case. - if (v_ctrl > (model->SWvThreshold - model->SWvHysteresis)) + if (v_ctrl > (model->SWvThreshold + fabs(model->SWvHysteresis))) current_state = REALLY_ON; - else if (v_ctrl < (model->SWvThreshold + model->SWvHysteresis)) + else if (v_ctrl < (model->SWvThreshold - fabs(model->SWvHysteresis))) current_state = REALLY_OFF; else { if (previous_state == HYST_ON || previous_state == HYST_OFF) diff --git a/src/spicelib/devices/sw/swmparam.c b/src/spicelib/devices/sw/swmparam.c index 501c54618..a1d50f73b 100644 --- a/src/spicelib/devices/sw/swmparam.c +++ b/src/spicelib/devices/sw/swmparam.c @@ -37,8 +37,7 @@ SWmParam(int param, IFvalue *value, GENmodel *inModel) break; case SW_MOD_VHYS: /* take absolute value of hysteresis voltage */ - // model->SWvHysteresis = (value->rValue < 0) ? -(value->rValue) : - // value->rValue; + /* model->SWvHysteresis = fabs(value->rValue) */ model->SWvHysteresis = value->rValue; model->SWhystGiven = TRUE; break;