首页 > 其他分享 >02-逻辑仿真工具VCS使用

02-逻辑仿真工具VCS使用

时间:2023-01-11 23:46:13浏览次数:49  
标签:02 仿真 20 cout sumout cin ain bin VCS

逻辑仿真工具VCS使用

1 Makefile执行VCS仿真

# Makefile for simulating the full_adder.v with the simulator VCS

# ----------------------------------------------------------------------------------
# Macro variable
RTL := ./full_adder.v
TB  += ./full_adder_tb.v
SEED ?= $(shell date +%s) 

# Target : Dependency
all : compile simulate

compile:
  vcs -sverilog -debug_all -timescale=1ns/1ps -l com.log
 
simulate:
  ./simv -l sim.log

run_dve:
  dve -vpd vcdplus.vpd &

clean :
  rm -rf *.log csrc simv* *.key *.vpd DVEfiles coverage *.vdb


# ------------------------------------------------------------------------------------
# This all_cov target is used to collect the code coverage
all_cov: compile_coverage simulate_coverage

compile_coverage:
  vcs -sverilog -debug_all -cm line+cond+fsm+tgl+branch \
      -lca timescale.v full_adder.v full_adder_tb.v -l com.log

simulate_coverage:
  ./simv +ntb_random_seed=$(SEED) -cm line+cond+fsm+tgl+branch \
         -lca -cm.log cm.log -l sim.log

report_cov:
  urg -dir simv.vdb -format both -report coverage

dve_cov:
  dve -cov -covdir simv.vdb -lca

2 full_adder RTL

module fulladder (
  // module head : verilog-2001 format
  input wire a_in,
  input wire b_in,
  input wire c_in,
  output wire sum_out,
  output wire c_out
  );
  // method 1 Gate Level Describe
  assign sum_out = a_in ^ b_in ^ c_in;
  assign c_out = (a_in & b_in) | (b_in & c_in) | (c_in & a_in);

  // method 2 RTL design for Adder with the keyword "assign"
  // behavior of adder can be systhesizable
  // "assign" means connectivity ,which is used to describe a combinational circuit
  // assign {c_out,sum_out} = a_in + b_in + c_in;

  // method 3 RTL design for Adder with the keyword "always"
  //reg c_out,sum_out
  //always @ (a_in,b_in,c_in) begin

endmodule

3 Testbench

module full_adder_tb;
  
  reg ain,bin,cin; //drive the input port with the reg type 
  wire sumout,cout;//sample the output port with the wire type
  full_adder u_full_adder(
  //task 1. how to create an instance 
  // module head: verilog-2001 format
  /*input wire*/ .a_in  (ain),
  /*input wire*/ .b_in  (bin),
  /*input wire*/ .c_in  (cin),    //carry in 
  /*output reg*/ .sum_out  (sumout);
  /*output reg*/ .c_out (cout)    //carry out
  );
  // behavior of the adder can be systhesizable
  // "assign" means connectivity
  // assign {c_out,sum_out} = a_in + b_in + c_in;
  
  // task 2. clock and rest generator
  parameter CLK_PERIOD = 20
  reg clk,rest_n; // rest_n :active low
  
  initial begin
    clk = 0
    forever begin
      #(CLK_PERIOD/2) clk = ~clk
    end
  end
  
  initial begin 
    reset_n = 0;
    #100
    reset_n = 1;
  end
  
  //taske 3. drive the stimulus and capture the response
  //Here is a testcase
  initial begin 
    #110 ain=0;
         bin=0;
         cin=0;    //00
    #20  ain=0;
         bin=1;
         cin=0;    //01
    #20  ain=1;
         bin=0;
         cin=0;    //01
    #20  ain=1;
         bin=1;
         cin=0;    //01
    #20  ain=0;
         bin=1;
         cin=0;    //01
    #20  ain=1;
         bin=0;
         cin=0;    //01
    #20  ain=1;
         bin=1;
         cin=0;    //10
    #20  ain=0;
         bin=0;
         cin=1;    //01
    #20  ain=0;
         bin=1;
         cin=1;    //10
    #20  ain=0;
         bin=0;
         cin=1;    //01
    #20  ain=0;
         bin=1;
         cin=1;    //10
    #20  ain=1;
         bin=0;
         cin=1;    //10
    #20  ain=1;
         bin=1;
         cin=1;    //11
    #50 finish;  // Here is a system task which can stop the simulation
  end

  //task 4. check the result
  always @ (posedge clk) begin
    if (!reset_n) begin
      $dispaly("%t:%m:restting...",$time)  // counter 5 clock
    end
    else begin 
      $dispaly("%t:%m:restting finish!",$time)  // the 6th clock
    end
  end
  
  initial begin 
    #115 if ({cout,simout} != 2'b00) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b01) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b01) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b10) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b01) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b10) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b10) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
    #20 if ({cout,simout} != 2'b11) $display("Error:{cout,sumout}=%b,ain=%b,bin=%b,cin=%b",{cout,sumout},ain,bin,cin);
  end
  
  //task 5. dump waveform with the comiple option -debug_all
  initial begin
    $vcdpluson
  end
