Ejemplo n.º 1
0
main(){
  data_init();
  line1(1,1,17,13);
  data_print();

  data_init();
  line3(1,1,17,11);
  line3(1,4,7,18);
  data_print();

  data_init();
  line4(7,5,5,1);
  line4(5,5,1,3);
  line4(18,1,2,11);
  line4(18,4,6,18);
  data_print();

  data_init();
  line5(5,5,18,9, 3);
  line5(10,18,3,9, 4);
  data_print();

  data_init();
  circ2(12,12,3);
  circ2(10,10,9);
  data_print();

  data_init();
  circ3(11,10,3, 1,1);
  circ3(10,10,9, 3,0);
  data_print();

  data_init();
  circ3(10,10,8, 8,0);
  data_print();

  return 0;
}
Ejemplo n.º 2
0
void test_circuit_rc_tran()
{
	ngdc dc("dc1", 5);
	ngspdt spdt("spdt");
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc.pos, spdt.throw1);
	ngline line2(spdt.pole, r.p1);
	ngline line3(r.p2, c.p1);
	ngline line4(c.p2, dc.neg);
	ngline line5(spdt.throw2, gnd.ground);
	ngline line0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spdt, &r, &c, &gnd, 0);
	sch.AddLines(&line1, &line2, &line3, &line4, &line5, &line0, 0);


	circuit cir(&sch);
	cir.Tran("1t", "100u");

	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'a':
			// switchover to charge or discharge
			cir.SwitchOver(&spdt);
			Sleep(200);
			break;
		case 'q':
			cir.Halt();
		default:
			break;
		};
	} while (cir.IsRunning());

	cir.Do("plot all");
}
Ejemplo n.º 3
0
/* same effect to test_rc_charge_discharge()
title rc charge discharge
.global gnd
vdc1 1 0 dc 5.000e+000
xspdt 1 2 0 spdt
rr1 2 3 5.000e+000
cc1 3 0 2.000e-001

.subckt spdt 1 2 3 params: vstatus=0 ron=1e-8 roff=1e30
r1 0 6 20
v1 6 0 dc {vstatus}
w0 2 1 v1 nc_contact
w1 2 3 v1 no_contact
.model no_contact csw (it=0.05 ih=0.025 ron={ron} roff={roff})
.model nc_contact csw (it=0.05 ih=0.025 ron={roff} roff={ron})
.ends

.control
stop when time = 5s
tran 100u 10s uic
alter v.xspdt.v1=-2
resume
plot all
.endc
*/
void test_rc_charge_discharge()
{
	ngdc dc("dc1", 5);
	ngspdt spdt("spdt");
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc.pos, spdt.throw1);
	ngline line2(spdt.pole, r.p1);
	ngline line3(r.p2, c.p1);
	ngline line4(c.p2, dc.neg);
	ngline line5(spdt.throw2, gnd.ground);
	ngline line0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spdt, &r, &c, &gnd, 0);
	sch.AddLines(&line1, &line2, &line3, &line4, &line5, &line0, 0);

	circuit cir(&sch);
	// transient analysis last 10 seconds
	cir.Tran("10", "1m");
	do 
	{
		Sleep(100);
		//charge 5 seconds. when time passes 5 seconds, start to discharge.
		static bool done = false;
		if (cir.CurrentValue("time") >= 5 && !done)
		{
			cir.SwitchOver(&spdt);
			Sleep(200);
			done = true;
		}
	} while (cir.IsRunning());
	cir.Do("plot all");
	getchar();
}