1. Verilog RAM - Single Port Async Design

A Single Port RAM has one bidirectional data port that can either read or write. This design uses two control signals: wr_en (write enable) and o_en (output enable). Only one signal should be active at a time.

Features

  • Parameterized: Configurable WIDTH, DEPTH, and ADDR
  • Asynchronous: No clock required
  • Bidirectional data port: Uses tristate for read/write
  • Reset: Clears all memory locations to zero

Port Description

PortDirectionDescription
datainoutBidirectional data bus [WIDTH-1:0]
addrinputAddress bus [ADDR-1:0]
resetinputAsynchronous reset (active high)
wr_eninputWrite enable
o_eninputOutput enable (read)

RTL Implementation

// Module: sp_ram.v
// Parameterized Single Port Asynchronous RAM

module sp_ram #(
  parameter WIDTH = 8,
  parameter DEPTH = 16,
  parameter ADDR  = 4
)(
  inout  [WIDTH-1:0] data,
  input  [ADDR-1:0]  addr,
  input              reset,
  input              wr_en,
  input              o_en
);

  // Memory array
  reg [WIDTH-1:0] mem [DEPTH-1:0];
  integer i;

  // Read Operation (active when o_en=1, wr_en=0)
  assign data = (o_en && !wr_en) ? mem[addr] : {WIDTH{1'bz}};

  // Write Operation
  always @(reset, data, addr, wr_en, o_en) begin
    if (reset) begin
      // Clear all memory on reset
      for (i = 0; i < DEPTH; i = i + 1)
        mem[i] = 0;
    end
    else if (wr_en && !o_en) begin
      // Write data to addressed location
      mem[addr] = data;
    end
  end

endmodule

Operation Modes

wr_eno_enOperation
00Idle (data = Hi-Z)
01Read from mem[addr]
10Write to mem[addr]
11Invalid (avoid)

Next: Continue to Part 2 - Single Port Testbench

Author
Mayur Kubavat
VLSI Design and Verification Engineer sharing knowledge about SystemVerilog, UVM, and hardware verification methodologies.

Comments (0)

Leave a Comment