简体   繁体   English

模块内的模糊内部的参数

[英]parameter inside a moulde inside a module

I have read about parameters and how to redefine them at module instantiation but what if i have a parameter inside a module inside a module say that i have a small module called gen 我已经阅读了有关参数以及如何在模块实例化时重新定义它们但是如果我在模块内的模块内部有一个参数说我有一个名为gen的小模块怎么办?

module gen(input,output);
parameter n=2;
parameter m=10;
//do something
endmodule

that module is instantiated in another module called top 该模块在名为top的另一个模块中实例化

module top(inputs,output);
gen gen1(inputs,output);
//do something
endmodule;   

and i am trying to make a testbench on the big module where i need to redefine the two parameter n and m 我试图在大模块上制作一个测试平台,我需要重新定义两个参数nm

module tb;
reg input;
wire output;
top top1(input,output)
endmodule;

how can i write that in verilog? 我怎么能在verilog中写出来?

One solution is to redefine the parameters at each level: 一种解决方案是重新定义每个级别的参数:

module gen(input,output);
parameter n=2;
parameter m=10;
//do something
endmodule


module top(inputs,output);
parameter n=2;
parameter m=10;
gen #(.n(n), .m(m)) gen1(inputs,output);
//do something
endmodule;   

module tb;
reg input;
wire output;
top #(.n(n), .m(m)) top1(input,output)
endmodule;

Another solution is to keep your current module definition and use defparam in your testbench to hierarchically override the value of parameters: 另一种解决方案是保持当前模块定义并在测试平台中使用defparam以分层方式覆盖参数值:

module tb;
reg input;
wire output;
defparam top1.gen1.m = 4;
defparam top1.gen1.n = 5;
top top1(input,output)
endmodule;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM