I am trying to make a 32x4 (32 words, 4-bit) single port RAM block. Here is my Verilog code:
module RAM_array (input clk, wren, input [4:0] address,
input [3:0] data, output reg [3:0] q);
reg [3:0] mem [31:0]; // a 4 bit wide 32 word RAM block.
always @(posedge clk) begin
if (wren)
mem[address] <= data;
q <= mem[address];
end
endmodule
Since I'm using Altera's Cyclone V chip on a DE-1-SoC, I based my code on their guide here: http://quartushelp.altera.com/14.1/mergedProjects/hdl/vlog/vlog_pro_ram_inferred.htm
Question: Whenever I write a value to an address in the block I have to wait an extra clock cycle for it to get written. Why so?
qoutput to change"? Given how you have written your code, it takes 2 clock cycles for outputqto change. - Matthew Taylorqto reflect the new value on the next cycle. At least Verilog is hardly my forte but I would be surprised if the synthesizer decided to map the logic to a block with different semantics than the code itself. - doynax