DRAM and SDRAM Timing

Explain why a DRAM must be refreshed, and schedule its ACTIVATE, READ and PRECHARGE commands in time.

You Will Be Able To

  • Explain the destructive read of a DRAM cell, the restore and the refresh.
  • Describe the row buffer and the split of the address into row and column.
  • Schedule ACTIVATE, READ and PRECHARGE with tRCD, CL and tRP.
  • Tell a page hit from a page miss and count the cycles of each.
Lesson
G8.4
Time
30 min
Runs on
Your browser
Check
5 questions

A frame buffer showed one wrong pixel at the start of every line. The first read of each line opened a new row. The controller sent READ one cycle after ACTIVATE, and the row was not ready.

READ One Cycle After ACTIVATEEach column is one clock cycle. act, rd and pre show the command sent in that cycle.
012345clkactrdpredqtoo early
Scroll horizontally ↔
  1. Cycle 1

    ACTIVATE starts to copy row 1 into the row buffer.

  2. Cycle 2

    READ arrives one cycle later. This memory needs two. The buffer is not ready.

  3. Cycle 4

    The data pins show an unknown value. The reader stores it as the word.

Measured on Icarus Verilog: the example of this lesson as it ships, cycles 1 to 6.

A Cell That Forgets

A DRAM cell is one transistor and one small capacitor. Charge on the capacitor means 1. This cell is much smaller than an SRAM cell, so DRAM holds more bits per chip.

What Happens to the Charge of One CellArrows show where the charge goes. Reading a cell empties it, so every read ends with a write.
  • Storage
  • Power
  • Interconnect
  • Device
  • Data
  • Power
  • Control
What happens to the charge of one cellArrows show where the charge goes. Reading a cell empties it, so every read ends with a write. storage Cell capacitor charge means 1 power Leak charge slowly drains interconnect Bit line a long wire device Sense amplifier one per column storage Refresh counter visits every row inturn read: charge issharedsmall changeall the timeread a row
  1. storage Cell capacitorcharge means 1
    • read: charge is shared → Bit line
    • all the time → Leak
  2. interconnect Bit linea long wire
    • small change → Sense amplifier
  3. device Sense amplifierone per column
  4. power Leakcharge slowly drains
  5. storage Refresh countervisits every row in turn
    • read a row → Sense amplifier
  1. Read

    The word line connects the capacitor to the bit line. The charge spreads over the long wire. The cell has lost its value: the read is destructive.

  2. Sense and restore

    The sense amplifier sees the small change and drives the bit line to a full 0 or 1. That full level flows back into the cell. This is the restore.

  3. Leak

    Even a cell that nobody reads loses charge. After some milliseconds a 1 looks like a 0.

  4. Refresh

    A refresh reads a row only to restore it. A counter steps through all rows, again and again.

Read the diagram as text
  • Cell capacitor: charge means 1
  • Leak: charge slowly drains
  • Bit line: a long wire
  • Sense amplifier: one per column
  • Refresh counter: visits every row in turn
  • Cell capacitor → Bit line: read: charge is shared
  • Bit line → Sense amplifier: small change
  • Cell capacitor → Leak: all the time
  • Refresh counter → Sense amplifier: read a row

Lesson G9.17 builds this cell from a transistor and a capacitor.

Refresh costs time. Every row must be refreshed within the retention time of its cells. So the controller sends a REFRESH command at a steady interval, and an internal counter picks the next row.

After a REFRESH the memory is busy for tRFC and takes no other command. The controller must fit these gaps between the reads.

Row First, Then Column

A DRAM takes its address in two parts on the same pins. First the row, then the column. The row part copies a whole row into the row buffer, which is the set of sense amplifiers.

Two Reads: Row 1 Column 2, Then Row 3 Column 0Each column is one clock cycle. buffer shows whether a row is in the row buffer. The memory has 4 rows of 4 words.
  • Control / FSM
  • Storage
ACTIVATEREADrowdqReadersends commandsCell arraylane01230x00x40x80xcRow bufferone row of 4 words
ACTIVATE→ Cell arrayREAD→ Cell arrayrow→ Row bufferdq→ ReaderReadersends commandsCell arraylane01230x00x40x80xcRow bufferone row of 4 words

A lit row of the array has been copied to the row buffer. The buffer is full while a row is open.

