private static void TwoBitAdder() { // rough draft of two circuits. // this will need to be wrapped in a circuit that can process one circuit, // then process the next circuit where all inputs are complete, until all // circuits are complete. var signalGenerator1 = new SignalGenerator(); var signalGenerator2 = new SignalGenerator(); var ground = new Ground(200); bool signalHigh = true; bool longSignalHigh = true; for (int i = 0; i < 200; i++) { if (i % 20 == 0) { signalHigh = !signalHigh; } if (i % 40 == 0) { longSignalHigh = !longSignalHigh; } signalGenerator1.AddSample(signalHigh ? 5 : 0); signalGenerator2.AddSample(longSignalHigh ? 5 : 0); } var adder1Circuit = new FullAdder(TTLGateTypeEnum.Perfect); var adder2Circuit = new FullAdder(TTLGateTypeEnum.Perfect); for (int i = 0; i < 200; i++) { adder1Circuit.A.Add(signalGenerator1.Output(i)); adder1Circuit.B.Add(signalGenerator2.Output(i)); adder1Circuit.Cin.Add(ground.Output(i)); adder2Circuit.A.Add(signalGenerator1.Output(i)); adder2Circuit.B.Add(signalGenerator2.Output(i)); } adder1Circuit.RunCircuit(); for (int i = 0; i < 200; i++) { adder2Circuit.Cin.Add(adder1Circuit.Cout(i)); } adder2Circuit.RunCircuit(); for (int i = 0; i < 200; i++) { _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)} S1:{adder1Circuit.S(i)} S2:{adder2Circuit.S(i)} Cout:{adder1Circuit.Cout(i)}"); } }
private static void FullAdderTest() { var signalGenerator1 = new SignalGenerator(); var signalGenerator2 = new SignalGenerator(); var signalGenerator3 = new SignalGenerator(); bool signalHigh = true; bool longSignalHigh = true; bool carrySignalHigh = true; for (int i = 0; i < 300; i++) { if (i % 20 == 0) { signalHigh = !signalHigh; } if (i % 40 == 0) { longSignalHigh = !longSignalHigh; } if (i % 80 == 0) { carrySignalHigh = !carrySignalHigh; } signalGenerator1.AddSample(signalHigh ? 5 : 0); signalGenerator2.AddSample(longSignalHigh ? 5 : 0); signalGenerator3.AddSample(carrySignalHigh ? 5 : 0); } var adder1Circuit = new FullAdder(TTLGateTypeEnum.LS); for (int i = 0; i < 200; i++) { adder1Circuit.A.Add(signalGenerator1.Output(i)); adder1Circuit.B.Add(signalGenerator2.Output(i)); adder1Circuit.Cin.Add(signalGenerator3.Output(i)); } adder1Circuit.RunCircuit(); for (int i = 0; i < 200; i++) { _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)} Cin:{signalGenerator3.Output(i)} S:{adder1Circuit.S(i)} Cout:{adder1Circuit.Cout(i)}"); } }
private void SimulateSRLatch() { bool carryInSignalHigh = true; for (int i = 0; i < 200; i++) { if (i % 30 == 0 && i > 0) { carryInSignalHigh = !carryInSignalHigh; } if (i < 100) { signalGenerator1.AddSample(carryInSignalHigh ? 5 : 0); signalGenerator2.AddSample(5); } else { signalGenerator1.AddSample(5); signalGenerator2.AddSample(carryInSignalHigh ? 5 : 0); } } for (int i = 0; i < 200; i++) { if (i == 0) { srLatch.S.Add(5); srLatch.R.Add(0); } else { srLatch.S.Add(signalGenerator1.Output(i)); srLatch.R.Add(signalGenerator2.Output(i)); } } srLatch.RunCircuit(); }
private void SimulateFullAdder() { bool carryInSignalHigh = false; bool signalBHigh = false; bool signalAHigh = false; for (int i = 0; i < 300; i++) { if (i % 30 == 0 && i > 0) { carryInSignalHigh = !carryInSignalHigh; } if (i % 60 == 0 && i > 0) { signalBHigh = !signalBHigh; } if (i % 120 == 0 && i > 0) { signalAHigh = !signalAHigh; } signalGenerator1.AddSample(carryInSignalHigh ? 5 : 0); signalGenerator2.AddSample(signalBHigh ? 5 : 0); signalGenerator3.AddSample(signalAHigh ? 5 : 0); } for (int i = 0; i < 300; i++) { adder1Circuit.A.Add(signalGenerator3.Output(i)); adder1Circuit.B.Add(signalGenerator2.Output(i)); adder1Circuit.Cin.Add(signalGenerator1.Output(i)); } adder1Circuit.RunCircuit(); }
static void HalfAdderTest() { var signalGenerator1 = new SignalGenerator(); var signalGenerator2 = new SignalGenerator(); bool signalHigh = true; bool longSignalHigh = true; for (int i = 0; i < 200; i++) { if (i % 20 == 0) { signalHigh = !signalHigh; } if (i % 40 == 0) { longSignalHigh = !longSignalHigh; } signalGenerator1.AddSample(signalHigh ? 5 : 0); signalGenerator2.AddSample(longSignalHigh ? 5 : 0); } var xorGate = new XorGate(TTLGateTypeEnum.Normal, 2); var andGate = new AndGate(TTLGateTypeEnum.Normal, 2); var circuit = new Circuit(); circuit.Gates.Add(xorGate); circuit.Gates.Add(andGate); circuit.Gates.Add(signalGenerator1); circuit.Gates.Add(signalGenerator2); circuit.Connections.Add(new Connection { Source = signalGenerator1, Termination = xorGate.Inputs[0] }); circuit.Connections.Add(new Connection { Source = signalGenerator2, Termination = xorGate.Inputs[1] }); circuit.Connections.Add(new Connection { Source = signalGenerator1, Termination = andGate.Inputs[0] }); circuit.Connections.Add(new Connection { Source = signalGenerator2, Termination = andGate.Inputs[1] }); circuit.RunCircuit(); for (int i = 0; i < 200; i++) { _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)} S:{xorGate.Output(i)} C:{andGate.Output(i)}"); } }