public void jk_set() { var jkFlipFlop = new JKMasterSlave(TTLGateTypeEnum.Perfect); jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(0); jkFlipFlop.Clk.Add(5); jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(0); jkFlipFlop.Clk.Add(0); jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(0); jkFlipFlop.Clk.Add(5); jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(0); jkFlipFlop.Clk.Add(0); jkFlipFlop.RunCircuit(); Assert.True(jkFlipFlop.VerifyNoShortedOutputs()); Assert.True(jkFlipFlop.VerifyAllGateInputsConnected()); Assert.True(jkFlipFlop.CircuitCompletedSuccessfully); Assert.Equal(5, jkFlipFlop.Q(1)); Assert.Equal(0, jkFlipFlop.QNot(1)); }
public void jk_toggle_once() { var jkFlipFlop = new JKMasterSlave(TTLGateTypeEnum.Perfect); jkFlipFlop.J.Add(0); jkFlipFlop.K.Add(5); jkFlipFlop.Clk.Add(5); jkFlipFlop.J.Add(0); jkFlipFlop.K.Add(5); jkFlipFlop.Clk.Add(0); // start toggle jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(5); jkFlipFlop.Clk.Add(5); jkFlipFlop.J.Add(5); jkFlipFlop.K.Add(5); jkFlipFlop.Clk.Add(0); // Give this 2 clock cycles to sort out any randomness jkFlipFlop.RunCircuit(); Assert.True(jkFlipFlop.VerifyNoShortedOutputs()); Assert.True(jkFlipFlop.VerifyAllGateInputsConnected()); Assert.True(jkFlipFlop.CircuitCompletedSuccessfully); Assert.Equal(5, jkFlipFlop.Q(3)); Assert.Equal(0, jkFlipFlop.QNot(3)); }
private void JKFlipFlopPaint() { Graphics g = this.CreateGraphics(); g.FillRectangle(Brushes.White, 0, 0, Width, Height); int leftOffset = 120; int topOffset = 100; int spacing = 80; int timingWidth = 4; var fontFamily = new FontFamily("Arial"); var font = new Font(fontFamily, 20, FontStyle.Regular, GraphicsUnit.Pixel); g.DrawString("J", font, Brushes.Black, 5, Height - 20 - (spacing * 6 + topOffset)); g.DrawString("K", font, Brushes.Black, 5, Height - 20 - (spacing * 5 + topOffset)); g.DrawString("CLK", font, Brushes.Red, 5, Height - 20 - (spacing * 4 + topOffset)); g.DrawString("Q", font, Brushes.Blue, 5, Height - 20 - (spacing * 3 + topOffset)); g.DrawString("QBar", font, Brushes.Blue, 5, Height - 20 - (spacing * 2 + topOffset)); //g.DrawString("G3", font, Brushes.BlueViolet, 5, Height - 20 - (spacing*1 + topOffset)); //g.DrawString("G4", font, Brushes.BlueViolet, 5, Height - 20 - (spacing*0 + topOffset)); for (int i = 1; i < jkFlipFlop.Count; i++) { // inputs g.DrawLine(Pens.Black, i * timingWidth + leftOffset, Height - ((float)jkFlipFlop.J.Output(i - 1) * 5 + topOffset + spacing * 6), i * timingWidth + timingWidth + leftOffset, Height - ((float)jkFlipFlop.J.Output(i) * 5 + topOffset + spacing * 6)); g.DrawLine(Pens.Black, i * timingWidth + leftOffset, Height - ((float)jkFlipFlop.K.Output(i - 1) * 5 + topOffset + spacing * 5), i * timingWidth + timingWidth + leftOffset, Height - ((float)jkFlipFlop.K.Output(i) * 5 + topOffset + spacing * 5)); g.DrawLine(Pens.Red, i * timingWidth + leftOffset, Height - ((float)jkFlipFlop.Clk.Output(i - 1) * 5 + topOffset + spacing * 4), i * timingWidth + timingWidth + leftOffset, Height - ((float)jkFlipFlop.Clk.Output(i) * 5 + topOffset + spacing * 4)); // outputs g.DrawLine(Pens.Blue, i * timingWidth + leftOffset, Height - ((float)jkFlipFlop.Q(i - 1) * 5 + topOffset + spacing * 3), i * timingWidth + timingWidth + leftOffset, Height - ((float)jkFlipFlop.Q(i) * 5 + topOffset + spacing * 3)); g.DrawLine(Pens.Blue, i * timingWidth + leftOffset, Height - ((float)jkFlipFlop.QNot(i - 1) * 5 + topOffset + spacing * 2), i * timingWidth + timingWidth + leftOffset, Height - ((float)jkFlipFlop.QNot(i) * 5 + topOffset + spacing * 2)); // test outputs /* * g.DrawLine(Pens.BlueViolet, * i*timingWidth + leftOffset, * Height - ((float) jkFlipFlop.Gate3Output(i - 1)*5 + topOffset + spacing*1), * i*timingWidth + timingWidth + leftOffset, * Height - ((float) jkFlipFlop.Gate3Output(i)*5 + topOffset + spacing*1)); * * g.DrawLine(Pens.BlueViolet, * i*timingWidth + leftOffset, * Height - ((float) jkFlipFlop.Gate4Output(i - 1)*5 + topOffset + spacing*0), * i*timingWidth + timingWidth + leftOffset, * Height - ((float) jkFlipFlop.Gate4Output(i)*5 + topOffset + spacing*0)); * // grid */ g.DrawLine(Pens.Gray, i * timingWidth + leftOffset, Height - 50 - (i % 10 == 0 ? 30 : 0), i * timingWidth + leftOffset, Height); } }