https://open-source-silicon.dev logo
#hardware-beginners
Title
# hardware-beginners
i

Iain Craig

08/14/2020, 9:41 AM
Copy code
module dual_port_ram(clock, read_addr, read_data, write_addr, write_data, write_enable);

  parameter MEM_SIZE = 65535;
  parameter WORD_SIZE = 8;

  input clock, write_enable;
  input [WORD_SIZE-1:0] read_addr, write_addr, write_data;
  output reg [WORD_SIZE-1:0] read_data;
  
  reg [WORD_SIZE-1:0] ram [0:MEM_SIZE];

  always @(posedge clock) begin
    if (write_enable) begin
      ram[write_addr] <= write_data;
    end
  end

  always @(posedge clock) begin
    read_data <= ram[read_addr];
  end
  
endmodule
t

Trevor Clarke

08/14/2020, 1:24 PM
that should work because it's using registers for RAM instead of a RAM primitive. It will not be very space efficient but it should work.
i

Iain Craig

08/14/2020, 1:30 PM
Brilliant, thanks; I was hoping space efficiency would be the trade-off, which I can live with.
3 Views