0

我创建了两个不同的 Verilog 模块(shiftByImmimmShifter)。我想要做的是只选择两者之一的输出作为我正在创建的这个小多路复用器模块的输出。

module superShifter(input [0:31] in, input select, input [0:4] shift_value, input[0:1] shift, output reg [0:31] out);

shiftByImm shift0(in, shift_value, shift, out);
immShifter shift1(in, shift_value, out);

assign {out} = select == 1'b0 ? shift0 : shift1;

endmodule

但是,这给了我两个完全可以理解的错误:

非法引用接口“shift0”and非法引用接口“shift1”

我知道这里缺少一些东西。如何选择SuperShifter模块的输出与预制模块之一的输出相同?

4

2 回答 2

3

您的问题在于您的命名约定。您有 2 个具有 2 个不同输出的模块(我猜),但您给它们取了相同的名称。在此示例中,您使用的是端口排序方法。括号中的名称按顺序隐式关联,不需要与它们在实例化中的名称相同。另一种方法是按名称连接端口。在示例中,我展示了这两种方法。从那时起,您将不得不使用声明的电线来选择带有“小多路复用器”的输出。

module superShifter(input [0:31] in, input select, input [0:4] shift_value, input[0:1] shift, output reg [0:31] out);

wire [0:31] temp_out_0;
wire [0:31] temp_out_1;

shiftByImm shift0(in, shift_value, shift, temp_out_0);
immShifter shift1(.in(in), .shift_value(shift_value), .out(temp_out_1));

assign {out} = select == 1'b0 ? temp_out_0 : temp_out_1;

endmodule
于 2014-03-18T05:28:53.193 回答
1

继@N8TROs 回答之后,您似乎正在尝试“调用”模块并让它们生成输出。

模块不等同于在需要时调用的任务,它们代表硬件的物理块。多路复用器需要选择您想要的输出,而不是您希望激活的模块。

由于两个模块驱动相同的输出,您可能会看到xs 当一个模块驱动 1 而另一个驱动 0 时,电线或网络最终会发生冲突。

我非常同意 N8TROs 建议使用 ANSI 风格的命名端口,这确实有助于调试和代码维护。

但为简洁起见并查看代码中的最小更改以使其工作:

shiftByImm shift0(in, shift_value, shift, out0); //<-- Unique output
immShifter shift1(in, shift_value, out1);        //<-- Unique output

assign {out} = select == 1'b0 ? out0: out1;  //<-- select output
于 2014-03-18T12:32:12.607 回答