打印

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

[复制链接]
1436|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
kangzj|  楼主 | 2017-9-3 21:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
双口ram读写数据一直不成功
沙发
zwll| | 2017-9-3 21:57 | 只看该作者
源代码

使用特权

评论回复
板凳
kangzj|  楼主 | 2017-9-3 21:59 | 只看该作者


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| | 2017-9-3 22:01 | 只看该作者
仿真图也一并发上来吧

使用特权

评论回复
5
juventus9554| | 2017-9-3 22:04 | 只看该作者
顺序是?

使用特权

评论回复
6
kangzj|  楼主 | 2017-9-3 22:06 | 只看该作者
图的顺序是读操作和写操作

使用特权

评论回复
7
kangzj|  楼主 | 2017-9-3 22:08 | 只看该作者
已经好用了 :P

使用特权

评论回复
8
stly| | 2017-9-3 22:10 | 只看该作者
怎么解决的啊  

使用特权

评论回复
9
kangzj|  楼主 | 2017-9-3 22:11 | 只看该作者

芯片有个sem端口,需要把它置高,我们硬件的把它浮空了,上拉后就好了

使用特权

评论回复
10
juventus9554| | 2017-9-3 22:13 | 只看该作者
聪明

使用特权

评论回复
11
kangzj|  楼主 | 2017-9-9 14:15 | 只看该作者
哈哈,结贴了哈

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

672

主题

7007

帖子

2

粉丝