4237 views|3 replies

1

Posts

0

Resources
The OP
 

How to write a testbench for a 19-bit counter in verilog hdl? [Copy link]



modulecounter(inclk,rst_n,en,out);

input inclk,rst_n,en;

output[18:0] out;

reg[18:0] out,value_r;

always @(posedge inclk ornegedge rst_n)

  if(~rst_n) value_r<=19'b0;

  else

  if(en)

    begin

    value_r<=value_r+19'h1;

    end

  else

  if(!en)

   begin

   out<=value_r;

   value_r<=0;  

   end

initial value_r<=0;
endmodule
以上为该计数器的源程序。
谢谢。
自己尝试了好多遍编写testbench,总是有问题。


This post is from FPGA/CPLD

Latest reply

Agree with the above  Details Published on 2018-5-12 11:23
 

1

Posts

0

Resources
2
 
Eliminate zero replies and wait for the master to explain. Xiaobai doesn't understand~
This post is from FPGA/CPLD
 
 

3

Posts

0

Resources
3
 
  1. module        tb_count();
  2. reg        inclk;
  3. reg        rst_n;
  4. reg        en;
  5. wire[18:0] out;
  6. initial
  7.         begin
  8.                 inclk  = 0        ;
  9.                 rst_n <= 0        ;
  10.                 en    <= 0        ;
  11.                 #50
  12.                 rst_n <= 1        ;
  13.         end
  14. always #5        inclk = ~inclk        ;
  15. always #100        en    <= ~en        ;
  16. counter        counter_inst(
  17.         .inclk        (inclk         ),
  18.         .rst_n        (rst_n         ),
  19.         .en        (en         ),
  20.         .out     (out     )
  21.         );
  22.        
  23. endmodule
复制代码
This post is from FPGA/CPLD
 
 
 

10

Posts

1

Resources
4
 
Agree with the above
This post is from FPGA/CPLD
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list