这是代码:
module counter(q,clock,clear);
output [3:0] q;
input clock,clear;
T_FF tff0(q[0],clock,clear);
T_FF tff1(q[1],q[0],clear);
T_FF tff2(q[2],q[1],clear);
T_FF tff3(q[3],q[2],clear);
endmodule
module T_FF(q,clock,reset);
output q;
input clock,reset;
D_FF d_ff(.q(q),.clk(clock),.clear(reset),.d(~q));
endmodule
module D_FF(q,qbar,clear,clk,d);
output q,qbar;
input clear,clk,d;
wire sbar,s,r,rbar,cbar;
assign cbar=~clear;
assign sbar=~(rbar&s);
assign s=~(sbar&cbar&~clk);
assign r=~(s&~clk&rbar);
assign q=~(s&qbar);
assign qbar=~(q&cbar&r);
endmodule
module counters
timulus;
reg clock,clear;
wire [3:0] q;
counter c1(q,clock,clear);
initial
begin
$monitor($time," q=%b,clock=%b,clear=%b",q,clock,clear);
end
initial
begin
clear=1'b1;
forever #30 clear=~clear;
end
initial
begin
clock=1'b0;
forever #10 clock=~clock;
end
endmodule
这是
仿真结果:
# 0 q=0000,clock=0,clear=1
run
run
# 10 q=0000,clock=1,clear=1
run
run
# 20 q=0000,clock=0,clear=1
run
run
# 30 q=xxx0,clock=1,clear=0
run
run
# 40 q=xxxx,clock=0,clear=0
run
run
# 50 q=xxxx,clock=1,clear=0
run
run
# 60 q=0000,clock=0,clear=1
run
run
# 70 q=0000,clock=1,clear=1
run
run
# 80 q=0000,clock=0,clear=1
run
run
# 90 q=xxx0,clock=1,clear=0
run
run
# 100 q=xxxx,clock=0,clear=0
run
run
# 110 q=xxxx,clock=1,clear=0
run
q为什么会出现xxxx?
谢谢,clear翻转确实太快了,但是我不太明白,虽然翻转快了,但是还是有时间间隔的吧,难道仿真器识别不了?
一周热门 更多>