G
Greg Quintana
Guest
I am trying to implement a small memory in verilog. My code is as
follows:
module memory(addr_in, data_in, data_out, we, clk);
parameter data_width = 8;
parameter addr_width = 3;
input [addr_width - 1:0] addr_in;
input [data_width - 1:0] data_in;
input we;
input clk;
output reg [data_width - 1:0] data_out;
reg [data_width - 1:0] memory_block [0:addr_width - 1]; // declare
memory
always@(posedge clk)
begin
if (we)
memory_block[addr_in] = data_in;
else
data_out = memory_block [addr_in];
end
endmodule
there is no CE because the memory is always enabled. Unfortunately
this memory does not work. Can someone suggest a fix or a similar
working memory?
Thanks
GregQ
follows:
module memory(addr_in, data_in, data_out, we, clk);
parameter data_width = 8;
parameter addr_width = 3;
input [addr_width - 1:0] addr_in;
input [data_width - 1:0] data_in;
input we;
input clk;
output reg [data_width - 1:0] data_out;
reg [data_width - 1:0] memory_block [0:addr_width - 1]; // declare
memory
always@(posedge clk)
begin
if (we)
memory_block[addr_in] = data_in;
else
data_out = memory_block [addr_in];
end
endmodule
there is no CE because the memory is always enabled. Unfortunately
this memory does not work. Can someone suggest a fix or a similar
working memory?
Thanks
GregQ