Verilog重载模块参数:spa
当一个模块引用另一个模块时,高层模块能够改变低层模块用parameter定义的参数值,改变低层模块的参数值可采用如下两种方式:code
1)defparam 重定义参数
语法:defparam path_name = value ;
低层模块的参数能够经过层次路径名从新定义,以下例:blog
module top ( .....) input....; output....; defparam U1 . Para1 = 10 ; M1 U1 (..........); endmodule module M1(....); parameter para1 = 5 ; input...; output...; ...... endmodule
在上例中,模块M1参数 para1 的缺省值为5,而模块top实例了M1后将参数的值改成10。input
2) 实例化时传递参数
在这种方法中,实例化时把参数传递进去,以下例所示:class
module top ( .....) input....; output....; M1 #( 10 ) U1 (..........); endmodule
在该例中,用#( 10 )修改了上例中的参数para1,当有多个参数时,用逗号隔开,如#( 10 , 5 )test
defparam可综合性问题:通常状况下是不可综合的.
提示:不要使用defparam语句!module
[例1] module mod ( out, ina, inb); … parameter cycle = 8, real_constant = 2.039, file = "/user1/jmdong/design/mem_file.dat"; … endmodule module test; … mod mk(out,ina,inb); // 对模块mod的实例引用 defparam mk.cycle = 6, mk.file = "../my_mem.dat"; // 参数的传递 … endmodule
[例2] module mod ( out, ina, inb); … parameter cycle = 8, real_constant = 2.039, file = "/user1/jmdong/design/mem_file.dat"; … endmodule module test; … mod # (5, 3.20, "../my_mem.dat") mk(out,ina,inb); // 对模块mod的实例引用 … endmodule
建议用此方法!file