ses_step_dc_diode.c ses_step_dc_transistor.c
authoryu.dongliang <18588496441@163.com>
Tue, 24 Oct 2023 07:07:49 +0000 (15:07 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 24 Oct 2023 07:07:49 +0000 (15:07 +0800)
scf_eda_pb.h
ses_step_dc_diode.c
ses_step_dc_transistor.c
ses_steps.c

index 951d1a798b9d3df6f719831c95584cd4570d9b61..eda39ff4044fad0f9877feab1a4e4e92a90b263d 100644 (file)
@@ -33,7 +33,7 @@ enum {
 #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
+#define SCF_EDA_V_NPN_OFF   0.60
 
 enum {
        SCF_EDA_Battery_NEG,
index 8afef4e04e94b8d6dc6baee62f193fdd5605849f..49aeba0b33e7d005c91b55934dbe87325f852ed5 100644 (file)
@@ -4,55 +4,89 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx
 {
        ScfEcomponent*   c;
        ScfEcomponent*   B;
-       ScfEline*        el;
-       ScfEline*        el1;
-       ScfEpin*         p0;
-       ScfEpin*         p1;
+       ScfEline*        lb;
+       ScfEline*        le;
+       ScfEpin*         pb;
+       ScfEpin*         pe;
+       ScfEpin*         Bp;
+       ScfEpin*         Bn;
 
        size_t i;
        size_t j;
        size_t k;
 
-       B = f->components[0];
+       B  = f->components[0];
+       Bp = B->pins[SCF_EDA_Battery_POS];
+       Bn = B->pins[SCF_EDA_Battery_NEG];
 
-       for (i = 0; i < f->n_elines; i++) {
-               el =        f->elines[i];
+       for (i = 0; i < f->n_components; i++) {
+               c  =        f->components[i];
 
-               if (!el->vconst)
+               if (SCF_EDA_Diode != c->type)
                        continue;
 
-               for (j = 0; j + 1 < el->n_pins; j += 2) {
+               pb = c->pins[SCF_EDA_Diode_POS];
+               pe = c->pins[SCF_EDA_Diode_NEG];
 
-                       c  = f->components[el->pins[j]];
+               lb = f->elines[pb->lid];
+               le = f->elines[pe->lid];
 
-                       if (SCF_EDA_Diode != c->type)
+               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);
+                       continue;
+               }
+
+               if (lb->v < SCF_EDA_V_MIN) {
+
+                       if (le->v < SCF_EDA_V_MIN)
                                continue;
 
-                       p0    = c->pins[ el->pins[j + 1]];
-                       p1    = c->pins[!p0->id];
-                       p0->v = el->v;
+                       pe->v = le->v;
+                       pb->v = le->v + SCF_EDA_V_Diode_ON;
+                       lb->v = pb->v;
 
-                       if (SCF_EDA_Diode_NEG == p0->id)
-                               p1->v = p0->v + SCF_EDA_V_Diode_ON;
-                       else
-                               p1->v = p0->v - SCF_EDA_V_Diode_ON;
+                       if (le->v == Bn->v)
+                               lb->vconst = 1;
 
-                       if (p1->v > B->v || p1->v < 0)
-                               c->status = SCF_EDA_Status_OFF;
+                       c->status = SCF_EDA_Status_ON;
 
-                       else {
-                               el1 = f->elines[p1->lid];
+               } else if (le->v < SCF_EDA_V_MIN) {
 
-                               if (el1->v < SCF_EDA_V_MIN || el1->v >= p1->v) {
-                                       el1->v      = p1->v;
-                                       el1->vconst = 1;
-                                       c->status   = SCF_EDA_Status_ON;
-                               } else
-                                       c->status = SCF_EDA_Status_OFF;
-                       }
+                       pb->v = lb->v;
+                       pe->v = lb->v - SCF_EDA_V_Diode_ON;
+                       le->v = pe->v;
 
-                       scf_loge("Diode c%ld, status: %d\n", c->id, c->status);
+                       if (lb->v == Bp->v)
+                               le->vconst = 1;
+
+                       c->status  = SCF_EDA_Status_ON;
+
+               } else if (lb->v >= le->v + SCF_EDA_V_Diode_OFF) {
+
+                       if (le->v == Bn->v) {
+                               if (lb->v == Bp->v) {
+                                       scf_loge("Diode c%ld, short connected\n", c->id);
+                                       return -EINVAL;
+                               }
+
+                               lb->vconst = 1;
+
+                       } else if (lb->v == Bp->v)
+                               le->vconst = 1;
+
+                       lb->v = le->v + SCF_EDA_V_Diode_ON;
+                       pb->v = lb->v;
+                       pe->v = le->v;
+
+                       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_loge("\033[34mDiode c%ld, status: %d\033[0m\n", c->id, c->status);
        }
 
        return 0;
index f9a2b3ccf98be9746fd7dd0fb3767addedacf6a2..156f582f9a13679ec45edf3907e4970a7013e15e 100644 (file)
@@ -83,11 +83,9 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
                        pe->v = le->v;
 
                        c->status = SCF_EDA_Status_ON;
-               } else {
+               } else
                        c->status = SCF_EDA_Status_OFF;
 
-                       scf_logi("NPN c%ld, status: %d, lb->v: %lg, le->v: %lg\n", c->id, c->status, lb->v, le->v);
-               }
                scf_loge("\033[34mNPN c%ld, status: %d\033[0m\n", c->id, c->status);
        }
 
index 31bd7114ba8abb0cd804b5d2ec40f18d66c2c5a1..023125be61ddec8cab3d38400cfcc482648cc037 100644 (file)
@@ -29,11 +29,11 @@ static ses_step_t*  ses_steps_0[] =
        &ses_step_battery,
 
        &ses_step_dc_input,
-       &ses_step_dc_diode,
 };
 
 static ses_step_t*  ses_steps_1[] =
 {
+       &ses_step_dc_diode,
        &ses_step_dc_transistor,
 
        &ses_step_simplify,