Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to transfer a value of an output from DUT to test bench?

Status
Not open for further replies.

ragulto516

Newbie level 2
Joined
May 13, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
17
Hi,

Would like to ask how to transfer a value of an output from DUT to test bench?

I have the following code:

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module my_mod(a, b);
    input a;
    output b;
 
    assign b = a;
  endmodule
 
  module my_mod_tst();
    reg x;
    wire y;
    reg z;
 
    my_mod_tst mmt(x, y);
 
    initial begin
      x = 1;
      z = y;
 
      if (z == 1)
        display$("Value of z is %d", z);
    end
  endmodule



But it does not work.
 
Last edited by a moderator:

It will help others and probably yourself if you explain what "does not work" means. What happens? What did you expect to happen? Look at the log file carefully.
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
You have not instantiated ur RTL in the first place. Check out the syntax for instantiating...
 

Hi,

Yes, apologies, I have instantiated the module incorrectly and here is the rewrite.

Code:
module my_mod(a, b);
  input a;
  output b;
 
  assign b = a;
endmodule
 
module my_mod_tst();
  reg x;
  wire y;
  reg z;
 
  my_mod mm(x, y);
 
  initial begin
    x = 1;
    z = y;
 
    if (z == 1)
      $display("Value of z is %d", z);
  end
endmodule

But after running it in simulator the test bench variable z becomes equal to 1'bx. Is there a way how to transfer the value from module under test to test bench correctly? Thanks.
 

The statement z=y and the display statement should be in always blocks and not in the initial block.
 

This is a simulation race condition. You are writing variable x and reading wire y with no delay in between. The initial block and continuous assignment are two independent processes, and without any delays or wait statements in the initial block, there is no guarantee that the continuous assignment in my_mod will execute in between the write and the read. Different version of Modelsim/Questa produce different results.

Generally, you write to your DUT inputs at one time, and read your DUT outputs at another time.

Code:
module my_mod(input a, output b); // preferred way to write your ports
    assign b = a;
 endmodule

  module my_mod_tst();
    reg x;
    wire y;
    reg z;

    my_mod mmt(x, y);

    initial begin
      x = 1;
      @y // or #1
      z = y;
      if (z == 1)
        $display("Value of z is %d", z);
    end
  endmodule
In most cases, you have a clock and can apply stimulus on a clock edge with a non-blocking assignment, and read the stimulus from the previous clock cycle at the same time
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top