双口ram读写数据一直不成功

[复制链接]
811|10
 楼主| kangzj 发表于 2019-2-15 11:14 | 显示全部楼层 |阅读模式
双口ram读写数据一直不成功
zwll 发表于 2019-2-15 11:17 | 显示全部楼层

源代码
 楼主| kangzj 发表于 2019-2-15 11:20 | 显示全部楼层


parameter idle=2'b00;

parameter write_state=2'b01;

parameter read_state=2'b10;
reg [1:0]current_state;

reg [1:0]next_state;

reg [1:0]cnt;

reg [9:0]init_cnt;

always@(posedge clk or negedge rst_n)

begin

if(!rst_n)

current_state<=idle;

else

current_state<=next_state;

end
always@(*)

begin

case(current_state)

  idle:begin

    if(init_cnt==10'd1023)

     next_state=write_state;

   else

   next_state<=idle;

   end

  write_state:begin

   if((addr==17'h1fffe)&(cnt==2'b11))

    next_state<=read_state;

   else

    next_state<=write_state;

  end

  read_state:begin

   if((addr==17'h1fffe)&(cnt==2'b11))

    next_state<=idle;

   else

    next_state<=read_state;

  end

  default:

   next_state<=idle;

    endcase

end


always@(posedge clk or negedge rst_n)begin

if(!rst_n)begin

addr<=17'h0;

oe<=1'b1;

wr<=1'b1;

cnt<=2'b0;

init_cnt<=10'h0;

end

else begin

case(current_state)

idle:begin

    addr<=17'h0;

    oe<=1'b1;

    wr<=1'b1;

  ce<=1'b1;

    write_data<=8'h0;

    read_data<=8'h0;

  if(init_cnt==10'd1023)

    init_cnt<=10'd1023;

    else

   init_cnt<=init_cnt+1;

    end  

  write_state:begin

   cnt<=cnt+1;

   ce<=1'b0;

   if(cnt==2'b00)begin

    wr<=1'b0;

   end

   else if(cnt==2'b01)begin

    wr<=1'b1;

   end

   else if(cnt==2'b10)begin

    ce<=1'b1;

   end

   else if(cnt==2'b11)begin

       if(addr==17'h1fffe)begin

    addr<=17'h0;

    cnt<=2'b0;

    write_data<=8'h0;

    end

    else begin

      addr<=addr+1;

    write_data<=8'h5a;//write_data+1;

    ce<=1'b0;

      cnt<=2'b0;

    end

   end

   end

   read_state:begin

    cnt<=cnt+1;

    wr<=1'b1;

    if(cnt==2'b00)begin

    ce<=1'b0;

   end

   else if(cnt==2'b01)begin

    oe<=1'b0;

   end

   else if(cnt==2'b10)begin

    read_data<=dpram_data;

    oe<=1'b1;

   end

   else if(cnt==2'b11)begin

          if(addr==17'h1fffe)begin

    addr<=17'h0;

    cnt<=2'b0;

    end      

   else begin

    addr<=addr+1;

     //addr<=17'h0;

    ce<=1'b1;

    cnt<=2'b00;

   end

   end

  end

default:begin  

          addr<=17'h0;

        oe<=1'b1;

    ce<=1'b1;

        wr<=1'b1;

        end

       endcase

      end

     end

assign dpram_ce=ce;

assign dpram_oe=oe;

assign dpram_wr=wr;

assign dpram_addr=addr;

assign dpram_data=(~wr)?write_data:8'hzzzz;
chuxh 发表于 2019-2-15 11:23 | 显示全部楼层
仿真图也一并发上来吧
juventus9554 发表于 2019-2-15 11:27 | 显示全部楼层
顺序是?
 楼主| kangzj 发表于 2019-2-15 11:31 | 显示全部楼层
图的顺序是读操作和写操作
 楼主| kangzj 发表于 2019-2-15 11:35 | 显示全部楼层

已经好用了 :P
stly 发表于 2019-2-15 11:38 | 显示全部楼层

怎么解决的啊  
 楼主| kangzj 发表于 2019-2-15 11:41 | 显示全部楼层
芯片有个sem端口,需要把它置高,我们硬件的把它浮空了,上拉后就好了
juventus9554 发表于 2019-2-15 11:45 | 显示全部楼层
 楼主| kangzj 发表于 2019-2-15 11:50 | 显示全部楼层
哈哈,结贴了哈
您需要登录后才可以回帖 登录 | 注册

本版积分规则

672

主题

7007

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部