RAM Memory

De la WikiLabs
Jump to navigationJump to search

Random Access Memory are memory circuits. The difference between these and the ROM memories is that RAMs can also write, not just read. Thus, besides the important parameters we know from ROM (the number of memory locations and the size of a location), a RAM can have one or more ports. These ports consist of multiple inputs and /or outputs, and can be of three types:

  • write port - this port can only write to memory;
  • read port - read only memory from this port;
  • read-write port - this port can also write and read, but only at the same address.

The read ports can also be of two types:

  • asynchronous - if the data output changes asynchronously with changing the read address, and this output is wire type;
  • synchronous - if the data output changes synchronously with the clock, regardless of the time of the change of address, and this output is reg.

The more memory a memory has, the higher (as area) and the slower it is. It is therefore recommended that a designer takes into account the functionality required for a memory and adds exactly the number and type of ports that are needed. For example, two read ports will not be added unless it is essential to read two memory locations at the same time.

Note: Each distinct port must have its own address entry.

Interface of a RAM

The interface of a RAM contains the clock signal as an input. In addition, each port has the following signals:

  • Read ports contain (as with a ROM where read only):
    • location address as input
    • data read from memory as output
  • Writing ports contain:
    • Destination address as input
    • date to be written, also as entry
    • A one-bit input signal commanding the input date write to the specified address, called the Write Enable (or we).
  • read-write ports contain:
    • address of the location to be accessed (read or written) as input
    • date to be written, also as entry
    • data read from memory as output
    • A one-bit input signal commanding the input date write to the specified address, called the Write Enable (or we).

Outputs can be either wire type, for asynchronous ports, or reg for synchronous ports.

Warning: A RAM does not have a reset signal!

Implementing a RAM

The memory cells of a RAM are defined as a register vector. Thus, a RAM of 1024 32-bit locations is defined inside the Verilog module as follows:

reg [31: 0] memory [0: 1023];

This syntax expresses a vector of 1024 elements (0-1023), which elements are 32-bit registers (31-0). Access to one of the registers in the 1024 registers vector is done using the operator []. For example, the register specified by an addr is accessed as follows:

memory[addr]
Rule: Always write a memory location is synchronous (on the clock front), so it is done using a block always sequentially.
Rule: Always, reading a memory location on a synchronous port is always done using a block always sequential.
Rule: Always read a memory location on an asynchronous port using an assign or always combinatorial block (assign is recommended).