简体   繁体   English

如何根据开关的值有条件地将参数传递给模块? (verilog)

[英]How to conditionally pass a parameter to a module depending on the value of a switch? (verilog)

does anyone know the correct method of passing a parameter to a verilog module conditionally? 有谁知道有条件地将参数传递给Verilog模块的正确方法? For example, I am doing a uart assignment, the uart itself can process 7 or 8 data bits per word. 例如,我正在执行uart分配,uart本身可以处理每个单词7或8个数据位。 I basically need a way to pass 7 or 8 down to the uart module if the switch is high or low. 如果开关高或低,我基本上需要一种将7或8传递给uart模块的方法。 I tried an always case statement but kept getting errors. 我尝试了一个总是个案的陈述,但是不断出错。

I know how to pass by name the parameter for example: 我知道如何通过名称传递参数,例如:

module top
#(parameter DATABITS = 7,
parameter DATABITS2 = 8)
(input [1:0] sw);

// Sorry I didnt list the whole code just tidbits to get the point across //对不起,我没有列出整个代码,只是花哨的小窍门

...... rest of code here....... 

// My attempt at an always case statement. //我尝试执行始终为个案的语句。 localparam dbit = 0; localparam dbit = 0;

always @(*)
begin 
        case(sw) 
            2'b00: begin
                dbit = DBIT1;
                end
            2'b01: begin
                dbit = DBIT2;
                end
        endcase
end // always @ (...)


UART #(.DATABITS(dbit)) UART_MODULE (.......ports etc in here); 

You use the module parameters to create modules that can be customized when you instantiate that module. 您可以使用模块参数来创建可在实例化该模块时自定义的模块。 However, once your netlist has been elaborated, the configuration of your UART_MODULE is fixed, based on the values you passed in as parameters. 但是,一旦详细说明了网表,UART_MODULE的配置将根据您作为参数传入的值而固定。

The module cannot be "re-parameterized" during run-time. 运行期间不能对模块进行“重新参数化”。 If you really do want to modify the data width on the fly you will have to add a 7/8-bit flag to your module's port list and add code to the module itself to handle the variable data width indicated by that flag. 如果您确实想即时修改数据宽度,则必须在模块的端口列表中添加7/8位标志,并在模块本身中添加代码以处理该标志指示的可变数据宽度。

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

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