01234567891011clkactrdpreaddr0102030row_at04crow_cells1111buffer0000111100001111dqz12z30
Scroll horizontally ↔
  1. Cycle 1

    ACTIVATE with address 1. The four cells of row 1 are read into the row buffer and restored.

  2. Cycle 3

    READ with address 2. The buffer already holds the row, so the column address only picks one word.

  3. Cycle 5

    The word 12 is on the data pins. PRECHARGE closes the row and prepares the bit lines.

  4. Cycle 7

    ACTIVATE again, now with row 3. The buffer can hold only one row at a time.

  5. Cycle 11

    The word 30 arrives, and the row is closed again.

Measured on Icarus Verilog: the example with its constant fixed, cycles 1 to 12.

Half of the address pins are saved this way. The price is a protocol: the controller must open a row before it reads from it.

Three Waits: tRCD, CL and tRP

An SDRAM is a DRAM with a clock. It takes one command per clock edge. Three commands do most of the work, and each one needs time.

One Read with Its WaitsEach column is one clock cycle. In this model every wait is 2 cycles.
0123456clkactrdpredqz12ztRCD startsCL startstRP starts
Scroll horizontally ↔
  1. Cycle 1

    ACTIVATE. The row needs tRCD cycles to reach the buffer: 2 here.

  2. Cycle 3

    READ, two cycles after ACTIVATE. The word needs CL cycles to reach the pins: 2 here.

  3. Cycle 5

    The word 12 is on dq. PRECHARGE goes out in the same cycle.

  4. Cycle 6

    PRECHARGE needs tRP cycles: 2 here. The next ACTIVATE must wait for them.

Measured on Icarus Verilog: the first read of the fixed example, cycles 1 to 7.

NameFromToIn this model
tRCDACTIVATEthe first READ of that row2 cycles
CLREADthe data on the pins2 cycles
tRPPRECHARGEthe next ACTIVATE2 cycles
tRFCREFRESHthe next commandnone here; 4 cycles in problem G8.4.1

A datasheet gives tRCD, tRP and tRFC in nanoseconds. The controller turns them into whole clock cycles. CL is the CAS latency. The lab model has no REFRESH command.

READ after one cycle

localparam int T_RCD = 1;

Icarus: READ 1 cycle(s) after ACTIVATE: needs 2. Both words come back as xx.

READ after two cycles

localparam int T_RCD = 2;

Icarus: 0 timing violations. The words are 12 and 30.

Page Hits, Misses and Banks

A controller may leave the row open after a read. This is the open-page policy. The next read then falls into one of three cases.

CaseCommandsCycles to the data
Page hit: the same row is openREADCL = 2
No row is openACTIVATE, READtRCD + CL = 4
Page miss: another row is openPRECHARGE, ACTIVATE, READtRP + tRCD + CL = 6

Measured on the model of this lesson: cycles from the first command to the edge that can take the data.

A hit is three times faster than a miss here. Programs that walk through memory in order get many hits.

One row buffer means one open row. So a DRAM is split into banks. Each bank has its own array and its own row buffer.

Two Banks Keep Two Rows OpenArrows show commands from the controller to a bank. The bank number is part of the address.
  • Control / FSM
  • Storage
  • I/O
  • Control
  • Data
Two banks keep two rows openArrows show commands from the controller to a bank. The bank number is part of the address. control Controller picks a bank percommand storage Bank 0 row buffer: row 5 storage Bank 1 row buffer: row 9 io Data pins shared by all banks commandscommandswordword
  1. control Controllerpicks a bank per command
    • commands → Bank 0
    • commands → Bank 1
  2. storage Bank 0row buffer: row 5
    • word → Data pins
  3. io Data pinsshared by all banks
  4. storage Bank 1row buffer: row 9
    • word → Data pins
  1. A hit in bank 0

    Row 5 is open in bank 0. A read of that row needs only READ.

  2. A hit in bank 1

    Row 9 is open in bank 1 at the same time. A read there is a hit too.

  3. A miss in bank 0 only

    A read of row 7 in bank 0 must close row 5 first. Bank 1 keeps row 9 open during all of this.

Read the diagram as text
  • Controller: picks a bank per command
  • Bank 0: row buffer: row 5
  • Bank 1: row buffer: row 9
  • Data pins: shared by all banks
  • Controller → Bank 0: commands
  • Controller → Bank 1: commands
  • Bank 0 → Data pins: word
  • Bank 1 → Data pins: word

A miss in one bank does not close the row of another bank.

Asked in interviews
  1. Why does DRAM need refresh and SRAM does not?

    A DRAM cell stores charge on a capacitor, and the charge leaks. A refresh reads each row and writes it back before the value is lost. An SRAM cell is a pair of inverters that holds its value as long as it has power.

  2. What are tRCD, CL and tRP?

    tRCD is the time from ACTIVATE to the first READ of that row. CL is the number of cycles from READ to the data. tRP is the time from PRECHARGE to the next ACTIVATE.

  3. What is a page hit?

    An access to the row that is already open in the row buffer. It needs only the READ command, so it is the fastest case. A miss must close the old row and open the new one first.

