|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
// sram_test.v
module sram_test(clk,reset,write,read,writeaddr,writedata,readaddr,readdata,
sram_oe,sram_ce,sram_lb,sram_we,sram_addr,sram_data);
input clk;
input reset;
input write;
input [17:0] writeaddr;
input [15:0] writedata;
input read;
input [17:0] readaddr;
output [15:0] readdata;
output sram_oe;
output sram_ce;
output sram_lb;
output sram_we;
output [17:0] sram_addr;
inout [15:0] sram_data;
reg sram_oe;
reg sram_ce;
reg sram_lb;
reg sram_we;
reg [17:0] sram_addr;
reg [15:0] readdata;
reg [3:0] presState;
reg [3:0] nextState;
reg [15:0] wdata_reg;
reg [17:0] waddr_reg;
reg [15:0] data_reg0;
reg [17:0] raddr_reg;
parameter stIdle = 4'b0000;
parameter stWrite1 = 4'b0001;
parameter stWrite2 = 4'b0010;
parameter stWrite3 = 4'b0011;
parameter stWrite4 = 4'b0100;
parameter stRead1 = 4'b0101;
parameter stRead2 = 4'b0110;
parameter stRead3 = 4'b0111;
parameter stRead4 = 4'b1000;
always @(posedge clk)
begin
if(!reset)
begin
waddr_reg <= 18'b0;
wdata_reg <= 16'b0;
end
else
begin
if(write)
begin
waddr_reg <= writeaddr;
wdata_reg <= writedata;
end
end
end
always @(posedge clk)
begin
if(!reset)
begin
raddr_reg <= 18'b0;
end
else
begin
if(read)
begin
raddr_reg <= readaddr;
end
end
end
always @(posedge clk)
begin
if(!reset)
begin
presState <= stIdle;
end
else
begin
presState <= nextState;
end
end
always @(*)
begin
case(presState)
stIdle:
begin
if(write == 1'b1)
begin
nextState = stWrite1;
end
else if(read == 1'b1)
begin
nextState = stRead1;
end
else
begin
nextState = stIdle;
end
end
stWrite1:
begin
nextState = stWrite2;
end
stWrite2:
begin
nextState = stWrite3;
end
stWrite3:
begin
nextState = stWrite4;
end
stWrite4:
begin
nextState = stIdle;
end
stRead1:
begin
nextState = stRead2;
end
stRead2:
begin
nextState = stRead3;
end
stRead3:
begin
nextState = stRead4;
end
stRead4:
begin
nextState = stIdle;
end
default:
begin
nextState = stIdle;
end
endcase
end
always @(posedge clk)
begin
if(!reset)
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b1111;
end
else
begin
case(nextState)
stIdle:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b1111;
end
stWrite1:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0110;
end
stWrite2:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0100;
end
stWrite3:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0100;
end
stWrite4:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0110;
end
stRead1:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0110;
end
stRead2:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0010;
end
stRead3:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0010;
end
stRead4:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b0110;
end
default:
begin
{sram_ce,sram_oe,sram_we,sram_lb} <= 4'b1111;
end
endcase
end
end
always @(posedge clk)
begin
if(nextState == stRead3)
begin
readdata <= sram_data;
end
end
always @(posedge clk)
begin
if(nextState == stWrite1)
begin
sram_addr <= waddr_reg;
end
else if(nextState == stRead1)
begin
sram_addr <= raddr_reg;
end
end
always @(posedge clk)
begin
if(nextState == stWrite3)
begin
data_reg0 <= wdata_reg;
end
end
assign sram_data = sram_we ? 16'hzzzz : data_reg0;
endmodule
问题描述:外部再写一个读写信号以及读写地址产生模块,逻辑分析仪引脚接在SRAM的控制引脚上,发现写正常(数据总线上有数据变化),读的时候,地址是变化的,几个控制信号也是变化的,但是总线上的数据始终不变化,这个是怎么回事呢?求高手帮忙。上面的代码,本来读写是分别用3个周期来完成的,后来为了排除问题,又增加了一个读写周期。我用小程序来测试这个SRAM,发现时可以读写的,那个程序用的是嵌套的IF...ELSE语句控制的,而这里采用的是状态机的方式控制。希望大家多发表看法,帮小弟解决下难题。
写操作图
读操作图
|
|