参考
ModelSim 配合 Makefile 搭建 Verilog 仿真工程
命令
Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows PS D:\test\ax301>iverilog-g2012-osim tb.sv clock_div.v PS D:\test\ax301>vvp sim VCD info: dumpfile clock_div.vcd openedforoutput.=====Start clk_div simulation(N=2)==========End clk_div simulation=====PS D:\workspace\gitee\0\ming-verilog_prj\ming-verilog\test\ax301>gtkwave clock_div.vcd GTKWave Analyzer v3.3.71(w)1999-2016 BSI[0]start time.[2000000]end time.clock_div.v
`timescale 1ns / 1ps module clock_div#( parameter P_CLK_DIV_CNT = 2 //MAX = 65535 )( input i_clk , input i_rst_n , output o_clk_div ); reg ro_clk_div ; reg [15:0] r_cnt ; assign o_clk_div = ro_clk_div; localparam L_COMPARE_CNT = P_CLK_DIV_CNT/2 - 1; always @(posedge i_clk or negedge i_rst_n)begin if(!i_rst_n) r_cnt <= 'd0; else if(r_cnt == L_COMPARE_CNT) r_cnt <= 'd0; else r_cnt <= r_cnt + 1; end always @(posedge i_clk or negedge i_rst_n)begin if(!i_rst_n) ro_clk_div <= 'd0; else if(r_cnt == L_COMPARE_CNT) ro_clk_div <= ~ro_clk_div; else ro_clk_div <= ro_clk_div; end endmoduletb.sv (生成vcd文件)
`timescale 1ns / 1ps module tb; // --------------------------------- // 参数:分频系数 // --------------------------------- parameter int P_CLK_DIV_CNT = 2; // --------------------------------- // 信号声明 // --------------------------------- reg i_clk; reg i_rstn; wire o_clk_div; // --------------------------------- // 实例化被测模块 // --------------------------------- clock_div #( .P_CLK_DIV_CNT(P_CLK_DIV_CNT) ) dut ( .i_clk (i_clk), .i_rst_n (i_rstn), .o_clk_div (o_clk_div) ); // --------------------------------- // 生成时钟:50MHz (20ns) // --------------------------------- initial i_clk = 1'b0; always #10 i_clk = ~i_clk; // --------------------------------- // 复位过程 // --------------------------------- initial begin i_rstn = 1'b0; #100; i_rstn = 1'b1; end // --------------------------------- // VCD 波形输出(关键) // --------------------------------- initial begin $dumpfile("clock_div.vcd"); // 生成的波形文件名 $dumpvars(0, tb); // dump 整个 tb 层级 end // --------------------------------- // 仿真时间控制 // --------------------------------- initial begin $display("===== Start clk_div simulation (N = %0d) =====", P_CLK_DIV_CNT); #2000; $display("===== End clk_div simulation ====="); $finish; end endmodule