• 单双口RAM


    // Quartus II Verilog Template
    // Simple Dual Port RAM with separate read/write addresses and
    // single read/write clock

    module simple_dual_port_ram_single_clock
    #(parameter DATA_WIDTH=8, parameter ADDR_WIDTH=6)
    (
    input [(DATA_WIDTH-1):0] data,
    input [(ADDR_WIDTH-1):0] read_addr, write_addr,
    input we, clk,
    output reg [(DATA_WIDTH-1):0] q
    );

    // Declare the RAM variable
    reg [DATA_WIDTH-1:0] ram[2**ADDR_WIDTH-1:0];

    always @ (posedge clk)
    begin
    // Write
    if (we)
    ram[write_addr] <= data;

    // Read (if read_addr == write_addr, return OLD data). To return
    // NEW data, use = (blocking write) rather than <= (non-blocking write)
    // in the write assignment. NOTE: NEW data may require extra bypass
    // logic around the RAM.
    q <= ram[read_addr];
    end

    endmodule

    // Quartus II Verilog Template
    // True Dual Port RAM with dual clocks

    module true_dual_port_ram_dual_clock
    #(parameter DATA_WIDTH=8, parameter ADDR_WIDTH=6)
    (
    input [(DATA_WIDTH-1):0] data_a, data_b,
    input [(ADDR_WIDTH-1):0] addr_a, addr_b,
    input we_a, we_b, clk_a, clk_b,
    output reg [(DATA_WIDTH-1):0] q_a, q_b
    );

    // Declare the RAM variable
    reg [DATA_WIDTH-1:0] ram[2**ADDR_WIDTH-1:0];

    always @ (posedge clk_a)
    begin
    // Port A
    if (we_a)
    begin
    ram[addr_a] <= data_a;
    q_a <= data_a;
    end
    else
    begin
    q_a <= ram[addr_a];
    end
    end

    always @ (posedge clk_b)
    begin
    // Port B
    if (we_b)
    begin
    ram[addr_b] <= data_b;
    q_b <= data_b;
    end
    else
    begin
    q_b <= ram[addr_b];
    end
    end

    endmodule

    引自:Quartus II 13.1 insert template

  • 相关阅读:
    字典转模型
    iOS开发之---传值大全
    UITableViewCell重用机制
    通知/代理/block 三者比对
    内存的那些事
    C++
    C#接口实现案例
    4.2 C#-----------------------------操作符的重载------------------------------------------
    C#抽象类和抽象方法的实现
    C#----析构函数
  • 原文地址:https://www.cnblogs.com/chengqi521/p/7476796.html
Copyright © 2020-2023  润新知