In reply to dave_59:
Hi Dave,
With Due Respect,
I have coded ram in verilog and used task with nonblocking statement and was getting 1 clock delay.After going through this link,i have used temp variable as you briefed,but that one clock delay is unaffected.Please find below the RAM verilog code:
module ram(clk,rst,wr,addr,data_in,data_out);
//you can change here and the program will work accordingly
parameter ADDR_WIDTH=9; //decide the address bits
parameter DATA_WIDTH=8; //decide the data bits
parameter memory_depth = 1 << ADDR_WIDTH; //by shifting like this,you can create memory of particular size.For eg :- here 2 raised to 10 memory is created i.e 1024 bits.
input [ADDR_WIDTH-1:0]addr; // [9:0] addr
input clk,rst,wr; // 1 bit ports
input [DATA_WIDTH-1:0] data_in; // [63:0] data_in
output reg [DATA_WIDTH-1:0] temp,data_out; //[63:0] data_out
integer i=0;
reg [DATA_WIDTH-1:0] ram[memory_depth-1:0]; //[63:0] ram [1023:0]
always@(posedge clk ,negedge rst)
begin
if (~rst ) //if reset is 0 it will set whole ram with initial predefined value
begin
reset; //reset is called to initialize the value of ram with the default value
temp <= 'd0;
data_out <= 'd0;
end
else
begin
if (wr==1) //if wr == 1 then write task will be called
write(addr,data_in);
else // (wr==0) //if wr == 0 then read task will be called
begin
read(addr,temp);
data_out <= temp;
end
end
end
task write(input [ADDR_WIDTH-1:0] addr,input [DATA_WIDTH-1:0] data_in); // by changing in parameter value of addr and data_in is updated
ram[addr] <= data_in; //passing data_in in particular addr of memory
endtask
// Read Task
task read(input [ADDR_WIDTH-1:0] addr,output [DATA_WIDTH-1:0] temp); //by changing in parameter value of addr and d_out is updated
temp <= ram[addr]; //particular data and this addr is updated in d_out
endtask
//reset task
task reset;
begin
$display(“memory_depth=%0d”,memory_depth);
for(i=0;i<memory_depth-1;i=i+1)
begin
ram[i]=0; //it will allot 0 to all the memory value
end
end
endtask
endmodule
Kindly suggest the solution.
Thanks in advance.