首页 > 技术文章 > Verilog如何从外部更改模块内参数

ylsm-kb 2018-04-18 17:39 原文

例如有一个模块

1 module x(a,b,c);
2    input a,b; 
3    output c; 

4    parameter t=4'd0, h=9'd3;
5  
6    ......
7  
8 endmodule

 

两种解决方法:

  • 1、使用带有参数值的模块实例语句
 1 module x_top(d,e,f,g);
 2   input d,e,f;
 3   output g;
 4 
 5   x #(1,4) xx(
 6       .a(a),
 7       .b(b),
 8       .c(c)
 9       );
10 endmodule

 

  • 2、使用参数重定义语句deparam

 

 1 module x_top(d,e,f,g);
 2   input d,e,f;
 3   output g;
 4 
 5   deparam   xx.t = 4'd1, xx.h = 9'd4;
 6 
 7   x  xx(
 8       .a(a),
 9       .b(b),
10       .c(c)
11       );
12 
13 endmodule

 

 

注意:对于下面这个模块

module exam_prj
2     #(parameter WIDTH=8)     //parameter 1
3     //端口内的参数只能在这使用 
4     (
5         input [WIDTH-1:0] dataa,//[WIDTH-1:0]
6         input [WIDTH-1:0] datab,
7 
8         output reg [WIDTH:0] result
9     );
 parameter Conuter_Top = 4'd9;//用于代码部分的参数  parameter 2
//代码部分省略
endmodule

这里出现的两个参数 parameter,第一个表示只在端口设置时使用,第二个是对于模块内部的使用。

 

2018-04-18  17:26:34

推荐阅读