Lesson 24 +40 XP

Memory Unit: RAM Organisation, Decoding & Expansion

Memory Unit: RAM Organisation, Decoding & Expansion

A memory unit is a large collection of storage cells with the circuits needed to move a word in or out. Random-access memory (RAM) can be written and read, and any word takes the same time to reach wherever it is (hence random access). This lesson describes the memory unit from the outside (its lines and operations), from the inside (cells, decoders, coincident selection), and shows how to build a large memory from small chips: the classic numerical question.

1. The Memory Unit

Memory unit block diagramMemory unit block diagram

A memory of 2k words, each of n bits, has:

  • k address lines selecting one word,
  • n data input and n data output lines (often one shared bidirectional data bus),
  • control lines: Read and Write (often one line, R/W'), plus a chip select / memory enable.

Capacity is stated as words × bits per word (e.g. 1K × 16) or in bytes (1K × 16 = 2048 bytes). Recall 1K = 210, 1M = 220, 1G = 230.

SolvedExample 1 · Address and data lines

Find the number of address lines, data lines and the capacity in bytes for (a) 1K × 16, (b) 64K × 8, (c) a 4 GB byte-addressable memory.

  1. (a) 1K = 210: 10 address lines, 16 data lines, 1024 × 2 = 2048 bytes.
  2. (b) 64K = 216: 16 address lines (addresses 0000 to FFFF in hex), 8 data lines, 65,536 bytes.
  3. (c) 4G = 232 bytes, one byte per address: 32 address lines, 8 data lines.
Answer(a) 10 and 16, 2 KB; (b) 16 and 8, 64 KB; (c) 32 and 8

2. Read and Write Operations

Write (store a word):

  1. Put the binary address on the address lines.
  2. Put the data bits on the data input lines.
  3. Activate the Write input (with chip select).

Read (fetch a word):

  1. Put the binary address on the address lines.
  2. Activate the Read input; after the access time the word appears on the output lines. Reading does not change the stored word.
EnableR/W'Operation
0Xnone (outputs disconnected, high impedance)
10write the selected word
11read the selected word

Write and read cyclesWrite and read cycles

The access time is the time from a valid address to valid output data; the cycle time is the minimum time between the starts of two successive operations.

3. Inside a RAM

Each bit is stored in a binary cell (BC): a latch with gates that let it be selected, written and read. A 2k × n RAM is a 2k-by-n grid of cells. A k × 2k decoder selects one row (word); a column of n OR gates collects the selected word's bits for reading.

Internal organisation of a 4 × 4 RAMInternal organisation of a 4 × 4 RAM

Coincident (two-dimensional) decoding

A single decoder for a large memory is enormous: 1K words need a 10 × 1024 decoder with 1024 AND gates of 10 inputs. Coincident decoding splits the address into two halves that drive an X (row) decoder and a Y (column) decoder; a cell is selected where an active row meets an active column.

Coincident decoding of a 1K memoryCoincident decoding of a 1K memory

SolvedExample 2 · Decoder savings with 2D selection

Compare the decoder outputs needed for (a) a 1K-word memory and (b) a 4K-word memory using one decoder and using coincident decoding.

  1. (a) Linear: 210 = 1024 outputs. 2D: two 5 × 32 decoders, 32 + 32 = 64 outputs.
  2. (b) Linear: 212 = 4096 outputs. 2D: two 6 × 64 decoders, 64 + 64 = 128 outputs.
Answer1024 vs 64, and 4096 vs 128; 2D decoding grows as 2 · 2k/2 instead of 2k

4. Static and Dynamic RAM

SRAMDRAM
Cella latch (about 6 transistors)one transistor + one capacitor
Holds dataas long as power is onfor a few milliseconds; must be refreshed
Density, cost per bitlow density, expensivehigh density, cheap
Speedfastslower
Typical usecache memorymain memory

Both are volatile: data is lost when power is removed (unlike ROM and flash).

A DRAM chip saves pins by address multiplexing: the row half of the address is sent first and latched by RAS (row address strobe), then the column half on the same pins with CAS (column address strobe).

SolvedExample 3 · DRAM pins and refresh rate

A 1M × 1 DRAM has 1024 rows and every row must be refreshed every 16 ms. (a) How many address pins does it need with multiplexing? (b) How often must a row refresh happen?

  1. (a) 1M = 220: 20 address bits, sent as 10 row bits then 10 column bits: 10 pins (plus RAS and CAS).
  2. (b) 1024 rows in 16 ms: one row every 16 / 1024 = 0.0156 ms = 15.6 µs.
Answer10 multiplexed address pins; refresh one row every 15.6 µs

5. Memory Expansion

Large memories are built from smaller chips in two directions:

  • Word-length (width) expansion: chips side by side share the address and chip select; each supplies some of the bits. Two 256 × 4 chips make 256 × 8.
  • Capacity (depth) expansion: rows of chips share the low address bits; the high address bits go to a decoder whose outputs drive the chip-select inputs, so exactly one row responds.
chips = frac{total words}{words per chip} × frac{total bits}{bits per chip}

1K × 8 memory from eight 256 × 4 chips1K × 8 memory from eight 256 × 4 chips

SolvedExample 4 · 1K × 8 from 256 × 4 chips

Build a 1K × 8 memory from 256 × 4 RAM chips. How many chips, what decoder, and what is the address map?

  1. Chips: (1024 / 256) × (8 / 4) = 4 × 2 = 8.
  2. Address lines: 10 in total (A9 dots A0). Each chip uses 8 (A7 dots A0).
  3. The remaining 2 lines (A9 A8) go to a 2 × 4 decoder, one output per row of chips.
A9 A8Row selectedAddress range (hex)
00row 0000 to 0FF
01row 1100 to 1FF
10row 2200 to 2FF
11row 3300 to 3FF
Answer8 chips in 4 rows of 2, a 2 × 4 decoder on A9 A8
SolvedExample 5 · 64K × 16 from 16K × 8 chips

How many 16K × 8 chips are needed for a 64K × 16 memory? How many address lines go to each chip and to the decoder?

  1. Chips: (64K / 16K) × (16 / 8) = 4 × 2 = 8.
  2. Total address lines: 64K = 216, so 16.
  3. Each chip: 16K = 214, so 14 lines (A13 dots A0).
  4. Decoder: 16 - 14 = 2 lines, a 2 × 4 decoder for the 4 rows.
Answer8 chips; 14 address lines to every chip, 2 to a 2 × 4 decoder
SolvedExample 6 · A 2 MB memory from 128K × 8 chips

How many 128K × 8 chips make a 2 MB byte-addressable memory, and how large is the decoder?

  1. Chips: 2M / 128K = 221 / 217 = 16 (one chip per row, since both are 8 bits wide).
  2. Address lines: 21 in total, 17 to each chip, 21 - 17 = 4 to the decoder.
Answer16 chips and a 4 × 16 decoder

6. RAM and Memory Expansion in Verilog

A memory is declared as an array of registers: reg [3:0] mem [0:15] is 16 words of 4 bits. Writing is synchronous; reading here is combinational, with a high-impedance output (4'bz) when the chip is not selected, so several chips can share one data bus. The top module builds a 32 × 8 memory from four 16 × 4 chips, using A4 to select a row:

VERILOG
// A 16 x 4 RAM chip, and a 32 x 8 memory built from four of them
module ram16x4 (
    input        clk,
    input        cs,            // chip select
    input        we,            // 1 = write, 0 = read
    input  [3:0] addr,
    input  [3:0] din,
    output [3:0] dout
);
    reg [3:0] mem [0:15];
    integer i;

    initial begin
        for (i = 0; i < 16; i = i + 1)
            mem[i] = 4'b0000;
    end

    always @(posedge clk) begin
        if (cs && we)
            mem[addr] <= din;               // synchronous write
    end

    assign dout = (cs && !we) ? mem[addr] : 4'bz;   // tri-state output when not selected
endmodule

module mem32x8 (
    input        clk,
    input        we,
    input  [4:0] addr,
    input  [7:0] din,
    output [7:0] dout
);
    wire row0 = ~addr[4], row1 = addr[4];   // 1-to-2 decoder on the top address bit

    // each row: two chips side by side give 8-bit words (high nibble, low nibble)
    ram16x4 c0h (.clk(clk), .cs(row0), .we(we), .addr(addr[3:0]), .din(din[7:4]), .dout(dout[7:4]));
    ram16x4 c0l (.clk(clk), .cs(row0), .we(we), .addr(addr[3:0]), .din(din[3:0]), .dout(dout[3:0]));
    ram16x4 c1h (.clk(clk), .cs(row1), .we(we), .addr(addr[3:0]), .din(din[7:4]), .dout(dout[7:4]));
    ram16x4 c1l (.clk(clk), .cs(row1), .we(we), .addr(addr[3:0]), .din(din[3:0]), .dout(dout[3:0]));
endmodule

module tb;
    reg clk = 0, we = 0;
    reg [4:0] addr;
    reg [7:0] din;
    wire [7:0] dout;

    mem32x8 m (.clk(clk), .we(we), .addr(addr), .din(din), .dout(dout));

    task write(input [4:0] a, input [7:0] d);
        begin
            addr = a;
            din = d;
            we = 1;
            #5 clk = 1;
            #5 clk = 0;
            we = 0;
            $display("write %h to address %0d (chip row %0d)", d, a, a[4]);
        end
    endtask

    task read(input [4:0] a);
        begin
            addr = a;
            #1 $display("read  address %0d -> %h", a, dout);
        end
    endtask

    initial begin
        write(5'd3, 8'hA7);
        write(5'd19, 8'h3C);
        read(5'd3);
        read(5'd19);
        read(5'd4);
    end
endmodule

Address 3 lands in the first row of chips and address 19 in the second; address 4 was never written:

OUTPUT
write a7 to address 3 (chip row 0)
write 3c to address 19 (chip row 1)
read  address 3 -> a7
read  address 19 -> 3c
read  address 4 -> 00
💡 Tip

Key points to remember

  • 2k × n memory: k address lines, n data lines; 1K = 210.
  • Write: address, data, Write. Read: address, Read, wait the access time.
  • Coincident decoding: X and Y decoders, 2 · 2k/2 outputs instead of 2k.
  • SRAM = latch, fast, cache; DRAM = capacitor, dense, needs refresh, main memory.
  • Chips = (words ratio) × (bits ratio); the extra high address bits drive a decoder for chip select.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. Draw the block diagram of a memory unit and explain the read and write operations. (5 Marks)
  • Q2. Explain the internal construction of a 4 × 4 RAM with a binary cell. (10 Marks)
  • Write: the binary cell (latch, select, read/write gates), the 2 × 4 decoder, the 4 × 4 grid, the output OR gates.
  • Q3. What is coincident decoding? How many decoder outputs does a 4K memory need with and without it? (5 Marks)
  • Q4. Design a 1K × 8 memory using 256 × 4 RAM chips. Draw the diagram and the address map. (10 Marks)
  • Q5. Compare SRAM and DRAM. Why does DRAM need refreshing? (5 Marks)