A JK flip-flop is a versatile sequential logic circuit used to store and toggle binary data. It eliminates the undefined state of the SR flip-flop and can perform set, reset, and toggle operations.
Inputs: J (Set), K (Reset), Clock (CLK)
Outputs: Q and Q̅ (complement of Q)
module jkff(q,qb,j,k,clk);
input j,k,clk;
output q,qb;
reg q=0;
reg qb=1;
always @(posedge clk)
begin
if (j==0 && k==0)
q=q;
else if (j==0 && k==1)
q=0;
else if (j==1 && k==0)
q=1;
else
q=~q;
qb <= ~q;
end
endmodule
module tb_jkff();
wire q,qb;
reg j,k,clk;
jkff dux(q,qb,j,k,clk);
initial
begin
clk = 0;
repeat(10)
begin
#5 clk =~clk;
end
end
initial
begin
j = 0; k = 0;
#10 j = 1; k = 0;
#10 j = 0; k = 1;
#10 j = 1; k = 1;
#20 $finish;
end
endmodule