From: yu.dongliang <18588496441@163.com> Date: Tue, 24 Oct 2023 07:45:00 +0000 (+0800) Subject: Diode X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=68a5b0fdb118f14d8bbbc22362f505b23159d25e;p=ses.git Diode --- diff --git a/scf_eda_pb.h b/scf_eda_pb.h index eda39ff..8406850 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -29,10 +29,10 @@ enum { #define SCF_EDA_V_MIN -10000000.0 #define SCF_EDA_V_MAX 10000000.0 -#define SCF_EDA_V_Diode_ON 0.68 -#define SCF_EDA_V_Diode_OFF 0.70 +#define SCF_EDA_V_Diode_ON 0.59 +#define SCF_EDA_V_Diode_OFF 0.58 -#define SCF_EDA_V_NPN_ON SCF_EDA_V_Diode_OFF +#define SCF_EDA_V_NPN_ON 0.70 #define SCF_EDA_V_NPN_OFF 0.60 enum { diff --git a/ses_step_dc_diode.c b/ses_step_dc_diode.c index 49aeba0..ada2aaa 100644 --- a/ses_step_dc_diode.c +++ b/ses_step_dc_diode.c @@ -34,7 +34,7 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx if (__ses_path_neg(f, lb) && !__ses_path_pos(f, lb)) { c->status = SCF_EDA_Status_OFF; - scf_loge("Diode c%ld, status: %d\n", c->id, c->status); + scf_loge("\033[34mDiode c%ld, status: %d\033[0m\n", c->id, c->status); continue; } @@ -50,7 +50,10 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx if (le->v == Bn->v) lb->vconst = 1; - c->status = SCF_EDA_Status_ON; + if (pb->v > Bp->v) + c->status = SCF_EDA_Status_OFF; + else + c->status = SCF_EDA_Status_ON; } else if (le->v < SCF_EDA_V_MIN) { @@ -61,7 +64,10 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx if (lb->v == Bp->v) le->vconst = 1; - c->status = SCF_EDA_Status_ON; + if (pe->v < Bn->v) + c->status = SCF_EDA_Status_OFF; + else + c->status = SCF_EDA_Status_ON; } else if (lb->v >= le->v + SCF_EDA_V_Diode_OFF) { @@ -80,12 +86,15 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx pb->v = lb->v; pe->v = le->v; - c->status = SCF_EDA_Status_ON; + if (pb->v > Bp->v) + c->status = SCF_EDA_Status_OFF; + else + c->status = SCF_EDA_Status_ON; } else { c->status = SCF_EDA_Status_OFF; - - scf_logi("Diode c%ld, status: %d, lb->v: %lg, le->v: %lg\n", c->id, c->status, lb->v, le->v); + scf_logd("Diode c%ld, status: %d, pb: %lg, pe: %lg, diff: %lg\n", c->id, c->status, pb->v, pe->v, pb->v - pe->v); } + scf_loge("\033[34mDiode c%ld, status: %d\033[0m\n", c->id, c->status); } diff --git a/ses_step_va_transistor.c b/ses_step_va_transistor.c index 11d7b6a..9124a81 100644 --- a/ses_step_va_transistor.c +++ b/ses_step_va_transistor.c @@ -33,10 +33,8 @@ int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG]; size_t i; - double DV = SCF_EDA_V_NPN_OFF; - - if (SCF_EDA_Diode == c->type) - DV = SCF_EDA_V_Diode_ON; + double Voff = SCF_EDA_Diode == c->type ? SCF_EDA_V_Diode_OFF : SCF_EDA_V_NPN_OFF; + double Von = SCF_EDA_Diode == c->type ? SCF_EDA_V_Diode_ON : SCF_EDA_V_NPN_ON; pb->v = f->elines[pb->lid]->v; pe->v = f->elines[pe->lid]->v; @@ -46,7 +44,7 @@ int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* if (pe->v < SCF_EDA_V_MIN) return 0; - pb->v = pe->v + DV; + pb->v = pe->v + Von; if (pb->v > Bp->v) { pb->v = Bp->v; @@ -56,7 +54,7 @@ int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* goto _changed; } else if (pe->v < SCF_EDA_V_MIN) { - pe->v = pb->v - DV; + pe->v = pb->v - Von; if (pe->v < Bn->v) { pe->v = Bn->v; @@ -65,7 +63,7 @@ int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* c->status = SCF_EDA_Status_ON; goto _changed; - } else if (pb->v - pe->v < DV) { + } else if (pb->v - pe->v < Voff) { if (c->status != SCF_EDA_Status_OFF) { c->status = SCF_EDA_Status_OFF; @@ -98,7 +96,8 @@ _changed: } } - scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status); + scf_loge("\033[34mc%ld, status: %d, pb->v: %lg, pe->v: %lg, diff: %lg, Von: %lg, Voff: %lg\033[0m\n", + c->id, c->status, pb->v, pe->v, pb->v - pe->v, Von, Voff); return 1; }