使用 veriwave 在 verilog 中进行 4 位 4:1 多路复用器结构建模
4 bit 4:1 mux structural modelling in verilog using veriwave
我正在设计一个 4 位 4:1 多路复用器的结构模型。
我的 verilog 代码显示 below.Eda playground 在执行 code.But 时抛出分段错误,使用其他 simulators.The 日志执行时没有问题,如下所示。
design.sv:L1:错误:语法错误,意外输入
design.sv:L7:错误:'a' 未声明
design.sv:L7:错误:'b' 未声明
design.sv:L7:错误:'c' 未声明
design.sv:L7:错误:'d' 未声明
design.sv:L7:错误:'sel' 未声明
design.sv:L8:错误:'sel' 未声明
design.sv:L9:错误:'out' 未声明
design.sv:L9:错误:'a' 未声明
design.sv:L10:错误:'out' 未声明
design.sv:L10:错误:'b' 未声明
design.sv:L11:错误:'out' 未声明
design.sv:L11:错误:'c' 未声明
design.sv: L12: 错误: 'out' 未声明
design.sv:L12:错误:'d' 未声明
./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
您的模块 header 和 ANSI 样式的端口定义自 IEEE std 1364-2001 以来是合法的。
EDAplayground 有 VeriWell 2.8.7,它只支持 1995 版的 Verilog 标准 (IEEE std 1364-1995)。 1995 年的标准支持现在称为 non-ANSI 样式的 header。 VeriWell 3 on github 提到它支持某些 2001 功能。
您可以将您的代码从 ANSI 转换为 non-ANSI(如下所示)或更改模拟器。 EDAplayground 有一系列模拟器。 Icarus 是维护最活跃的免费模拟器。 Aldec Riviera 是一款商业模拟器,目前可在 EDAplayground 上免费使用。
除非明确要求您遵循 IEEE1364-1995 标准,否则我建议您更换模拟器。现代模拟器已转向 IEEE1800 SystemVerilog 标准,该标准可与 IEEE1364 向后比较。
ANSI 样式header:(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);
Non-ANSI 风格 header: (IEEE1364-1995 and later)
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
(均未使用 @
)进一步增强了它,用于在模拟中检查某些综合要求。
- Non-blocking 分配 (
<=
) 应该用于分配 flip-flops 和预期的锁存器。组合逻辑应使用阻塞分配 (=
)。您的 4:1 mux 表示组合逻辑,因此需要阻塞分配。 blocking/non-blocking 的不正确使用会导致意外的仿真行为和 RTL 与综合不匹配。
我正在设计一个 4 位 4:1 多路复用器的结构模型。 我的 verilog 代码显示 below.Eda playground 在执行 code.But 时抛出分段错误,使用其他 simulators.The 日志执行时没有问题,如下所示。
design.sv:L1:错误:语法错误,意外输入
design.sv:L7:错误:'a' 未声明
design.sv:L7:错误:'b' 未声明
design.sv:L7:错误:'c' 未声明
design.sv:L7:错误:'d' 未声明
design.sv:L7:错误:'sel' 未声明
design.sv:L8:错误:'sel' 未声明
design.sv:L9:错误:'out' 未声明
design.sv:L9:错误:'a' 未声明
design.sv:L10:错误:'out' 未声明
design.sv:L10:错误:'b' 未声明
design.sv:L11:错误:'out' 未声明
design.sv:L11:错误:'c' 未声明
design.sv: L12: 错误: 'out' 未声明
design.sv:L12:错误:'d' 未声明
./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
您的模块 header 和 ANSI 样式的端口定义自 IEEE std 1364-2001 以来是合法的。
EDAplayground 有 VeriWell 2.8.7,它只支持 1995 版的 Verilog 标准 (IEEE std 1364-1995)。 1995 年的标准支持现在称为 non-ANSI 样式的 header。 VeriWell 3 on github 提到它支持某些 2001 功能。
您可以将您的代码从 ANSI 转换为 non-ANSI(如下所示)或更改模拟器。 EDAplayground 有一系列模拟器。 Icarus 是维护最活跃的免费模拟器。 Aldec Riviera 是一款商业模拟器,目前可在 EDAplayground 上免费使用。
除非明确要求您遵循 IEEE1364-1995 标准,否则我建议您更换模拟器。现代模拟器已转向 IEEE1800 SystemVerilog 标准,该标准可与 IEEE1364 向后比较。
ANSI 样式header:(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);
Non-ANSI 风格 header: (IEEE1364-1995 and later)
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
(均未使用@
)进一步增强了它,用于在模拟中检查某些综合要求。- Non-blocking 分配 (
<=
) 应该用于分配 flip-flops 和预期的锁存器。组合逻辑应使用阻塞分配 (=
)。您的 4:1 mux 表示组合逻辑,因此需要阻塞分配。 blocking/non-blocking 的不正确使用会导致意外的仿真行为和 RTL 与综合不匹配。