Verilog组合逻辑设计运行testbench时出现elaboration阶段错误的咨询
Verilog组合逻辑仿真Elaboration阶段报错修复
报错对应问题拆解
仿真器抛出的3个elaboration错误全部是代码书写错误导致,和仿真器运行环境无关,对应问题逐一定位如下:
CDnot信号绑定失败
对应原组合逻辑模块第29行的F赋值语句:assign F = AnotCnotD|CDnot|ACnotDnot;- 问题本质:代码全程没有声明、定义过
CDnot这个信号,也没有对其做赋值操作,仿真器根本识别不了这个标识符。 - 大概率笔误:同模块里已经写好了
BCDnot = B&C&~D的赋值,拼F的表达式时漏写了前面的B,把BCDnot错写成了CDnot。
- 问题本质:代码全程没有声明、定义过
project4_test层次绑定失败
对应原testbench中$dumpvars(0, project4_test);语句:- 问题本质:当前testbench的模块名是
tb_combLogic,整个仿真层次里根本不存在叫project4_test的模块或实例,$dumpvars填的层次路径是错的。
- 问题本质:当前testbench的模块名是
- 连带的端口、类型声明错误
原testbench还藏了两处后续会触发报错的问题:- 例化
combinational_logic模块时,漏接了原模块的F输出端口,端口连接不完整。 - 误把UUT输出的
F信号在testbench里声明成了reg类型,UUT输出驱动的连接信号在testbench端应该声明为wire,不需要手动赋值驱动。
- 例化
修正后可直接运行的代码
调整后的待测试组合逻辑模块
module combinational_logic( A, B, C, D, AnotCnotD, BCDnot, ACnotDnot, F ); input A; input B; input C; input D; output F; output AnotCnotD; output BCDnot; output ACnotDnot; assign AnotCnotD = ~A&~C&D; assign BCDnot = B&C&~D; assign ACnotDnot = A&~C&~D; // 修正笔误:将错写的CDnot替换为已定义的BCDnot assign F = AnotCnotD | BCDnot | ACnotDnot; endmodule
调整后的Testbench代码
`include "project4.v" module tb_combLogic; reg A; reg B; reg C; reg D; // 修正类型:F是UUT输出信号,改用wire声明 wire F; wire AnotCnotD; wire BCDnot; wire ACnotDnot; combinational_logic uut ( .A(A), .B(B), .C(C), .D(D), .AnotCnotD(AnotCnotD), .BCDnot(BCDnot), .ACnotDnot(ACnotDnot), // 补全之前漏掉的F端口连接 .F(F) ); initial begin $display("Start of Test."); $dumpfile("comb_logic.vcd"); // 修正层次参数:替换为当前testbench的模块名tb_combLogic $dumpvars(0, tb_combLogic); $display("End of Test."); end endmodule
写代码的小提示
- Verilog模块的端口列表最后一个端口后面不要加多余的逗号,部分老旧仿真器对这类语法兼容性不好,原代码端口列表里F后面的逗号可以删掉。
- Testbench里的信号分两类写类型:用来驱动UUT输入的激励信号声明为
reg,接UUT输出的观察信号声明为wire,不要混着写。
内容的提问来源于stack exchange,提问作者GHG HGH
相关产品推荐
相关产品推荐

