Verilog阻塞分配未阻塞
我对Verilog阻塞分配有一个问题,在模拟中,它似乎没有阻塞。特别是在第二个总是@block。我需要rst只为V1单元(时钟周期?)变为“1”,但它同时变为“1”和“0”。当我替换两个Verilog阻塞分配未阻塞,verilog,system-verilog,hdl,Verilog,System Verilog,Hdl,我对Verilog阻塞分配有一个问题,在模拟中,它似乎没有阻塞。特别是在第二个总是@block。我需要rst只为V1单元(时钟周期?)变为“1”,但它同时变为“1”和“0”。当我替换两个rst=1'b0时带有rst=#10 1'b0然后在模拟中,我可以看到rst在10个时间单位内变为“1”。有人能帮我吗 module testled( input clk, output reg out ); reg [23:0] counter; reg rst; initial begin
rst=1'b0时代码>带有rst=#10 1'b0代码>然后在模拟中,我可以看到rst在10个时间单位内变为“1”。有人能帮我吗
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
endmodule出于模拟目的,您可以执行以下操作:
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
始终@(posedge clk,rst)开始
如果(rst)开始
计数器你需要使用非阻塞(你能编辑这个问题来描述你试图生成的序列吗。你希望rst高出多长时间?这根本不重要,因为我只想看看如何生成“1”和“0”不同长度的。我想对ws2812b LED进行编程,数据流中的位与不同长度的逻辑“1”和“0”相结合。我无法使这些“1”和“0”具有不同的长度,所以我只想了解这是如何工作的。ws2812b数据表类文档可以在这里的链接上找到