Try It

Each line shows one cycle: the command, its address, whether a row is open, and the data pins. Command 1 is ACTIVATE, 2 is READ and 3 is PRECHARGE.

Line e2 sends ACTIVATE and line e3 already sends READ. The model answers READ 1 cycle(s) after ACTIVATE: needs 2. Line e5 shows dq=xx, and the reader stores it.

Fix the constant T_RCD: it must be 2. Run again. READ moves to line e4, the data 12 shows on line e6, and the run ends with 0 timing violations.

Now try the constant CL at 1 with T_RCD at 2. The reader takes the pins one cycle early and stores zz: nothing drives them yet.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e0 cmd=0 addr=0 open=0 dq=-- e1 cmd=0 addr=0 open=0 dq=-- e2 cmd=1 addr=1 open=0 dq=-- e3 cmd=2 addr=2 open=1 dq=-- DRAM: READ 1 cycle(s) after ACTIVATE: needs 2 e4 cmd=0 addr=0 open=1 dq=-- e5 cmd=3 addr=0 open=1 dq=xx read row 1 col 2: xx e6 cmd=0 addr=0 open=0 dq=-- e7 cmd=1 addr=3 open=0 dq=-- e8 cmd=2 addr=0 open=1 dq=-- DRAM: READ 1 cycle(s) after ACTIVATE: needs 2 e9 cmd=0 addr=0 open=1 dq=-- e10 cmd=3 addr=0 open=1 dq=xx read row 3 col 0: xx 2 timing violations
Read included file: tb.sv
// tb.sv: the bench (read-only). It reads the word at row 1, column 2 and the word at row 3, column 0.
`timescale 1ns/1ps
// sdram4x4: a small SDRAM (a model, read-only). 4 rows of 4 words. Word {row, col} holds the two
// digits row and col: row 1, column 2 holds 12. Commands are taken at the rising clock edge.
//   ACTIVATE row  copies one row into the row buffer. Needs T_RP cycles after a PRECHARGE.
//   READ col      takes one word from the row buffer. Needs T_RCD cycles after the ACTIVATE.
//                 The word is on dq CL cycles after the READ, for one cycle.
//   PRECHARGE     closes the row and gets the bit lines ready for the next ACTIVATE.
module sdram4x4 #(parameter int T_RCD = 2, CL = 2, T_RP = 2) (
  input  logic       clk,
  input  logic [1:0] cmd,       // 0 NOP, 1 ACTIVATE, 2 READ, 3 PRECHARGE
  input  logic [1:0] addr,
  output logic [7:0] dq
);
  logic       open = 1'b0;      // 1: a row is in the row buffer
  logic [1:0] open_row;
  int         since_act = 99, since_pre = 99;   // cycles since the last ACTIVATE and PRECHARGE
  int         violations = 0;
  logic [7:0] pipe [4];         // words on their way to dq
  logic       pipe_v [4];

  initial begin
    dq = 8'hzz;
    for (int i = 0; i < 4; i++) pipe_v[i] = 1'b0;
  end

  always @(posedge clk) begin
    // the data path: a word leaves the pipe CL cycles after its READ
    dq <= pipe_v[CL-2] ? pipe[CL-2] : 8'hzz;
    for (int i = 3; i > 0; i--) begin pipe[i] <= pipe[i-1]; pipe_v[i] <= pipe_v[i-1]; end
    pipe_v[0] <= 1'b0;
    since_act <= since_act + 1;
    since_pre <= since_pre + 1;
    case (cmd)
      2'd1: begin                                   // ACTIVATE
        if (open) begin
          violations++; $display("   DRAM: ACTIVATE while row %0d is open: PRECHARGE first", open_row);
        end else if (since_pre < T_RP) begin
          violations++; $display("   DRAM: ACTIVATE %0d cycle(s) after PRECHARGE: needs %0d", since_pre, T_RP);
        end
        open <= 1'b1; open_row <= addr; since_act <= 1;
      end
      2'd2: begin                                   // READ
        pipe_v[0] <= 1'b1;
        pipe[0]   <= {2'b00, open_row, 2'b00, addr};
        if (!open) begin
          violations++; pipe[0] <= 8'hxx; $display("   DRAM: READ with no open row");
        end else if (since_act < T_RCD) begin
          violations++; pipe[0] <= 8'hxx; $display("   DRAM: READ %0d cycle(s) after ACTIVATE: needs %0d", since_act, T_RCD);
        end
      end
      2'd3: begin open <= 1'b0; since_pre <= 1; end // PRECHARGE
      default: ;
    endcase
  end
endmodule

module tb;
  logic       clk = 0, rst = 0, start = 0;
  logic [1:0] row = 2'd0, col = 2'd0;
  wire  [1:0] cmd, addr;
  wire  [7:0] dq, rdata;
  wire        done;
  int         edge_n = -1;

  always #5 clk = ~clk;                       // a 10 ns clock
  always @(posedge clk) edge_n = edge_n + 1;

  dram_reader dut (.clk(clk), .rst(rst), .start(start), .row(row), .col(col),
                   .cmd(cmd), .addr(addr), .dq(dq), .rdata(rdata), .done(done));
  sdram4x4 ram (.clk(clk), .cmd(cmd), .addr(addr), .dq(dq));

  // One cycle: drive the inputs, show the command of this cycle, then take the edge.
  task automatic tick(input logic do_rst, input logic do_start, input logic [1:0] r, input logic [1:0] c);
    rst = do_rst; start = do_start; row = r; col = c;
    #4;
    if (dq === 8'hzz) $display("e%0d cmd=%0d addr=%0d open=%b dq=--", edge_n + 1, cmd, addr, ram.open);
    else              $display("e%0d cmd=%0d addr=%0d open=%b dq=%h", edge_n + 1, cmd, addr, ram.open, dq);
    @(posedge clk); #1;
  endtask
  task automatic read(input logic [1:0] r, input logic [1:0] c);
    tick(0, 1, r, c);
    while (!done) tick(0, 0, r, c);
    $display("read row %0d col %0d: %h", r, c, rdata);
  endtask

  initial begin
    tick(1, 0, 2'd0, 2'd0);      // edge 0: reset
    read(2'd1, 2'd2);
    read(2'd3, 2'd0);
    $display("%0d timing violations", ram.violations);
    $finish(0);
  end
endmodule

Check Yourself

Spot the bugEach option is a command schedule for the SDRAM model of this lesson. take checks the word on the data pins. Which schedule breaks a rule?
Predict the outputTwo model cells hold a 1 and leak one unit per millisecond. Only cell a is refreshed, and a refresh writes back what it reads. What exact line does the program print after 20 ms?
module tb;
  int charge_a = 8, charge_b = 8;        // two cells that hold a 1
  initial begin
    for (int t = 1; t <= 20; t++) begin
      charge_a--;                        // every cell leaks one unit per millisecond
      charge_b--;
      if (t % 4 == 0) charge_a = (charge_a > 3) ? 8 : 0;   // refresh of cell a every 4 ms: it restores what it reads
    end
    // a cell still reads 1 while it holds more than 3 units
    $display("a=%0d b=%0d", charge_a > 3, charge_b > 3);
  end
endmodule
ConceptWhy is a DRAM read called destructive?
ConceptRow 4 of a bank is open. The next read is for row 6 of the same bank. Which commands does the controller send?
ConceptWhat do banks add to a DRAM?

Common Mistakes

Wrong Send READ in the cycle after ACTIVATE.

The row is not in the buffer yet: the model reports READ 1 cycle(s) after ACTIVATE: needs 2 and returns xx.

Fix Count tRCD cycles from ACTIVATE before the READ.

Before
localparam int T_RCD = 1;
After
localparam int T_RCD = 2;

Wrong Send ACTIVATE for a new row while another row is still open.

The buffer holds one row at a time: the model reports ACTIVATE while row 2 is open: PRECHARGE first.

Fix Send PRECHARGE, wait tRP cycles, and only then ACTIVATE the new row.

Wrong Take the data one cycle after the READ command.

The data appears CL cycles after the READ: taken one cycle early, the lab stores zz.

Fix Count CL cycles from the READ, then store the data pins.

Wrong Leave a DRAM alone for a long time and expect the data to stay.

A cell is a capacitor that leaks: the cell of the model program reads 0 after 20 ms with no refresh.

Fix Refresh every row before its charge is too low. The controller must make time for it.

Remember

  • A DRAM cell is a capacitor: a read empties it, the sense amplifier restores it, and it leaks.
  • Refresh reads every row in turn before its charge is lost.
  • ACTIVATE copies a row into the row buffer. READ picks a column. PRECHARGE closes the row.
  • Wait tRCD before READ, CL for the data and tRP before the next ACTIVATE.
  • A page hit needs only READ. Banks keep several rows open.

Practice

Report a problem with this page