【问题标题】:How to wire up modules and pass value如何连接模块并传递值
【发布时间】:2023-03-29 17:26:01
【问题描述】:
module container(x1, x2, x3, NUMBER);

input x1, x2, x3;
output NUMBER;
wire w0, w1;

dec_counter U1 (x1, x2, x3, w0, w1);
doz_counter U2 (w1, w0, NUMBER);


endmodule


module dec_counter(clk, reset, clk_enable, counter, terminal);

    input clk;
    input reset;
    input clk_enable;
    output reg [3:0] counter;
    output reg terminal;



always @(posedge clk, posedge clk_enable, posedge reset)
        if(reset)
        begin
            terminal <= 1;
            counter <= 0;
        end
        else if(clk && clk_enable)
            if(counter < 9)
            begin
                terminal <= 1;
                counter <= counter + 1; 
            end           
            else
            begin
                terminal <= 1;
                counter <= 0;
            end  
endmodule



module doz_counter(dozens, unity, number);

input dozens;
input unity;
output reg [7:0] number;

initial begin
    number = 8'd0;
end    

always @(posedge dozens)
    if(dozens)
        number <= number + 1;

endmodule

你好!我是verilog的新手,我遇到了第一个问题。我有从 0 到 9 计数的模块 dec_counter。当它达到 9+1 时,它显示 0 并将“输出终端”设置为 1。现在我想将该值作为“输入数十”传递给我的下一个模块 doz_counter。我试过接线,正如你在模块容器中看到的那样,但在我的模拟中,几十个总是 X,即使终端是 1。

我觉得我犯了一些严重的设计错误。

【问题讨论】:

    标签: module verilog vivado


    【解决方案1】:

    您发布的代码运行良好端口连接规则请参考下图。输出端口可以是regwire 中的任何一个,但输入端口始终是wire

    几个错误如下:

    您已将dec_counter 模块中的4 位端口reg [3:0] counter; 连接到container 模块中的单位端口w0。这将导致端口连接宽度不匹配。

    wire [3:0] w0;
    wire w1;
    // ...
    

    同样,container 模块中的单比特端口 NUMBER 连接到doz_counter 模块中的8 比特端口 number。这将导致端口连接宽度不匹配。

    output [7:0] NUMBER;
    //...
    

    另外,terminal重置时的值可能为零if-else 条件驱动 terminal 的相同值。 terminal 应该有不同的值,分别为 terminal &lt;= 1terminal &lt;= 0;

    这是供您参考的代码的测试平台:

    module top();
    
    bit x1, x2, x3;
    bit [7:0] NUMBER;
    
    container c(x1, x2, x3, NUMBER);
    
    always #5 x1 = ~x1;
    
    initial
    begin
    #6 x2 = 1;
    #6 x2 = 0; x3 = 1;
    #100 $finish;
    end
    
    endmodule 
    

    【讨论】:

      猜你喜欢
      • 2020-09-02
      • 1970-01-01
      • 2014-04-26
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 2023-04-08
      • 2021-02-19
      相关资源
      最近更新 更多