【问题标题】:Verilog multiple simultaneous independant signal assignments in testbenchVerilog 在测试台中同时分配多个独立信号
【发布时间】:2014-07-22 19:38:41
【问题描述】:

在 VHDL 中,我可以在我的测试平台中编写:

    signal clk      : std_logic := '0';
    signal count_in     : std_logic_vector(3 downto 0) := "0000";
    signal load     : std_logic := '0';
    signal reset        : std_logic := '0';
    signal count_out    : std_logic_vector(3 downto 0)  := "0000";
    ...

    clk <= not clk after 50 ns;
    reset <= '1' after 1400 ns, '0' after 1900 ns;
    count_in <= "1010" after 2500 ns;
    load <= '1' after 2700 ns, '0' after 3000 ns;

信号声明位于测试平台架构的“开始”之前,而省略号之后的部分位于测试平台架构的主体中。更好的方法是在编写测​​试平台时使用以“wait”语句结尾的进程。我了解如何在 verilog 和 VHDL 中执行此操作。

在verilog中,我们可以有一个初始块,赋值一次。也可以有多个初始块。我没有尝试过,但我认为从多个初始块驱动相同的信号是不明智的。

现在我的问题是,如何将上述 DUT 激励代码转换为 Verilog?我希望我将使用具有多个#delay 值的分配语句。那是对的吗?我该怎么做?

【问题讨论】:

    标签: vhdl verilog


    【解决方案1】:

    在 Verilog 2001 及更高版本中,您可以在声明时初始化变量,如 VHDL。另一种有趣但可能不太常见的方法是使用带有阻塞分配的 fork-join 块。在下面的代码中,fork-join 块中的每一行都是独立并发执行的。

    module test;
        reg clk, load, reset;
      reg [3:0] count_in, count_out;
        initial 
        begin
            fork 
                begin clk   = 0;        while (1) #50 clk = ~clk;               end 
                begin count_in  = 0;    #2500 ; count_in = 4'b1010;             end
                begin load      = 0;    #2700 ; load = 1 ; #3000; load = 0;     end
                begin reset = 0;        #1400 ; reset = 1; #1900; reset = 1;    end
                count_out   = 0;
            join
        end
    endmodule
    

    edaplayground 上的工作示例。

    另外,请注意代码中的 clk 信号只切换一次。我稍微修改了一下,让时钟无限运行。

    【讨论】:

    • hmm.. 我在 VHDL 中看不到任何类似于 fork-join 的东西。我认为这是 systemverilog 特有的。
    • 据我所知,VHDL 中没有 fork-join,但它从 Verilog-95 开始就存在于 Verilog 中。 SystemVerilog 通过添加join_anyjoin_none 对其进行了扩展。请注意,fork-join 是一个非常强大的构造,但它不可综合,可能会使调试复杂化。
    【解决方案2】:

    我对 VHDL 不太熟悉,但这看起来像是测试台刺激。我生成了可运行的测试用例进行比较here

    Verilog 等效项如下所示:

    reg clk = 1'b0;
    reg [3:0] count_in = 4'b0000;
    reg load = 1'b0;
    reg reset = 1'b0;
    wire [3:0] count_out; // test bench is not driving this
    ...
    
    initial begin
      clk <= #50 !clk;
      reset <= #1400 1'b1;
      reset <= #1900 1'b0;
      count_in <= #2500 4'b1010;
      load <= #2700 1'b1;
      load <= #3000 1'b0;
    end
    

    这将生成相同的波形,除了count_out 是浮动的而不是全零。根据命名约定,我认为count_out 应该由被测设备驱动,它必须是电线类型。

    SystemVerilog 可能类似于:

    /* Note: bit cannot be X or Z
     * initializes equivalent to 'logic clk = 1'b0;' or 'reg clk = 1'b0;'
     */
    bit clk; 
    bit [3:0] count_in;
    bit load;
    bit reset;
    wire [3:0] count_out; // logic type is also okay
    ...
    
    initial begin
      clk <= #50ns !clk;
      reset <= #1400ns 1'b1;
      reset <= #1900ns 1'b0;
      count_in <= #2500ns 4'b1010;
      load <= #2700ns 1'b1;
      load <= #3000ns 1'b0;
    end
    

    Verilog 和 System Verilog 的工作示例here

    【讨论】:

      猜你喜欢
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多