我正在尝试使用 mod-8 计数器实现 mod-6 计数器,但无法获得所需的输出波形。
module mod_six_counter(clk,rst,q,qbar);
input clk;
input wire rst;
output wire [2:0]q;
output [2:0]qbar;
assign rst = ~((~q[0])&q[1]&(q[2]));
jkff ff1(1'b1,1'b1,clk,rst,q[0],qbar[0]);
jkff ff2(1'b1,1'b1,q[0],rst,q[1],qbar[1]);
jkff ff3(1'b1,1'b1,q[1],rst,q[2],qbar[2]);
endmodule
module jkff(j,k,clk,rst,q,qbar);
input j,k,clk,rst;
output reg q;
output qbar;
always@(posedge clk or negedge rst)
begin
if (!rst) q <= 1'b0;
else begin
case({j,k})
2'b00 : q<=q;
2'b01 : q<=1'b0;
2'b10 : q<=1'b1;
2'b11 : q<=~q;
endcase
end
end
assign qbar = ~q;
endmodule
测试台代码:
module tbmod_sixcounter;
reg clk,rst;
wire[2:0] q,qbar;
mod_six_counter DUT(.clk(clk),.rst(rst),.q(q),.qbar(qbar));
always #10 clk=~clk;
initial
begin
clk<=0;
rst<=0;
#7 rst<=1;
end
endmodule
这段代码有什么错误?有人可以帮忙解决吗? 波形简单地显示为 xxx。