spicelib/devices/{sw,csw}, #3/, clean up negative hysteresis
Rewrite expression for better emphasis of using fabs(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
5bb08ea5c8
commit
b4db438731
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue