【问题标题】:4 bit 4:1 mux structural modelling in verilog using veriwave使用 Veriwave 在 Verilog 中进行 4 位 4:1 多路复用器结构建模
【发布时间】:2020-12-06 16:30:17
【问题描述】:

我正在为 4 位 4:1 多路复用器设计结构模型。 我的verilog代码如下所示。Eda Playground在执行代码时抛出了分段错误。但是使用其他模拟器执行时没有问题。日志如下所示。

design.sv: L1: error: 语法错误,意外输入

design.sv: L7: error: 'a' not declared

design.sv: L7: error: 'b' not declared

design.sv: L7: error: 'c' not declared

design.sv: L7: 错误:'d' 未声明

design.sv: L7: 错误: 'sel' 未声明

design.sv: L8: 错误:'sel' 未声明

design.sv:L9:错误:未声明“out”

design.sv: L9: 错误:'a' 未声明

design.sv: L10: error: 'out' not declared

design.sv: L10: error: 'b' not declared

design.sv:L11:错误:未声明“out”

design.sv: L11: error: 'c' not declared

design.sv: L12: error: 'out' not declared

design.sv: L12: error: 'd' not declared

./run.sh:第 4 行:14 分段错误(核心转储)veriwell design.sv testbench.sv

module mux_4to1_case ( input [3:0] a,                 
                       input [3:0] b,                 
                       input [3:0] c,                 
                       input [3:0] d,                 
                       input [1:0] sel,               
                       output reg [3:0] out);  
  always @ (a or b or c or d or sel) begin
      case (sel)
         2'b00 : out <= a;
         2'b01 : out <= b;
         2'b10 : out <= c;
         2'b11 : out <= d;
      endcase
   end
endmodule

Verilog 测试台


    module tb_4to1_mux;
    
      reg [3:0] a;
      reg [3:0] b;
      reg [3:0] c;
      reg [3:0] d;
      wire [3:0] out;
      reg [1:0] sel;
      integer i;
    
    
      mux_4to1_case  mux0 (   .a (a),
                           .b (b),
                           .c (c),
                           .d (d),
                           .sel (sel),
                           .out (out));
    
    
      initial begin
    
        $monitor ("[%0t] sel=0x%0h a=0x%0h b=0x%0h c=0x%0h d=0x%0h out=0x%0h", $time, sel, a, b, c, d, out);
    
    
        sel <= 0;
        a <= $random;
        b <= $random;
        c <= $random;
        d <= $random;
    
    
        for (i = 1; i < 4; i=i+1) begin
          #5 sel <= i;
        end
    
    
        #5 $finish;
      end
        initial begin
        $dumpvars;
        $dumpfile("sth.vcd");
      end
    endmodule

执行代码时出现以下分段错误 Logs.png

【问题讨论】:

  • 如果是 Verilog,为什么您的文件是 .sv?它是作为 SystemVerilog 运行的吗?

标签: verilog fpga


【解决方案1】:

自 IEEE std 1364-2001 起合法的 ANSI 样式的模块头和端口定义。

EDAplayground 有 VeriWell 2.8.7,它只支持 1995 版的 Verilog 标准 (IEEE std 1364-1995)。 1995 标准支持现在称为非 ANSI 样式的标头。 VeriWell 3 on github 提到它支持一些 2001 功能。

您可以将代码从 ANSI 转换为非 ANSI(如下所示)或更改模拟器。 EDAplayground 有一系列模拟器可供选择。 Icarus 是维护最积极的免费模拟器。 Aldec Riviera 是一款商业模拟器,目前可在 EDAplayground 上免费使用。

除非明确要求您遵循 IEEE1364-1995 标准,否则我建议您更改模拟器。现代模拟器已转向 IEEE1800 SystemVerilog 标准,该标准与 IEEE1364 向后可比。


ANSI 样式标头:(IEEE1364-2001 及更高版本)

module mux_4to1_case ( input [3:0] a,
                       input [3:0] b,
                       input [3:0] c,
                       input [3:0] d,
                       input [1:0] sel,
                       output reg [3:0] out);

非 ANSI 样式标头:(IEEE1364-1995 及更高版本)

module mux_4to1_case (a,b,c,d,sel,out);
  input [3:0] a;
  input [3:0] b;
  input [3:0] c;
  input [3:0] d;
  input [1:0] sel;
  output [3:0] out;
  reg [3:0] out;

其他说明:

  • always @ (a or b or c or d or sel) 适用于 IEEE1364-1995,但已简化为 always @*,适用于 IEEE1364-2001 及更高版本。 SystemVerilog IEEE1800 使用always_comb/always_latch@ 均未使用)进一步增强了它,以便在模拟中检查一些综合要求。
  • 应使用非阻塞分配 (&lt;=) 来分配触发器和预期的锁存器。组合逻辑应使用阻塞分配 (=)。您的 4:1 多路复用器代表组合逻辑,因此需要阻塞分配。不正确地使用阻塞/非阻塞可能会导致意外的模拟行为以及 RTL 与综合不匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多