首页 文章

Verilog在测试平台中多个同时独立的信号分配

提问于
浏览
1

在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;

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

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

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

2 回答

  • 4

    在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信号只能切换一次 . 我稍微修改了它,以便时钟无休止地运行 .

  • 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

相关问题