tariq786
Advanced Member level 2
ram with verylog
Hi friends,
I have modeled RAM in verilog. The code is simple see below. I can read and write it without any problem. When i try to access it from the test bench using a new instance, i get xxxxxxxxxxxxxxxxx. Can anyone guide me towards the solution.
Note that i have to access RAM in different module of a larger project and i have to create RAM instances to access RAM.
The one who helps get 50 to 100 points.
timescale 1ns / 1ps
module REGFILE(
output reg [127:0] Rdata,
input [127:0] Wdata,
input clk,
input Read,
input Write
);
reg [127:0] RAM;
always @(posedge clk,Read,Write)
if(Read)
begin
Rdata = RAM;
end
else if (Write)
begin
RAM = Wdata;
end
endmodule
/***********************************************Test Bench ********/
`timescale 1ns / 10ps
module test;
reg clk;
reg Read, Write;
reg Read1, Write2;
reg [127:0] X;
wire [127:0] Y;
wire [127:0] Z;
initial
begin
clk = 0;
X = 128'b0;
end
always
begin
#5 clk = ~clk;
end
initial
#15 Write = 1;
initial
#25 Write = 0; //stop writing
initial
begin #25 Read = 1; Read1 = 1; end
initial
begin #35 Read = 0; Read1 = 0; end
REGFILE u0(.Rdata(Y),
.Wdata(X),
.clk(clk),
.Read(Read),
.Write(Write)
);
REGFILE u1(.Rdata(Z),
.Wdata(X),
.clk(clk),
.Read(Read1),
.Write(Write1)
);
initial
$monitor($time,",X is %h, Y is %h, Z is %h Read is %d, Write is %d \n",X,Y,Z,Read,Write);
endmodule
/**************** Simulation Result **********************************/
# 0,X is 00000000000000000000000000000000, Y is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is x, Write is x
#
# 15,X is 00000000000000000000000000000000, Y is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is x, Write is 1
#
# 25,X is 00000000000000000000000000000000, Y is 00000000000000000000000000000000, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is 1, Write is 0
#
# 35,X is 00000000000000000000000000000000, Y is 00000000000000000000000000000000, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is 0, Write is 0
Hi friends,
I have modeled RAM in verilog. The code is simple see below. I can read and write it without any problem. When i try to access it from the test bench using a new instance, i get xxxxxxxxxxxxxxxxx. Can anyone guide me towards the solution.
Note that i have to access RAM in different module of a larger project and i have to create RAM instances to access RAM.
The one who helps get 50 to 100 points.
timescale 1ns / 1ps
module REGFILE(
output reg [127:0] Rdata,
input [127:0] Wdata,
input clk,
input Read,
input Write
);
reg [127:0] RAM;
always @(posedge clk,Read,Write)
if(Read)
begin
Rdata = RAM;
end
else if (Write)
begin
RAM = Wdata;
end
endmodule
/***********************************************Test Bench ********/
`timescale 1ns / 10ps
module test;
reg clk;
reg Read, Write;
reg Read1, Write2;
reg [127:0] X;
wire [127:0] Y;
wire [127:0] Z;
initial
begin
clk = 0;
X = 128'b0;
end
always
begin
#5 clk = ~clk;
end
initial
#15 Write = 1;
initial
#25 Write = 0; //stop writing
initial
begin #25 Read = 1; Read1 = 1; end
initial
begin #35 Read = 0; Read1 = 0; end
REGFILE u0(.Rdata(Y),
.Wdata(X),
.clk(clk),
.Read(Read),
.Write(Write)
);
REGFILE u1(.Rdata(Z),
.Wdata(X),
.clk(clk),
.Read(Read1),
.Write(Write1)
);
initial
$monitor($time,",X is %h, Y is %h, Z is %h Read is %d, Write is %d \n",X,Y,Z,Read,Write);
endmodule
/**************** Simulation Result **********************************/
# 0,X is 00000000000000000000000000000000, Y is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is x, Write is x
#
# 15,X is 00000000000000000000000000000000, Y is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is x, Write is 1
#
# 25,X is 00000000000000000000000000000000, Y is 00000000000000000000000000000000, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is 1, Write is 0
#
# 35,X is 00000000000000000000000000000000, Y is 00000000000000000000000000000000, Z is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Read is 0, Write is 0