How to declare bidirectional bus in verilog testbench?

Status
Not open for further replies.

thaolam

Newbie level 1
Joined
Aug 4, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
18
Hi,

I am creating testbench for SRAM.

When WREN_N=0 && BFRD=0 && OE=0, SRAM will do write operation with input Data is D[7:0].

When WREN_N=1 && BFRD=1 && OE=1, SRAM will do read operation with output Data is D[7:0].

WREN_N: write enable pin, active at low
BFRD: read enable pin, active at high
OE: output enable, active at high, using is read mode.

I am declaring D as the following (referring the similar threads):

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
23
24
25
26
27
28
29
30
31
32
module s65fh_sp528x8x8_test ;
        supply0 gnd_1;
        supply1 vdd;
        wire [7:0] D;
        reg [0:9] BA;
        reg BFRD, RY_EN, SLOWRD_EN, POR_N, OE, WREN_N;
        reg clk;
        integer i=0;
        reg [0:23] ivector,temp;
        reg [0:23] wvector[0:528] ;
        reg [0:23] rvector[0:528] ;
 
s65fh_sp528x8x8 s65fh_sp528x8x8 (.BFRD(BFRD),.WREN_N(WREN_N),.RY_EN(RY_EN),.SLOWRD_EN(SLOWRD_EN),.OE(OE),.POR_N(POR_N),.D(D),.BA(BA),.gnd_1(gnd_1),.vdd(vdd));
initial begin
        wvector[0] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000000,10'b0000000000};
        wvector[1] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000001,10'b1000000000};
        wvector[2] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000010,10'b0100000000};
        wvector[3] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000011,10'b1100000000};
        wvector[4] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000100,10'b0010000000};
        wvector[5] = {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,8'b00000101,10'b1010000000};
        ....
end
 
always@(posedge clk)
 temp=ivector;
 
//bidirectional data
 
        assign D=(OE == 0 && WREN_N == 0 && BFRD == 0) ? temp[6:13] : 8'bz ;
....
end
endmodule



However, I am getting failed in result. By reviewing waveform and netlist, I am seeing that the D, node after D input buffer for write, and node before D output buffer for read have the same logic. I wonder my declaration of bidirectional D is right or not? Please help.
 
Last edited by a moderator:

Maybe we could help you if you had posted the testbench and the code so we could take a look.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…