Verilog如何從外部更改模塊內參數


例如有一個模塊

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM