24小时热门版块排行榜    

Znn3bq.jpeg
查看: 786  |  回复: 3

lss1776

新虫 (初入文坛)

[求助] 用Verilog 写的SDRAM控制器实现读写功能,没出现像,求帮忙看看,多谢。

module sdram_0 (
// input
                                        reset,
                                        clk,
                                        in_data,
//full,empty,
// out
                  addr,
                  bank,//???????????????????????????????????????
                  cas,
                  cke,
                  cs,
                  dq,// yu za_data qu bie ??????????????????
                  dqm,
                  ras,
                  out_data,
                  we,
      
                  );
   
   //  duan kou sheng ming
input reset,clk;
input [40:0]in_data;//addr [37:16] data[15:0]

output  [11:0] addr;
reg [11:0] addr;
output reg [1:0] bank;
output  cas,cke,cs,ras,we;
wire cas,cke,cs,ras,we;
assign cke=1'b1;
wire  [3:0] cmd;
assign{cs,ras,cas,we}=cmd;
assign  cmd=init_done?m_cmd:i_cmd;
inout [15:0] dq;
wire [15:0] dq;
output [1:0] dqm;
wire [1:0] dqm;
assign dqm=2'b00;
output reg [15:0] out_data;
reg init_done;
// ji shu ji cun qi sheng ming
reg [15:0]NOP_counter; //200 us and  8 us auto refresh

// kong zhi ji cun qi ;

reg ref_req;

reg [3:0] i_cmd;
reg [11:0] i_addr;
reg [2:0] counter;
reg [2:0] i_state;
reg [2:0] i_next;
reg r;
reg [99:0]rr;
reg start;



always @ (posedge clk or negedge reset )
begin
if(reset==0)
begin
NOP_counter<=19200;
ref_req<=0;
rr<=0;
start<=1;
end
else
begin
if(NOP_counter==1)
begin   ;NOP_counter<=800;if(rr==0) begin rr<=rr+1; start<=1; end else  start<=0;end
else begin NOP_counter<=NOP_counter-1; end
ref_req <= ((NOP_counter == 1) | ref_req) & ~act_ref_req & init_done;
end

end

