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


沒有留言:

張貼留言

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...