I am modelling a JK FLIP Flop using Verilog. I am getting the output q
as x
in all the cases. I used case
statement for various jk combinations. I hardly found any issue with the code.
Design
module jk_ff ( input j, input k, input clk, output q);
reg q;
always @ (posedge clk)
case ({j,k})
2'b00 : q <= q;
2'b01 : q <= 1'b0;
2'b10 : q <= 1'b1;
2'b11 : q <= ~q;
endcase
endmodule
test bench
module tb_jk;
reg j;
reg k;
reg clk;
always #5 clk = ~clk;
jk_ff jk0 ( .j(j),
.k(k),
.clk(clk),
.q(q));
initial begin
$dumpfile("test.vcd");
$dumpvars;
j <= 0;
k <= 0;
#5 j <= 0;
k <= 1;
#20 j <= 1;
k <= 0;
#20 j <= 1;
k <= 1;
#20 $finish;
end
initial
$monitor ("j=%0d k=%0d q=%0d", j, k, q);
endmodule
logs
vu2swz@PPDP01:~$ iverilog jk_ff.v
vu2swz@PPDP01:~$ ./a.out
VCD info: dumpfile test.vcd opened for output.
j=0 k=0 q=x
j=0 k=1 q=x
j=1 k=0 q=x
j=1 k=1 q=x
The output is showing only x
instead of 0 1 and Q.