写了一个SRAM的读写控制器,verilog编写的,由于板子上没有现成的验证电路我现在的验证想法是这样:用串口发送数据到开发板,用一个串口接收模块接收后,
写入到SRAM,然后立刻将写入的数据从刚才的地址读出来
读出来的数据放到LED中显示。
目前这个模块写完了我也下载了运行,结果测试非常顺利——就是太顺利了我都怀疑我的数据根本没有通过SRAM,二是直接到了LED中。现在又点晕,有达人有空帮我看看这个状态机是否正确么?
代码如下:
module SRAM(A,D,SRAM_CE,SRAM_OE,SRAM_WE,BHE,BLE,DOUT,DIN,clk);
input clk;
input [7:0] DIN;//串口接收后的数据,8位
output SRAM_CE,SRAM_OE,SRAM_WE,BHE,BLE;//SRAM的控制接口
output [7:0] DOUT;//输出到LED的8位数据
inout [15:8] D;//16位地址线的高8位
output [17:0] A;//18位数据线
reg oe,we,bhe,ble;
reg start;
reg [2:0] state;
reg [7:0] outbuf,inbuf1,inbuf2;
reg [15:8] dbuf;
reg [17:0] abuf;
parameter idle=3'b000, write1=3'b001, write2=3'b011,
read1=3'b100, read2=3'b110;
assign SRAM_CE = 0;
assign SRAM_WE = we;
assign SRAM_OE = oe;
assign BHE = bhe;
assign BLE = ble;
assign DOUT = outbuf;
assign A[17:0] = abuf[17:0];
assign D[15:8] = dbuf[15:8];
always @(posedge clk)
begin
inbuf1 <=DIN;
inbuf2 <=inbuf1;
end
always @(posedge clk)
begin
case(state)
idle:
begin
if(inbuf2!=inbuf1)
begin
start <=1;
bhe <=1;
ble <=1;
we <=0;
oe <=1;
state <=write1;
end
else
begin
start <=0;
bhe <=1;
ble <=1;
we <=1;
oe <=1;
state <=idle;
end
end
write1:
if(start)
begin
abuf <=abuf+18'b1;
bhe <=0;//高8位允许
state <=write2;
end
write2:
begin
dbuf[15:8]<=inbuf2;
bhe <=1;
we <=1;
state <=read1;
end
read1:
begin
oe <=0;
bhe <=0
state <=read2;
end
read2:
begin
outbuf[7:0]<=D[15:8];
state <=idle;
end
endcase
end
当写完这个帖子的时候我发现了代码肯定有问题,因为我烧录程序的时候bhe置的是1而 ble是0,也就是说反过来了,输出的是低8位,但是数据依然正确,所以这个代码肯定有问题,没有经过SRAM
有人能帮我看看哪里有问题吗?或者有更好的验证方法? |