Ejemplo n.º 1
0
		public override void step(Circuit sim) {
			double vc = lead_volt[3] - lead_volt[2];
			double vo = lead_volt[1];
			int dir = (vo < 2.5) ? 1 : -1;
			// switch direction of current through cap as we oscillate
			if (vo < 2.5 && vc > 4.5) {
				vo = 5;
				dir = -1;
			}
			if (vo > 2.5 && vc < .5) {
				vo = 0;
				dir = 1;
			}

			// generate output voltage
			sim.updateVoltageSource(0, lead_node[1], pins[1].voltSource, vo);
			// now we set the current through the cap to be equal to the
			// current through R1 and R2, so we can measure the voltage
			// across the cap
			int cur1 = sim.nodeCount + pins[4].voltSource;
			int cur2 = sim.nodeCount + pins[5].voltSource;
			sim.stampMatrix(lead_node[2], cur1, dir);
			sim.stampMatrix(lead_node[2], cur2, dir);
			sim.stampMatrix(lead_node[3], cur1, -dir);
			sim.stampMatrix(lead_node[3], cur2, -dir);
			cDir = dir;
		}
Ejemplo n.º 2
0
 public override void step(Circuit sim)
 {
     if (waveform != WaveType.DC)
     {
         sim.updateVoltageSource(lead_node[0], lead_node[1], voltSource, getVoltage(sim));
     }
 }
Ejemplo n.º 3
0
 public override void step(Circuit sim)
 {
     open       = (lead_volt[2] < 2.5);
     resistance = (open) ? r_off : r_on;
     sim.stampResistor(lead_node[3], lead_node[1], resistance);
     sim.updateVoltageSource(0, lead_node[3], voltSource, lead_volt[0] > 2.5 ? 5 : 0);
 }
Ejemplo n.º 4
0
        public override void step(Circuit sim)
        {
            for (int i = 0; i != getLeadCount(); i++)
            {
                Pin p = pins[i];
                if (!p.output)
                {
                    p.value = lead_volt[i] > 2.5;
                }
            }

            execute(sim);

            for (int i = 0; i != getLeadCount(); i++)
            {
                Pin p = pins[i];

                if (p.output)
                {
                    //Debug.Log(i, p.name, p.value, p.voltSource);
                    sim.updateVoltageSource(0, i, p.voltSource, p.value ? 5 : 0);
                }
            }
            //Debug.Log("--");
        }
Ejemplo n.º 5
0
        public override void step(Circuit sim)
        {
            if (voltageL == null)
            {
                sim.panic("Transmission line delay too large!", this);
                return;
            }

            sim.updateVoltageSource(lead_node[4], lead_node[0], voltSource1, -voltageR[ptr]);
            sim.updateVoltageSource(lead_node[5], lead_node[1], voltSource2, -voltageL[ptr]);

            if (Math.Abs(lead_volt[0]) > 1e-5 || Math.Abs(lead_volt[1]) > 1e-5)
            {
                sim.panic("Need to ground transmission line!", this);
                return;
            }
        }
Ejemplo n.º 6
0
        public override void step(Circuit sim)
        {
            double v0      = lead_volt[1];
            double @out    = lead_volt[0] > 2.5 ? 0 : 5;
            double maxStep = slewRate * sim.timeStep * 1e9;

            @out = Math.Max(Math.Min(v0 + maxStep, @out), v0 - maxStep);
            sim.updateVoltageSource(0, lead_node[1], voltSource, @out);
        }
Ejemplo n.º 7
0
        public override void step(Circuit sim)
        {
            bool f = calcFunction();

            if (isInverting())
            {
                f = !f;
            }
            sim.updateVoltageSource(0, lead_node[inputCount], voltSource, f ? 5 : 0);
        }
Ejemplo n.º 8
0
 public override void step(Circuit sim)
 {
     // if output is low, discharge pin 0. we use a small
     // resistor because it's easier, and sometimes people tie
     // the discharge pin to the trigger and threshold pins.
     // We check setOut to properly emulate the case where
     // trigger is low and threshold is high.
     if (!@out && !setOut)
     {
         sim.stampResistor(lead_node[N_DIS], 0, 10);
     }
     // output
     sim.updateVoltageSource(0, lead_node[N_OUT], pins[N_OUT].voltSource, @out ? lead_volt[N_VIN] : 0);
 }
Ejemplo n.º 9
0
        public override void step(Circuit sim)
        {
            int ival = 0;

            for (int i = 0; i != bits; i++)
            {
                if (lead_volt[i] > 2.5)
                {
                    ival |= 1 << i;
                }
            }
            int    ivalmax = (1 << bits) - 1;
            double v       = ival * lead_volt[bits + 1] / ivalmax;

            sim.updateVoltageSource(0, lead_node[bits], pins[bits].voltSource, v);
        }
Ejemplo n.º 10
0
        public override void step(Circuit sim)
        {
            double v0 = lead_volt[1];
            double @out;

            if (state)
            {
                // Output is high
                if (lead_volt[0] > upperTrigger)
                {
                    // Input voltage high enough to set output low
                    state = false;
                    @out  = 0;
                }
                else
                {
                    @out = 5;
                }
            }
            else
            {
                // Output is low
                if (lead_volt[0] < lowerTrigger)
                {
                    // Input voltage low enough to set output high
                    state = true;
                    @out  = 5;
                }
                else
                {
                    @out = 0;
                }
            }

            double maxStep = slewRate * sim.timeStep * 1e9;

            @out = Math.Max(Math.Min(v0 + maxStep, @out), v0 - maxStep);
            sim.updateVoltageSource(0, lead_node[1], voltSource, @out);
        }
Ejemplo n.º 11
0
 public override void step(Circuit sim)
 {
     for (int i = 0; i != getLeadCount(); i++)
     {
         Pin p = pins[i];
         if (p.output && pins[9].value)
         {
             p.value = lead_volt[i] > 2.5;
         }
         if (!p.output)
         {
             p.value = lead_volt[i] > 2.5;
         }
     }
     execute(sim);
     for (int i = 0; i != getLeadCount(); i++)
     {
         Pin p = pins[i];
         if (p.output && !pins[9].value)
         {
             sim.updateVoltageSource(0, lead_node[i], p.voltSource, p.value ? 5 : 0);
         }
     }
 }
Ejemplo n.º 12
0
 public override void doStep(Circuit sim)
 {
     sim.updateVoltageSource(0, lead_node[0], voltSource, v);
 }
Ejemplo n.º 13
0
 public override void step(Circuit sim)
 {
     sim.updateVoltageSource(0, lead_node[0], voltSource, getVoltage(sim.time));
 }