在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 4746|回复: 7

[求助] 新手求助,可赋初值4位加法器,写了testbench,好像一直没有运行里面的initial

[复制链接]
发表于 2013-10-8 10:58:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 NJAlvin 于 2013-10-8 14:53 编辑

Waveform

Waveform
我写了一个test bench来测试一个4-bit 加法器。 加法器里有一个输出使能控制信号,该信号为低时可输出技术,否则输出Z。在test bench里已经对该使能信号做了控制,可是波形里始终是无效的。求大神帮忙啊!感激不尽!

testbench代码





  1. `timescale 1ns / 100ps
  2. module count16_tb  ;


  3.   reg    oe_1   ;
  4.   reg    load_1   ;
  5.   reg    rst_1   ;
  6.   reg    clk   ;
  7.   reg   [3:0] cnt_in   ;
  8.   reg    enable_1   ;
  9.   
  10.   //Outputs from the Device Under Test are wire type
  11.   wire  [3:0]  count   ;
  12.   wire  [3:0]  count_tri   ;
  13.   
  14.   
  15.   
  16.   //Initial blocks are sequenctial and start at time 0
  17.   initial
  18.   begin
  19.     $display($time,"<<Starting the simulation>>");
  20.     clk=1'b0;
  21.     rst_1=1'b0;
  22.     load_1=1'b1;
  23.     enable_1=1'b1;
  24.     cnt_in=4'b0;
  25.     oe_1=1'b0;
  26.     #20 rst_1=1'b1;
  27.     $display($time,"<<Coming out of reset>>");
  28.    
  29.     @(negedge clk);
  30.     //load passed initial value to the counter.
  31.     load_counter(4'hA);
  32.     @(negedge clk);
  33.    
  34.     $display($time,"<<Turning ON the count enable>>");
  35.     enable_1<=1'b0;
  36.    
  37.     wait(count==4'b0001);
  38.     $display($time,"<<count=%d-Turning OFF the count enable>>",count);
  39.     enable_1=1'b1;
  40.     #40;
  41.     $display($time,"<<Turning OFF the OE>>");
  42.     oe_1=1'b1;
  43.    
  44.     #20;
  45.     $display($time,"<<Simulation Complete>>");
  46.     $stop;
  47.         
  48.    
  49.   end
  50.   
  51.   
  52.   
  53.   
  54.   
  55.   //Instantiate the Device Under Test
  56.   count16  
  57.    DUT  (
  58.        .oe_1 (oe_1 ) ,
  59.       .load_1 (load_1 ) ,
  60.       .rst_1 (rst_1 ) ,
  61.       .count (count ) ,
  62.       .clk (clk ) ,
  63.       .cnt_in (cnt_in ) ,
  64.       .enable_1 (enable_1 ) ,
  65.       .count_tri (count_tri ) );
  66.   //Create a 50Mhz clock.
  67.   always

  68.   #10 clk=~clk;
  69.   
  70.   
  71.   


  72.   //The load_count task loads the counter with the value passed.
  73.   task load_counter;
  74.   input [3:0] load_value;
  75.   begin
  76.     @(negedge clk);
  77.     load_1<=1'b0;
  78.     cnt_in=load_value;
  79.     @(negedge clk);
  80.     load_1=1'b1;
  81.   end
  82. endtask
  83. endmodule



复制代码



下面是计数器的代码






  1. `timescale 1ns/100ps
  2. module count16(count,count_tri,clk,rst_1,load_1,enable_1,cnt_in,oe_1);
  3. output [3:0] count;
  4. output [3:0]count_tri;//tri_state buffers
  5. input clk;
  6. input rst_1;
  7. input load_1;
  8. input enable_1;
  9. input [3:0] cnt_in;
  10. input oe_1;

  11. reg [3:0] count;         
  12. assign count_tri=(!oe_1) ? count : 4'bZZZZ;

  13. always @ (posedge clk or negedge rst_1)
  14. begin

  15.   if(!rst_1)
  16.   begin
  17.     count<=#1 4'b0000;
  18.   end                                          
  19.   else if(!load_1)                                           begin         count<=#1 4'b1010;
  20.   end                                       
  21.   else if(!enable_1) //enable_1 is the enable signal of counting.
  22.   begin
  23.     count<=#1 count+1;
  24.   end                                       
  25. end

  26. endmodule
  27.          
  28.   
  29.          



复制代码


 楼主| 发表于 2013-10-8 16:18:36 | 显示全部楼层
为什么单步调试就可以正常,直接run all就不行呢?
发表于 2013-10-8 16:44:02 | 显示全部楼层
波形的最小精度可以放大些,现在才1000ps,也就半个clk,怎么看
clk都没显现出来
也可以看看printf信息
发表于 2013-10-8 16:46:44 | 显示全部楼层
确定你testbench中的 $stop这个函数的时间位置是正确的嘛,在我用VCS仿真的时候,执行./simv时,vcs告诉我仿真停止在 $stop这一行,你可以查一下你的仿真时间的长度是否够。我是注释掉 $stop这个函数仿真可以看到波形,没有问题。
发表于 2013-10-8 20:26:07 | 显示全部楼层
先把 oe_1 = 1 注释掉,再看看
发表于 2013-10-8 20:32:48 | 显示全部楼层
是不是仿真时间太短。。。。clk才刚到第一个上升沿
 楼主| 发表于 2013-10-12 13:24:07 | 显示全部楼层
回复 3# bruce_hz


   确实是波形精度的问题,其实已经正常仿真了,只是我的时间范围没有调好,谢谢你!也谢谢各位高手的回答。
发表于 2014-7-30 21:16:15 | 显示全部楼层
不错
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-19 17:59 , Processed in 0.023002 second(s), 11 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表