always@(posedge clk or  negedge reset )
begin
if(reset==0)
begin
i_addr<={12{1'b1}};
counter<=0;
i_state<=3'b000;
i_next<=3'b000;
r<=0;
end
else
if(!init_done && (start==0))
case(i_state)
// qu xiao xin pian
3'b000:
begin  i_cmd<=4'b1111;i_state<=3'b001;end
// precharge
3'b001: begin  i_cmd<=4'b0010;i_state<=3'b011;i_next<=3'b010;end
//auto_charge

3'b010:begin i_cmd<=4'b0001;i_state<=3'b011;counter<=3;
if(r<1)  begin  i_next<=2; r<=r+1;end
else    i_next<=7;
end

//NOP
3'b011:begin i_cmd<=4'b0111;  if(counter > 1) counter<=counter-1; else i_state<=i_next;  end

//
3'b101:begin i_state<=3'b101; end

// mo shi she ding
3'b111:begin i_cmd<=4'b0000; i_state<=3'b011; i_next<=3'b101; counter<=4;i_addr={12{1'b0}}; end
default :i_state<=3'b000;
endcase
end

always @(posedge clk or negedge reset)
begin
if(reset==0)
init_done<=0;
else
if(i_state==5)  init_done<=1;
end




// work state


//        3      22      16
assign {m_wor,m_bus_addr,m_data}=in_data;

wire [2:0]  m_wor;       // read or write signal

wire  wr ;

assign wr={m_wor[0]};

wire [21:0] m_bus_addr;  // addr bus
assign m_bank={m_bus_addr[21],m_bus_addr[8]};///////********************** you wen ti
wire [11:0] m_addr;       // addr

wire [15:0] m_data;       // data

wire [1:0] m_bank;



reg [2:0]m_count;
reg [3:0] m_state;
reg [3:0] m_next;

reg [3:0] m_cmd;
reg oe;
reg act_ref_req;   // 1 active
assign dq=oe? m_data:16'bzzzz;

always @(posedge clk )
begin
if(reset==0)
begin
m_state<=0;
m_next<=0;
oe<=0;
m_count<=0;
act_ref_req<=0;
end
else

case(m_state)
// idle
0:    if(init_done)
begin
               if(ref_req==1)
                         begin   m_state<=6; end
               else
                     begin  
                      m_state<=1;
                      end
end
// row active
1:
  begin
m_state<=2;m_cmd<=4'b0011;  oe <= 1'b0;bank<=m_bank;addr<=m_bus_addr[20:9]; m_next<=wr?3:4; m_count<=2;//*********************** tRC
end

//NOP
2:begin   oe <= 1'b0;act_ref_req<=0;if (m_next == 7)
                      m_cmd <= {{1{1'b0}},3'h7};
                  else
                    m_cmd <= {{{1'b0}},3'h7};
                       if (m_count > 1)
                      m_count <= m_count - 1'b1;
                  else
                    m_state <= m_next;
              end

//read
3:begin  m_cmd <= {{{1'b0}},3'h5}; oe <= 1'b0;
                if (ref_req)
                        begin
                          m_state <= 6;
                        
                        end
                      else
                        begin
                          addr <= {4'b0100,m_bus_addr[7:0]};
                          out_data <= dq;
                           m_state <=2;
                           m_next<=1;
                           m_count<=2;
                          end
end
//write
4:begin   m_cmd <= {{{1'b0}},3'h4};
                  
                  if (ref_req)
                        begin
                          m_state <= 6;
                        
                        end
                      else
                        begin
                          addr <={4'b0100,m_bus_addr[7:0]};
                           m_state <=2;
                           m_next<=1;
                           oe <= 1'b1;
                          end
end

//ref
6:begin    oe <= 1'b0;      m_state <= 7; //*********************************************tRP
                  addr <= {12{1'b1}};//              
                  // precharge all if arf, else precharge csn_decode
                  if (ref_req)
                      m_cmd <= {{1{1'b0}},3'h2};
                  else
                    m_cmd <= {{{1'b0}},3'h2};
end
// ref_act
7:begin
                  act_ref_req <= 1'b1;
                  m_state <= 2;
                  m_cmd <= {{1{1'b0}},3'h1};
                  m_count <= 3;
                  m_next <= 0;
                  end


              
              default: begin
                  m_state <= m_state;
                  m_cmd <= 4'b1111;
                  oe <= 1'b0;
              end // default
endcase



end
endmodule
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhy910827

铜虫 (小有名气)

多半是刷新的问题,你再算算刷新间隔

发自小木虫Android客户端
2楼2016-06-05 09:12:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jbb0523

至尊木虫 (著名写手)

我不去想是否能够成功,既然选择了远方便只顾风雨兼程……
3楼2016-06-06 20:28:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lss1776

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by jbb0523 at 2016-06-06 20:28:35
硬件好着没

硬件没问题

发自小木虫Android客户端
4楼2016-06-06 21:37:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 lss1776 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 300求调剂 +8 橙a777 2026-04-15 8/400 2026-04-16 01:25 by L0alice
[考研] 初试324 中药学 一志愿天中医 求调剂 +3 李的Lucky 2026-04-10 3/150 2026-04-15 23:54 by 陈皮皮
[考研] 271求调剂 +32 2261744733 2026-04-11 33/1650 2026-04-15 22:03 by noqvsozv
[考研] 297,工科调剂? +3 河南农业大学-能 2026-04-14 3/150 2026-04-15 22:02 by noqvsozv
[考研] 284求调剂 +21 让我上岸吧阿西 2026-04-09 21/1050 2026-04-15 21:53 by noqvsozv
[考研] 求助调剂,跨调 +19 X十甫寸Y 2026-04-11 20/1000 2026-04-15 21:18 by cuisz
[考博] 26年电池方向博士申请 10+3 15615939259 2026-04-09 4/200 2026-04-15 14:22 by kwansei
[考研] 310求调剂 +16 666真好 2026-04-11 18/900 2026-04-15 13:28 by 黑科技矿业
[考研] 药学305求调剂 +7 玛卡巴卡boom 2026-04-11 7/350 2026-04-15 13:21 by 西北望—风沙
[考研] 272分材料子求调剂 +41 Loy0361 2026-04-10 54/2700 2026-04-14 18:00 by lhj2009
[考研] 求调剂 +12 何气正 2026-04-13 13/650 2026-04-14 14:47 by zs92450
[考研] 0856专硕求调剂 希望是a区院校 +24 好好休息好不好 2026-04-09 27/1350 2026-04-13 22:22 by pies112
[考研] 生物学调剂,一志愿西南大学348,Top期刊一区二作、二区三作,三等奖学金三次 +5 candyyyi 2026-04-09 5/250 2026-04-13 09:02 by 可淡不可忘
[考研] 求调剂288 +7 ioodiiij 2026-04-10 9/450 2026-04-13 08:33 by Hayaay
[考研] 本科南方医科大学 一志愿985 药学学硕284分 求调剂 +5 弱水听文 2026-04-09 5/250 2026-04-12 13:16 by shengxi123
[考研] 280求调剂 +13 wzzz王 2026-04-09 13/650 2026-04-12 00:31 by 勇攀高峰0126
[考研] 22408调剂315分 +3 zhuangyan123 2026-04-09 3/150 2026-04-12 00:25 by 蓝云思雨
[考研] 化工调剂求导师收留!一志愿失利,踏实肯干,有植物提取科研经历 +20 yzyzx 2026-04-09 21/1050 2026-04-12 00:12 by 小小小小啦啦啦
[考研] 087100初试311求调剂 +4 任雅琴 2026-04-09 4/200 2026-04-11 10:33 by zhq0425
[考研] 301求调剂 +5 149. 2026-04-10 5/250 2026-04-10 15:45 by 柴小白
信息提示
请填处理意见