Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17253 Discussions

how to read data from inout port into a testbench

Altera_Forum
Honored Contributor II
3,288 Views

Hi, I'm writing a test bench to write data into an sram module. I have to write the data and read back from it. data is inout port in that module. How do I read the data back from the module into my test bench? This is my code... 

 

`timescale 1 ns/10 ps 

 

 

module ht6116_tb(); 

 

 

reg [7:0] data_set; 

wire [7:0] data; 

reg [10:0] address; 

reg write_enable_n, read_enable_n, chip_select_n, reset; 

 

 

IDT6116SA15 M1(.IO(data), .A(address), .WE_N(write_enable_n), .OE_N(read_enable_n), .CS_N(chip_select_n), .RESET(reset)); 

 

 

assign data = data_set; 

 

 

initial 

begin 

reset = 1'b0; 

address = 11'h0; 

write_enable_n = 1'h1; 

read_enable_n = 1'h1; 

chip_select_n = 1'h0; 

 

# 100; 

data_set = 8'h55; 

write_enable_n = 1'h0;# 100; 

write_enable_n = 1'h1; 

data_set = 8'hzz;# 100; 

read_enable_n = 1'h0; 

 

# 100; 

 

 

end
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
1,788 Views

`timescale 1 ns/10 ps module ht6116_tb(); reg data_set; reg read_data; // Somewhere to store the data in your test bench wire data; reg address; reg write_enable_n, read_enable_n, chip_select_n, reset; IDT6116SA15 M1(.IO(data), .A(address), .WE_N(write_enable_n), .OE_N(read_enable_n), .CS_N(chip_select_n), .RESET(reset)); assign data = data_set; initial begin reset = 1'b0; address = 11'h0; write_enable_n = 1'h1; read_enable_n = 1'h1; chip_select_n = 1'h0; read_data = 8'h00; // You might want to provision your reg but you don't have to. # 100; data_set = 8'h55; write_enable_n = 1'h0; # 100; write_enable_n = 1'h1; data_set = 8'hzz; # 100; read_enable_n = 1'h0; # 50; read_data = data; // Read the data in (e.g. half way through your read enable pulse, but can be anywhere whilst read enable is active) # 50; read_enable_n = 1'h1; # 100; end 

Cheers, 

Alex
0 Kudos
Altera_Forum
Honored Contributor II
1,788 Views

Well you could create a bidir controller. Search this forum for bidir (short for bidirectional) and you will find some references. You can also directly write Z when you read and write the value when you write.

0 Kudos
Altera_Forum
Honored Contributor II
1,788 Views

Hey Thanks!!

0 Kudos
Reply