全加器输出始终设置为 X

问题描述 投票:0回答:2

我开始进行 FPGA 编码,我的第一个练习是编写全加器。我正在使用 SystemVerilog 在 Vivado 中进行编码。我对此的看法如下:

来源:

`timescale 1ns/10ps
module challenge
  (
   input  wire  [2:0]    SW,
   output logic [1:0]    LED
   );
  assign LED[0]=SW[1]^SW[0]^SW[2]; // Write the code for the Sum
  assign LED[1]=(SW[1]&SW[0])|((SW[1]^SW[0])&SW[2]); // Write the code for the Carry
endmodule // challenge

测试台:

`timescale 1ns/100ps
module tb;

  logic [2:0] SW;
  logic [1:0] LED;

  challenge u_challenge (.*);

  // Stimulus
  initial begin
    $printtimescale(tb);
    SW = '0;
    for (int i = 0; i < 8; i++) begin
      $display("Setting switches to %3b", i[2:0]);
      SW  = i[2:0];
      #100;
    end
    $display("PASS: logic_ex test PASSED!");
    $stop;
  end

  logic [2:0] sum;
  assign sum = SW[0] + SW[1] + SW[2];
  // Checking
  always @(SW, LED) begin
    if (sum !== LED[0]) begin
      $display("FAIL: Addition mismatch");
      $stop;
    end
  end 
endmodule // tb

无论我从

SW
放入
LED
中(SW[0]、SW[1]、SW[2] 的任意组合),我总是将
LED
值设置为 X。 我对
SW
的定义有问题吗?

system-verilog fpga hdl vivado
2个回答
1
投票

你对

SW
的定义看起来不错。

我从代码中删除了

$stop
调用,以便模拟能够运行完成。使用
$stop
停止模拟并将其设置为交互模式。也许 Vivado 正在等待您输入命令,然后才会更新您的输出。

我将您的代码复制到EDA Playground,并且运行良好。我在波形中没有看到 X。

这是我看到的输出:

Setting switches to 001
FAIL: Addition mismatch
Setting switches to 010
Setting switches to 011
FAIL: Addition mismatch
FAIL: Addition mismatch
Setting switches to 100
FAIL: Addition mismatch
Setting switches to 101
FAIL: Addition mismatch
FAIL: Addition mismatch
Setting switches to 110
FAIL: Addition mismatch
Setting switches to 111
FAIL: Addition mismatch
FAIL: Addition mismatch
PASS: logic_ex test PASSED!

0
投票

我认为您可以在检查前增加一些等待时间。

  // Checking
  always @(SW, LED) begin
    #50;
    if (sum !== LED) begin
      $display("FAIL: Addition mismatch");
      $stop;
    end
  end 
© www.soinside.com 2019 - 2024. All rights reserved.