2014年6月7日 星期六

Memory

RAM: 
源自於
 http://blog.csdn.net/chevroletss/article/details/6305397
Syntax
reg [wordsize:0] array_name [0:arraysize]
E.G. reg [7:0] my_memory [0:255];space.gif
Here [7:0] is the memory width and [0:255] is the memory depth with the following parameters:
  • Width : 8 bits, little endian
  • Depth : 256, address 0 corresponds to location 0 in the array.
Storing Data:
my_memory [address] = Data_in;
Reading Data:
Data_out = my_memory [address];
Initializing Memories
$readmemh("file_name",mem_array,start_addr,stop_addr);
Note : start_addr and stop_addr are optional.
module  memory();
reg [7:0] my_memory [0:255];

initial begin
 $readmemh("memory.list", my_memory);
end
endmodule


Following is the Verilog code for a single port RAM with asynchronous read.


module raminfr (clk, we, a, di, do);  
input clk;
input we;
input [4:0] a;
input [3:0] di;
output [3:0] do;
reg [3:0] ram [31:0];

always @(posedge clk) begin
if (we)
ram[a] = di;
end
assign do = ram[a];
endmodule


Following is the Verilog code for a single port RAM with "false" synchronous read.


module raminfr (clk, we, a, di, do);
input clk;
input we;
input [4:0] a;
input [3:0] di;
output [3:0] do;
reg [3:0] ram [31:0];
reg [3:0] do;

always @(posedge clk) begin
if (we)
ram[a] = di;
do = ram[a];
end

endmodule


The following descriptions, featuring an additional reset of the RAM output, are also only mappable onto Distributed RAM with an additional resetable buffer on the data output as shown in the following figure:


module raminfr (clk, we, rst, a, di, do);
input clk;  
input we;  
input rst; 
input  [4:0] a;  
input  [3:0] di;  
output [3:0] do;  
reg    [3:0] ram [31:0];  
reg    [3:0] do;


  always @(posedge clk) begin  
    if (we)  
      ram[a] = di;  
    if (rst)  
      do = 4'b0;  
    else  
      do = ram[a];  
  end  
endmodule


Following is the Verilog code for a single-port RAM with synchronous read (read through).

module raminfr (clk, we, a, di, do);


input clk;  
input we;  
input  [4:0] a;  
input  [3:0] di;  
output [3:0] do;  
reg    [3:0] ram [31:0];  
reg    [4:0] read_a;


  always @(posedge clk) begin  
    if (we)  
      ram[a] = di;  
    read_a = a;  
  end  
  assign do = ram[read_a];  
endmodule


沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...