#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,
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)
{
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)
} 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)
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) {
} 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;
static size_t __ses_line_update(ScfEfunction* f, ScfEline* el)
{
ScfEcomponent* c;
- ScfEline* el2;
ScfEpin* p;
ScfEpin* p2;
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);
}
}
}
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) {
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) {
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);
}
}
}
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;
} 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;
}
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) {
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);
}
}
}