Vivado 双口RAM 的调用和实现

1、双口RAM例程

例程1,Altera官方例程,采用寄存器构建双口RAM

moduletrue_dpram_sclk

(

    input [7:0] data_a, data_b,

    input [5:0] addr_a, addr_b,

    input we_a, we_b, clk,

    outputreg [7:0] q_a, q_b

);

    // Declare the RAM variable

    reg [7:0] ram[63:0];

    // Port A

    always @ (posedge clk)

    begin

        if (we_a)

        begin

            ram[addr_a] <= data_a;

            q_a <= data_a;

        end

        else

        begin

            q_a <= ram[addr_a];

        end

    end

    // Port B

    always @ (posedge clk)

    begin

        if (we_b)

        begin

            ram[addr_b] <= data_b;

            q_b <= data_b;

        end

        else

        begin

            q_b <= ram[addr_b];

        end

    end

endmodule

例程2,Xilinx官方例程,采用寄存器构建真双口RAM

// Dual-Port Block RAM with Two Write Ports

// File: rams_16.v

modulev_rams_16 (
        clka,
        clkb,
        ena,
        enb,
        wea,
        web,
        addra,
        addrb,
        dia,
        dib,
        doa,
        dob
);

input clka,clkb,ena,enb,wea,web;

input [9:0] addra,addrb;

input [15:0] dia,dib;

output [15:0] doa,dob;

reg[15:0] ram [1023:0];

reg[15:0] doa,dob;

always @(posedge clka) 
begin if (ena)
    begin

if (wea)

ram[addra] <= dia;

doa <= ram[addra];

end

end

always @(posedge clkb) beginif (enb)

begin

if (web)

ram[addrb] <= dib;

dob <= ram[addrb];

end

end

endmodule

    例程3,该例程是网友博客中的例程[],代码如下:

moduleTOP(

input USER_CLK

)

`define DLY #1

reg FPGA_Enable=0;

reg[3:0] FPGA_Write_Enable=4'h0;

reg[31:0] FPGA_Address=0;

reg[31:0] FPGA_Write_Data=0;

reg[31:0] FPGA_Read_Data_reg=0;

wire[31:0] FPGA_Read_Data;

reg[10:0] count=0;

always @ (posedge USER_CLK)

begin

 

count <= count +1;

 

if(count<=100)

 

begin

 

FPGA_Enable <=0;

 

FPGA_Write_Enable <=4'h0;

 

end

 

elseif((count <=105)&&(count >100))

 

begin

 

FPGA_Enable <=1;

 

FPGA_Write_Enable <=4'hf;

 

FPGA_Address <= FPGA_Address +4;

 

FPGA_Write_Data <= FPGA_Write_Data +1;

 

end

 

elseif((count <=110)&&(count >105))

 

begin

 

FPGA_Enable <=0;

 

FPGA_Write_Enable <=4'h0;

 

FPGA_Address <=0;

 

FPGA_Write_Data <=0;

 

end

 

elseif((count <=117)&&(count >110))

 

begin

 

FPGA_Enable <=1;

 

FPGA_Write_Enable <=4'h0;

 

FPGA_Read_Data_reg <= FPGA_Read_Data;

 

FPGA_Address <= FPGA_Address +4;

 

end

 

elseif(count ==118)

 

begin

 

FPGA_Enable <=0;

 

count <= count;

 

 

 

end

 

end

 

 

 

BBBByour_instance_name (

 

.clka(USER_CLK), // input clka

 

.ena(FPGA_Enable), // input ena

 

.wea(FPGA_Write_Enable), // input [3 : 0] wea

 

.addra(FPGA_Address), // input [31 : 0] addra

 

.dina(FPGA_Write_Data), // input [31 : 0] dina

 

.douta(FPGA_Read_Data), // output [31 : 0] douta

 

 

 

 

 

.clkb(clkb), // input clkb

 

.enb(enb), // input enb

 

.web(web), // input [3 : 0] web

 

.addrb(addrb), // input [31 : 0] addrb

 

.dinb(dinb), // input [31 : 0] dinb

 

.doutb(doutb) // output [31 : 0] doutb

 

);

 

endmodule

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖人称纪博大

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值