endmodule

标签:02,仿真,20,cout,sumout,cin,ain,bin,VCS
From: https://www.cnblogs.com/Icer-newer/p/17045210.html

相关文章

  • m基于matlab的IEEE802.15.4家庭网络高效节能的有效接入方法
    1.算法描述我们主要从三个方面进行研究。 第一,需要研究基于IEEE802.15.4的接入算法; 第二,在研究IEEE802.15.4的接入算法之后,研究IEEE802.15.4家庭网络的接入算法; ......
  • m分集2跳OFDM系统中基于功率分配和子载波配对算法的信道容量matlab仿真
    1.算法描述       随着当代无线通信事业的迅猛发展,无线频谱资源已显得越来越匮乏,传统固定静态的无线频谱分配模式和策略,很难为未来的无线通信事业的进一步发展......
  • 2022SWJTU寒假选拔赛1题解
    目录A-马宝の皮颜矩阵I-小幻777J-小幻考考你A-马宝の皮颜矩阵Description给定矩阵\(a[N][M],1\leN·M\le1e5,1\lea[i][j]\le1e5\),求所有相同元素的曼哈顿......
  • 01-逻辑仿真工具VCS使用
    1逻辑仿真工具VCS的使用在书写完成RTL代码之后,确保自己书写的代码和自己想要的逻辑是一致的。VCS是synopsys公司下的的仿真工具。1VCS仿真过程编译-->仿真-->debug/......
  • 自选股 2023年1月11日
    1.603916苏博特2.603477巨星农牧3.603536惠发食品4.300750宁德时代5.300015爱尔眼科6.600251冠农股份7.600206有研新材8.600330天通股份9.002475立讯精密10.00200......
  • 2023-1-11 #26 我仍珍惜 你予我 这一段随时光起舞的情节
    今天dls来雅礼了,于是一行人围着yali转了几圈,去火宫殿吃了一顿!挺开心的。XXOpenCup,GrandPrixofTokyo。142ACookies143BEvacuation144CSumModuloDX......
  • 2022ccpc绵阳站 2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite
    C.​​CatchYouCatchMe​​题目大意:给你n条路径构成一个无向树,结点编号为1~n。在这棵树中,结点1为出口,其他所有结点上都有一只蝴蝶。每一分钟,每只蝴蝶都会沿着一条树的......
  • Markdown语法学习(2023.1.11)
    Markdown语法学习标题+空格+标题名表示一级标题+空格+标题名表示二级标题以此类推,最多有六级标题字体斜体(左右一个*号)粗体(左右两个*号)斜体+粗体(左右三个*号)引......
  • 2022.1.9~2022.1.11 营业日志
    P4563[JXOI2018]守卫zxy讲过。如果直接从代数角度推推不出来,从几何角度会好一点。首先最后一个位置一定要放,放完之后有一些点可以被看到,假设为\(p_{1\simk}\),那么序......
  • vcs仿真vivado独立IP和的方法
    转载:VCS独立仿真VivadoIP核的一些方法总结-知乎(zhihu.com)最近,需要使用VCS仿真一个高速并串转换的Demo,其中需要用到Vivado的SelectIOIP核以及IDELAYCTRL,IDELAY2原语......