我遇到了Verilog阻塞分配的问题,在模拟中似乎没有阻塞。 Espessialy在第二个永远@块。我需要rst只用于1的单位(时钟周期?),但它同时变为“1”和“0”。当我用rst = #10 1'b0;
替换module testled(
input clk,
output reg out
);
reg [23:0] counter;
reg rst;
initial begin
out = 1'b0;
rst = 1'b0;
counter = 24'b000000000000000000000000;
end
always @(posedge clk, posedge rst) begin
if(rst) begin
counter = 24'b000000000000000000000000;
end
else begin
counter = counter + 1;
end
end
always @(posedge clk) begin
case (out)
1'b1 : begin
if (counter[5]) begin
rst = 1'b1;
out = 1'b0;
rst =1'b0;
end
else begin
out = out;
end
end
1'b0 : begin
if (counter[3]) begin
rst = 1'b1;
out = 1'b1;
rst = 1'b0;
end
else begin
out = out;
end
end
endcase
end
时,在模拟中我可以看到rst在10个单位时间内变为“1”。有人能帮助我吗?
{{1}}
endmodule
答案 0 :(得分:0)
出于模拟目的,你可以这样做:
initial begin
out = 1'b1;
#10ns out = 1'b0;
#20ns out = 1'b1;
#30ns out = 1'b0;
end
但这不是可综合的,所以对你的最终申请没有帮助。
对于顺序(时钟)逻辑,时间高或低必须是整数个时钟周期。使用计数器作为状态并对其进行组合解码。
always @(posedge clk, rst) begin
if(rst) begin
counter <= 'b0;
end
else begin
counter <= counter + 1;
end
end
always @* begin
if (counter < 10) begin
out = 1'b0;
end
else if (counter < 30) begin
out = 1'b1;
end
else if (counter < 50) begin
out = 1'b0;
end
else if (counter < 90) begin
out = 1'b1;
end
else begin
out = 1'b0;
end
end