add ram
This commit is contained in:
24
ram/ram.v
Normal file
24
ram/ram.v
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Ram Sincrona
|
||||
*/
|
||||
|
||||
module ram #(
|
||||
parameter DEPTH = 256, // posiciones
|
||||
parameter W = 16 // bits por posicion
|
||||
) (
|
||||
input clk,
|
||||
input wr_en,
|
||||
input [$clog2(DEPTH)-1:0] addr,
|
||||
input [W-1:0] wr_data,
|
||||
output reg [W-1:0] rd_data
|
||||
);
|
||||
reg [W-1:0] mem [0:DEPTH-1];
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (wr_en)
|
||||
mem[addr] <= wr_data;
|
||||
else
|
||||
rd_data <= mem[addr];
|
||||
end
|
||||
|
||||
endmodule
|
||||
54
ram/ram_tb.v
Normal file
54
ram/ram_tb.v
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Ram Sincrona testbench
|
||||
*/
|
||||
`include "ram/ram.v"
|
||||
|
||||
module ram_tb;
|
||||
reg clk, wr_en;
|
||||
reg [7:0] addr;
|
||||
reg [15:0] wr_data;
|
||||
wire [15:0] rd_data;
|
||||
|
||||
ram ram1(
|
||||
.clk(clk),
|
||||
.wr_en(wr_en),
|
||||
.addr(addr),
|
||||
.wr_data(wr_data),
|
||||
.rd_data(rd_data)
|
||||
);
|
||||
|
||||
initial clk = 0;
|
||||
always #5 clk = ~clk;
|
||||
|
||||
initial begin
|
||||
$dumpfile("ram/ram.vcd");
|
||||
$dumpvars(0, ram_tb);
|
||||
|
||||
wr_en = 0; addr = 0; wr_data = 0;
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
wr_en = 1; addr = 25; wr_data = 256;
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
wr_en = 0;
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
addr = 16;
|
||||
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
@(posedge clk);
|
||||
$display("wr_en=%b, addr=%d, wr_data=%d, rd_data=%d", wr_en, addr, wr_data, rd_data);
|
||||
|
||||
|
||||
$finish;
|
||||
end
|
||||
|
||||
endmodule
|
||||
@@ -351,7 +351,7 @@ gtkwave modulo.vcd
|
||||
- [x] Fase 2.2 — Contador
|
||||
- [x] Fase 2.3 — Shift Register
|
||||
- [x] Fase 2.4 — Register File
|
||||
- [ ] Fase 3.1 — RAM sincrona
|
||||
- [x] Fase 3.1 — RAM sincrona
|
||||
- [ ] Fase 3.2 — ROM
|
||||
- [ ] Fase 3.3 — Stack
|
||||
- [ ] Fase 4.1 — FSM Semaforo
|
||||
|
||||
Reference in New Issue
Block a user