首页 > 解决方案 > Verilog Dataflow 测试平台的问题导致不同站点上的不同错误

问题描述

该程序在 Dataflow Verilog 中。我要做的是使加法器和减法器依赖于选择器。我目前收到一些错误,这些错误是第 10 行的“连续分配中的语法错误”(assign {cout...},)或“启动 EPWave 时出错:[无法解析文件:在标题中找不到 $timescale .]. 无法加载“./dataflow_hw_1.vcd”。

我在整个互联网上寻找如何解决这个问题,但我一直在尝试推荐的解决方案,但无济于事。我不知道尝试测试它时出了什么问题。

这是代码:

module dataflow_1 (a[7:0],b[7:0],out[7:0],cout);

  input a,b;
  output out,cout;
  //if a have odd number of 1s, output = a + b
  //else if even positions have even number of 1s in total, output = a-b

  assign selectorOdd = (a[1]^ a[3]^ a[5] ^ a[7]);
  assign selectorEven = (~selectorOdd & ~(a[0] ^ a[2] ^ a[4] ^ a[6])); 
  assign {cout,out[7:0]} = (selectorOdd & ({a[7:0] + b[7:0}) | (selectorEven & ({a[7:0] - b[7:0]}));


endmodule

这是测试台代码:

// Code your testbench here
module dataflow_1();

  reg [7:0] a;
  reg [7:0] b;
  wire [7:0] out;


   dataflow_1  test(
     .a(a),
     .b(b),
     .out(out)
  );

  initial begin
    $dumpfile("dump.vcd");
    $dumpvars(0, out);

    a = 8'b01010101;
    b = 8'b00000001;
  #100;

  end



endmodule

标签: verilogdataflow

解决方案


问题出在这一行:

assign {cout,out[7:0]} = (selectorOdd & ({a[7:0] + b[7:0}) | (selectorEven & ({a[7:0] - b[7:0]}));

您使用了错误的{}and []{}用于连接位。它应该像这样修复:

assign {cout,out} = selectorOdd ? (a + b) : (selectorEven ? (a - b) : {9{1'b0}});

你的代码应该有更多的情况。在这段代码中 ifselectorOddselectorEvenare 0,我分配{cout,out}={9{1'b0}}.


推荐阅读