__ses_status_check()
authoryu.dongliang <18588496441@163.com>
Mon, 23 Oct 2023 14:15:57 +0000 (22:15 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 23 Oct 2023 14:15:57 +0000 (22:15 +0800)
scf_eda_pb.h
ses_core.h
ses_step_dc_transistor.c
ses_step_va_balance.c
ses_step_va_bridge.c
ses_step_va_transistor.c

index 5fdb4bae060af6be267b568f666fa1dfd031d66a..379270b3f6374ba2fc1c972a63d13cc88488355d 100644 (file)
@@ -32,6 +32,9 @@ enum {
 #define SCF_EDA_V_Diode_ON  0.69
 #define SCF_EDA_V_Diode_OFF 0.70
 
+#define SCF_EDA_V_NPN_ON    SCF_EDA_V_Diode_OFF
+#define SCF_EDA_V_NPN_OFF   0.65
+
 enum {
        SCF_EDA_Battery_NEG,
        SCF_EDA_Battery_POS,
index 89ae3c5a5821af4ce98392c5a1dfb965f832231b..99850950f066dceb0d66b354908a50da96ba6c7a 100644 (file)
@@ -117,11 +117,11 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count);
 void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja);
 void __ses_path_pr     (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr);
 void __ses_path_sr     (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr);
-int  __ses_path_pos    (ScfEfunction* f, ScfEline* el);
-int  __ses_path_neg    (ScfEfunction* f, ScfEline* el);
 int  __ses_path_va     (ScfEfunction* f, ses_path_t* path);
+int  __ses_path_pos    (ScfEfunction* f, ScfEline*   el);
+int  __ses_path_neg    (ScfEfunction* f, ScfEline*   el);
 
-int  __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn);
+int  __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe);
 
 static inline void vertical(int* px, int* py, int dx, int dy, int d)
 {
index ccf5863be54591ad5b414aff6c3af3dd59fc14c7..6bcba8709f9c6ce1f316194f0af73ec979f8ca4e 100644 (file)
@@ -46,7 +46,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
                                continue;
 
                        pe->v = le->v;
-                       pb->v = le->v + SCF_EDA_V_Diode_ON;
+                       pb->v = le->v + SCF_EDA_V_NPN_ON;
                        lb->v = pb->v;
 
                        if (le->v == Bn->v)
@@ -57,7 +57,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
                } else if (le->v < SCF_EDA_V_MIN) {
 
                        pb->v = lb->v;
-                       pe->v = lb->v - SCF_EDA_V_Diode_ON;
+                       pe->v = lb->v - SCF_EDA_V_NPN_ON;
                        le->v = pe->v;
 
                        if (lb->v == Bp->v)
@@ -65,7 +65,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
 
                        c->status  = SCF_EDA_Status_ON;
 
-               } else if (lb->v >= le->v + SCF_EDA_V_Diode_OFF) {
+               } else if (lb->v >= le->v + SCF_EDA_V_NPN_OFF) {
 
                        if (le->v == Bn->v) {
                                if (lb->v == Bp->v) {
@@ -78,7 +78,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
                        } else if (lb->v == Bp->v)
                                le->vconst = 1;
 
-                       lb->v = le->v + SCF_EDA_V_Diode_ON;
+                       lb->v = le->v + SCF_EDA_V_NPN_ON;
                        pb->v = lb->v;
                        pe->v = le->v;
 
index a85ea451b601633c4a043a05ff05adf2d35e9035..f298c0aabacdbc8621befb8d070aea25701a8d6b 100644 (file)
@@ -70,7 +70,6 @@ static void inline __ses_bridge_i(double* i0, double* i1, double* i2, double* i3
 static size_t __ses_line_update(ScfEfunction* f, ScfEline* el)
 {
        ScfEcomponent* c;
-       ScfEline*      el2;
        ScfEpin*       p;
        ScfEpin*       p2;
 
@@ -87,57 +86,25 @@ static size_t __ses_line_update(ScfEfunction* f, ScfEline* el)
 
                        if (SCF_EDA_Diode_POS == p->id) {
 
-                               p2    = c->pins[SCF_EDA_Diode_NEG];
-                               el2   = f->elines[p2->lid];
-                               p2->v = el2->v;
-
-                               if (p->v - p2->v < SCF_EDA_V_Diode_ON) {
-                                       c->status    = SCF_EDA_Status_OFF;
-                                       n++;
-
-                                       scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p->v - p2->v);
-                               }
+                               p2 = c->pins[SCF_EDA_Diode_NEG];
+                               n += __ses_status_check(f, c, p, p2);
 
                        } else {
-                               p2    = c->pins[SCF_EDA_Diode_POS];
-                               el2   = f->elines[p2->lid];
-                               p2->v = el2->v;
-
-                               if (p2->v - p->v < SCF_EDA_V_Diode_ON) {
-                                       c->status    = SCF_EDA_Status_OFF;
-                                       n++;
-
-                                       scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p2->v - p->v);
-                               }
+                               p2 = c->pins[SCF_EDA_Diode_POS];
+                               n += __ses_status_check(f, c, p2, p);
                        }
 
                } else if (SCF_EDA_NPN == c->type) {
 
                        if (SCF_EDA_NPN_B == p->id) {
 
-                               p2    = c->pins[SCF_EDA_NPN_E];
-                               el2   = f->elines[p2->lid];
-                               p2->v = el2->v;
-
-                               if (p->v - p2->v < SCF_EDA_V_Diode_ON) {
-                                       c->status    = SCF_EDA_Status_OFF;
-                                       n++;
-
-                                       scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p->v - p2->v);
-                               }
+                               p2 = c->pins[SCF_EDA_NPN_E];
+                               n += __ses_status_check(f, c, p, p2);
 
                        } else if (SCF_EDA_NPN_E == p->id) {
 
-                               p2    = c->pins[SCF_EDA_NPN_B];
-                               el2   = f->elines[p2->lid];
-                               p2->v = el2->v;
-
-                               if (p2->v - p->v < SCF_EDA_V_Diode_ON) {
-                                       c->status    = SCF_EDA_Status_OFF;
-                                       n++;
-
-                                       scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p2->v - p->v);
-                               }
+                               p2 = c->pins[SCF_EDA_NPN_B];
+                               n += __ses_status_check(f, c, p2, p);
                        }
                }
        }
