如何在verilog中切换模块?

如何在verilog中切换模块?,verilog,Verilog,我想使用SW[15]在模块A_7seg和B_7seg之间切换,但它不起作用。(2个模块分别工作) 由于“两个模块分别工作”,简单的方法是使用SW[15]在两个模块的输出之间进行选择 module mix( input CLOCK, input [15:0] SW, output reg [15:0] led, output reg [3:0] an, output reg [7:0] seg ); wire [15:0] B_led; wi

我想使用
SW[15]
在模块
A_7seg
B_7seg
之间切换,但它不起作用。(2个模块分别工作)


由于“两个模块分别工作”,简单的方法是使用
SW[15]
在两个模块的输出之间进行选择

module mix(
    input CLOCK,
    input [15:0] SW,
    output reg [15:0] led,
    output reg [3:0] an,
    output reg [7:0] seg
);
    wire [15:0] B_led;
    wire [3:0] A_an, B_an;
    wire [7:0] A_seg, B_seg;

    // if not using 'generate' block, modules are instantiated at
    // the top level, not in other 'if'/'case'/... structures.
    // and name the 2 instantiations
    A_7seg u_A_7seg (.CLOCK(CLOCK), .an(A_an), .seg(A_seg));
    B_7seg u_B_7seg (.CLOCK(CLOCK), .SW(SW), .led(B_led), .an(B_an), .seg(B_seg));

    // this extra circuit is needed to select between the two
    always@(*)begin
        if(SW[15])begin
            led = B_led;
            an  = B_an;
            seg = B_seg;
        end
        else begin
            led = 16'h0;  // <-- I assume the inactive value for 'led' is all-zero
            an  = A_an;
            seg = A_seg;
        end
    end
endmodule
模块混合(
输入时钟,
输入[15:0]开关,
输出调节[15:0]发光二极管,
输出寄存器[3:0]an,
输出寄存器[7:0]分段
);
导线[15:0]发光二极管;
电线[3:0]A_an,B_an;
导线[7:0]A_seg,B_seg;
//如果不使用“生成”块,模块将在
//顶层,而不是其他“如果”/“案例”/。。。结构。
//并命名这两个实例
A_7seg u_A_7seg(.CLOCK(CLOCK),.an(A_an),.seg(A_seg));
B_7seg u_B_7seg(.CLOCK(时钟),.SW(软件),.led(B_led),.an(B_an),.seg(B_seg));
//需要这个额外的电路来在两者之间进行选择
始终@(*)开始
如果(SW[15])开始
发光二极管=发光二极管;
a=B_an;
seg=B_seg;
结束
否则开始

发光二极管=16'h0;//<代码>生成
块用于在“编译时”而不是“运行时”有条件地实例化模块。您可以使用参数选择要实例化的模块,这将导致出现
a_7seg
B_7seg
;或者您实例化这两个(更多的面积消耗),并使用一根导线来选择当前正在工作的导线。在这种情况下,我可以知道如何添加导线吗?谢谢
module mix(
    input CLOCK,
    input [15:0] SW,
    output reg [15:0] led,
    output reg [3:0] an,
    output reg [7:0] seg
);
    wire [15:0] B_led;
    wire [3:0] A_an, B_an;
    wire [7:0] A_seg, B_seg;

    // if not using 'generate' block, modules are instantiated at
    // the top level, not in other 'if'/'case'/... structures.
    // and name the 2 instantiations
    A_7seg u_A_7seg (.CLOCK(CLOCK), .an(A_an), .seg(A_seg));
    B_7seg u_B_7seg (.CLOCK(CLOCK), .SW(SW), .led(B_led), .an(B_an), .seg(B_seg));

    // this extra circuit is needed to select between the two
    always@(*)begin
        if(SW[15])begin
            led = B_led;
            an  = B_an;
            seg = B_seg;
        end
        else begin
            led = 16'h0;  // <-- I assume the inactive value for 'led' is all-zero
            an  = A_an;
            seg = A_seg;
        end
    end
endmodule