Diode
authoryu.dongliang <18588496441@163.com>
Tue, 24 Oct 2023 07:45:00 +0000 (15:45 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 24 Oct 2023 07:45:00 +0000 (15:45 +0800)
scf_eda_pb.h
ses_step_dc_diode.c
ses_step_va_transistor.c

index eda39ff4044fad0f9877feab1a4e4e92a90b263d..8406850d0ccc480923deb1e4b07935037b429953 100644 (file)
@@ -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 {
index 49aeba0b33e7d005c91b55934dbe87325f852ed5..ada2aaad1784ea156143d82d0844426232d28aba 100644 (file)
@@ -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);
        }
 
index 11d7b6acb7128e864d279aa10e504b40f6182d5f..9124a816aa4d6372f748516dd07ee3d9fe4f7822 100644 (file)
@@ -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;
 }