@@ -182,7 +149,7 @@ static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, ses_flow_t
        p1->v  = el->v;
        p1->jv = el->jv;
 
-       scf_loge("p0: %lg, p1: %lg, bridge->r: %lg\n", p0->v, p1->v, bridge->r);
+       scf_loge("p0: %lg, p1: %lg, diff: %lg, bridge->r: %lg\n", p0->v, p1->v, p0->v - p1->v, bridge->r);
 
        if (p0->v > p1->v) {
 
index 00254ccbb26b7fbf30e00c92d7c533ce630b887f..2354fa4cb5b508caca4dc619dc42f50c201ac9a6 100644 (file)
@@ -53,7 +53,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed)
                        if (SCF_EDA_NPN_B == p0->id) {
 
                                p1        = c->pins[SCF_EDA_NPN_E];
-                               *changed += __ses_status_check(c, p0, p1, Bn);
+                               *changed += __ses_status_check(f, c, p0, p1);
                        }
 
                } else if (SCF_EDA_Diode  == c->type) {
@@ -61,7 +61,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed)
                        if (SCF_EDA_Diode_POS == p0->id) {
 
                                p1        = c->pins[SCF_EDA_Diode_NEG];
-                               *changed += __ses_status_check(c, p0, p1, Bn);
+                               *changed += __ses_status_check(f, c, p0, p1);
                        }
                }
        }
index 26d45038a24a338598635a4d346e5a71f7cc4d6a..ec93c5726bfb86e7e94256186c9623e31079ea18 100644 (file)
@@ -22,10 +22,21 @@ void __ses_path_dr_transistor(ScfEfunction* f, ses_path_t* path, int i, int j)
                        p->cid, p->id, v, r, p->sr, p->a, p->dr);
 }
 
-int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn)
+int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe)
 {
+       ScfEcomponent* B  = f->components[0];
+       ScfEpin*       Bn = B->pins[SCF_EDA_Battery_NEG];
+
+       double DV = SCF_EDA_V_NPN_OFF;
+
+       if (SCF_EDA_Diode == c->type)
+               DV = SCF_EDA_V_Diode_ON;
+
+       pb->v = f->elines[pb->lid]->v;
+       pe->v = f->elines[pe->lid]->v;
+
        if (pe->v < SCF_EDA_V_MIN) {
-               pe->v = pb->v - SCF_EDA_V_Diode_ON;
+               pe->v = pb->v - DV;
 
                if (pe->v < Bn->v) {
                        pe->v = Bn->v;
@@ -33,19 +44,19 @@ int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn)
                } else
                        c->status = SCF_EDA_Status_ON;
 
-               scf_loge("c%ld, status: %d\n", c->id, c->status);
+               scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status);
                return 1;
 
-       } else if (pb->v - pe->v < SCF_EDA_V_Diode_ON) {
+       } else if (pb->v - pe->v < DV) {
 
                if (c->status != SCF_EDA_Status_OFF) {
                        c->status  = SCF_EDA_Status_OFF;
-                       scf_loge("c%ld, status: %d\n", c->id, c->status);
+                       scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status);
                        return 1;
                }
        } else if (SCF_EDA_Status_ON != c->status) {
                c->status  = SCF_EDA_Status_ON;
-               scf_loge("c%ld, status: %d\n", c->id, c->status);
+               scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status);
                return 1;
        }
 
@@ -73,13 +84,11 @@ static int __ses_status_change(ScfEfunction* f, ScfEline* el)
                c  = f->components[el->pins[j]];
                p  = c->pins      [el->pins[j + 1]];
 
-               p->v = el->v;
-
                if (SCF_EDA_NPN == c->type) {
                        if (SCF_EDA_NPN_B == p->id) {
 
                                pe       = c->pins[SCF_EDA_NPN_E];
-                               changed += __ses_status_check(c, p, pe, Bn);
+                               changed += __ses_status_check(f, c, p, pe);
                        }
 
                } else if (SCF_EDA_Diode  == c->type) {
@@ -87,7 +96,7 @@ static int __ses_status_change(ScfEfunction* f, ScfEline* el)
                        if (SCF_EDA_Diode_POS == p->id) {
 
                                pe       = c->pins[SCF_EDA_Diode_NEG];
-                               changed += __ses_status_check(c, p, pe, Bn);
+                               changed += __ses_status_check(f, c, p, pe);
                        }
                }
        }