最近在做SRAM方面的测试,本想
FPGA采集数据通过接口传给
单片机进行处理,可是现在fpga控制SRAM读写好像出了些问题。每次fpga刚上电时,先写再读,显示的数是正确的。可是,我把输入的数据调了,换了个数,再写SRAM,读出的数据就不正确了,还是第一次写的数。查了些资料,没有说SRAM写过后还要擦除的,所以可能还是我控制的方法有问题。我用的SRAM 是IS61LV2568,以下是我的程序,主要是参考了DE2
开发板的程序,然后修改了一下。希望各位能帮我看看,到底程序有没有问题,问题在哪?如能回复,十分感谢!
module simple_exram(
input clk,
input wr,
input rd,
input[7:0] adc_data_in,
input[17:0]wr_end_addr,
output MEM_WE_N,
output reg MEM_OE_N,
output[17:0] MEM_A,
inout[7:0] MEM_DATA,
input[17:0] addr_to_read,
output reg[7:0] data_read
);
/*************** extern_ram *****************/
reg[17:0] wr_addr18 = 18'd0;
reg[17:0] rd_addr18 = 18'd0;
//读数据
reg[7:0] Data_out_r = 8'h00;
always @(posedge clk)
begin
if(rd==1'b1)
begin
MEM_OE_N <= 1'b0;
rd_addr18 <= addr_to_read;
Data_out_r <= MEM_DATA;
data_read <= Data_out_r;
end
else
begin
MEM_OE_N <= 1'b1;
rd_addr18 <= 18'd0;
Data_out_r <= 8'h00;
end
end
//写数据
reg flag = 1'b0;
reg we_r = 1'b0;
reg[7:0] bufdata = 8'd0;
reg[17:0] wr_addr18_reg = 18'd0;
always @(posedge clk)
begin
if(wr == 1'b1)
begin
if(wr_addr18 <= wr_end_addr)
begin
if(!flag)
begin
we_r <= 1'b1;
wr_addr18 <= wr_addr18_reg;
wr_addr18_reg <= wr_addr18_reg + 18'd1;
bufdata <= adc_data_in;
flag <= 1'b1;
end
else
begin
we_r <= 1'b0;
wr_addr18 <= wr_addr18;
bufdata <= bufdata;
flag <= 1'b0;
end
end
else
begin
we_r <= 1'b0;
flag <= 1'b0;
wr_addr18 <= wr_addr18;
bufdata <= bufdata;
end
end
else
begin
we_r <= 1'b0;
wr_addr18_reg <=18'd0;
wr_addr18 <= 18'd0;
bufdata <= 8'd0;
flag <= 1'b0;
end
end
assign MEM_A = wr?wr_addr18:rd_addr18;
assign MEM_WE_N = (~we_r)?1'b1:1'b0;
assign MEM_DATA = we_r? bufdata:8'hzz;
endmodule
一周热门 更多>