Verilog Code :JK Flip Flop using Case Statement
Verilog Code
module JKFlipFlop(
input J,
input K,
input clk,
output Q,
output Qbar
);
reg Q,Qbar;
input J,
input K,
input clk,
output Q,
output Qbar
);
reg Q,Qbar;
always@(posedge clk)
begin
case({J,K})
2’b0_0:Q<=Q;
2’b0_1:Q<=1’b0;
2’b1_0:Q<=1’b1;
2’b1_1:Q<=Qbar;
endcase
end
endmodule
Test Bench
module JK_FlipFlop_TB;
// Inputs
reg J;
reg K;
// Outputs
wire Q;
wire Qbar;
// Instantiate the Unit Under Test (UUT)
JKFlipFlop uut (
.J(J),
.K(K),
.Q(Q),
.Qbar(Qbar)
);
initial begin
// Initialize Inputs
J = 0;
K = 0;
clk
// Wait 100 ns for global reset to finish
#100
J=0;
K=1;
#100
J=1;
K=0;
#100
J=1;
K=1;
// Add stimulus here
end
endmodule
Soon We will Provide Output Pics also