//
// Initializing Block RAM from external data file
//
module v_rams_20c (clk, we, addr, din, dout);
input clk;
input we;
input [4:0] addr;
input [15:0] din;
output [15:0] dout;
reg [15:0] ram [0:31];
reg [15:0] dout;
initial begin
$readmemh("rams_20c.data",ram, 0, 31);
end
always @(posedge clk) begin
if (we)
ram[addr] <= din;
dout <= ram[addr];
end
endmodule
AABB
CCDD
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
reg [15:0] ram [0:31];
(* RAM_STYLE="BLOCK" *) reg [15:0] ram [0:31];
//
// Initializing Block RAM from external data file
//
module v_rams_20c (clk, we, addr, din, dout);
input clk;
input [1:0] we;
input [4:0] addr;
input [15:0] din;
output [15:0] dout;
(* RAM_STYLE="BLOCK" *) reg [15:0] ram [0:31];
// reg [15:0] ram [0:31];
reg [15:0] dout;
initial begin
$readmemh("rams_20c.data",ram, 0, 31);
end
always @(posedge clk) begin
dout <= ram[addr];
if (we[0])
ram[addr][7:0] <= din[7:0];
if (we[1])
ram[addr][15:8] <= din[15:8];
end
endmodule
//
// Initializing Block RAM from external data file
//
module v_rams_20c (clk, we, addr, din, dout);
parameter DATA_WIDTH = 16;
parameter ADDR_WIDTH = 5;
input wire [DATA_WIDTH-1:0] din;
input wire [ADDR_WIDTH-1:0] addr;
input wire [1:0] we;
input wire clk;
output reg [DATA_WIDTH-1:0] dout;
wire ram_ena;
assign ram_ena = 1'b1;
(* RAM_STYLE="BLOCK" *) reg [DATA_WIDTH-1:0] ram [2**ADDR_WIDTH-1:0];
reg [(DATA_WIDTH/2)-1:0] di0, di1;
// The following code is only necessary if you wish to initialize the RAM
// contents via an external file (use $readmemb for binary data)
initial
$readmemh("rams_20c.data", ram, 0, 31);
always @(we, din) begin
if (we[0])
di0 = din[(DATA_WIDTH/2)-1:0];
else
di0 = ram[addr][(DATA_WIDTH/2)-1:0];
if (we[1])
di1 = din[DATA_WIDTH-1:DATA_WIDTH/2];
else
di1 = ram[addr][DATA_WIDTH-1:DATA_WIDTH/2];
end
always @(posedge clk)
if (ram_ena) begin
dout <= {di1,di0};
ram[addr] <= {di1,di0};
end
endmodule
Spartan-3 SLICEM
Spartan-3E SLICEM
Spartan-3A Block RAM
Virtex-4 Block RAM
Virtex-5 Block RAM
Spartan-6 Block RAM
Virtex-6 Block RAM
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |