在 verilog 中使用 always 块时出错
Error while using always block in verilog
我在 verilog 中有一个模块 temp1
,如下所示,-
module temp1;
---
---
---
endmodule
我想从其他模块 temp2
调用这个模块实例。但是,我想在时钟的上升沿保持这种状态-
module temp2(clk);
input clk;
always @(posedge clk)
temp1 t1;
endmodule
这给我语法错误。看来我不应该从 always 块中调用任何模块。我们不能从 always
块中创建模块实例是真的吗?如果是,我怎么能以其他方式做到这一点,因为我只能在时钟的位置调用 temp1?
在 verilog 中,当您实例化 一个模块时,这意味着您正在向电路板添加额外的硬件。
这个硬件必须在仿真开始之前添加(即在编译时)。在这里,您可以 not add/remove 硬件在每个时钟脉冲。
实例化后,模块 executed/checked 用于模拟的 每个时间戳 ,直到结束。
因此,要执行任何模块,只需实例化它,向其提供 clk 和其他所需的输入,然后 在子模块中添加 always 块本身.
module temp2(clk);
input clk;
temp1 t1(clk); // note the input port clk here
endmodule
module temp(input clk);
always @(posedge clk)
begin
// ...
end
endmodule
Verilog 提供了一个 generate 块,用于创建同一模块的 多个实例 。
genvar i; // note special genvar type, used in generate block
generate
for(i=0;i<5;i++)
temp t1[i]; // create 5 instances of temp module
endgenerate
旁注:
你可能对模块实例化和task/function的调用理解混淆了。模块是一个静态实体,而task/function可以是动态实体。如您所见,如果 temp 是一个任务,那么上面的调用是有效的。
task temp;
// ...
endtask: temp
module temp2(clk);
input clk;
always @(posedge clk)
temp1(); // task/function temp
endmodule
更多关于实例化的信息可以从Verilog Module Instantiation, Instantiating Modules and Primitives, Structural Modelling链接获得。
我在 verilog 中有一个模块 temp1
,如下所示,-
module temp1;
---
---
---
endmodule
我想从其他模块 temp2
调用这个模块实例。但是,我想在时钟的上升沿保持这种状态-
module temp2(clk);
input clk;
always @(posedge clk)
temp1 t1;
endmodule
这给我语法错误。看来我不应该从 always 块中调用任何模块。我们不能从 always
块中创建模块实例是真的吗?如果是,我怎么能以其他方式做到这一点,因为我只能在时钟的位置调用 temp1?
在 verilog 中,当您实例化 一个模块时,这意味着您正在向电路板添加额外的硬件。
这个硬件必须在仿真开始之前添加(即在编译时)。在这里,您可以 not add/remove 硬件在每个时钟脉冲。
实例化后,模块 executed/checked 用于模拟的 每个时间戳 ,直到结束。
因此,要执行任何模块,只需实例化它,向其提供 clk 和其他所需的输入,然后 在子模块中添加 always 块本身.
module temp2(clk);
input clk;
temp1 t1(clk); // note the input port clk here
endmodule
module temp(input clk);
always @(posedge clk)
begin
// ...
end
endmodule
Verilog 提供了一个 generate 块,用于创建同一模块的 多个实例 。
genvar i; // note special genvar type, used in generate block
generate
for(i=0;i<5;i++)
temp t1[i]; // create 5 instances of temp module
endgenerate
旁注:
你可能对模块实例化和task/function的调用理解混淆了。模块是一个静态实体,而task/function可以是动态实体。如您所见,如果 temp 是一个任务,那么上面的调用是有效的。
task temp;
// ...
endtask: temp
module temp2(clk);
input clk;
always @(posedge clk)
temp1(); // task/function temp
endmodule
更多关于实例化的信息可以从Verilog Module Instantiation, Instantiating Modules and Primitives, Structural Modelling链接获得。