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.
act, rd and pre show the command sent in that cycle.- Cycle 1
ACTIVATE starts to copy row 1 into the row buffer.
- Cycle 2
READ arrives one cycle later. This memory needs two. The buffer is not ready.
- 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.
- Storage
- Power
- Interconnect
- Device
- Data
- Power
- Control
- 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.
- 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.
- Leak
Even a cell that nobody reads loses charge. After some milliseconds a 1 looks like a 0.
- 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.
buffer shows whether a row is in the row buffer. The memory has 4 rows of 4 words.- Control / FSM
- Storage
A lit row of the array has been copied to the row buffer. The buffer is full while a row is open.
- Cycle 1
ACTIVATE with address 1. The four cells of row 1 are read into the row buffer and restored.
- Cycle 3
READ with address 2. The buffer already holds the row, so the column address only picks one word.
- Cycle 5
The word 12 is on the data pins. PRECHARGE closes the row and prepares the bit lines.
- Cycle 7
ACTIVATE again, now with row 3. The buffer can hold only one row at a time.
- 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.
- Cycle 1
ACTIVATE. The row needs tRCD cycles to reach the buffer: 2 here.
- Cycle 3
READ, two cycles after ACTIVATE. The word needs CL cycles to reach the pins: 2 here.
- Cycle 5
The word 12 is on
dq. PRECHARGE goes out in the same cycle. - 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.
| Name | From | To | In this model |
|---|---|---|---|
| tRCD | ACTIVATE | the first READ of that row | 2 cycles |
| CL | READ | the data on the pins | 2 cycles |
| tRP | PRECHARGE | the next ACTIVATE | 2 cycles |
| tRFC | REFRESH | the next command | none 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.
| Case | Commands | Cycles to the data |
|---|---|---|
| Page hit: the same row is open | READ | CL = 2 |
| No row is open | ACTIVATE, READ | tRCD + CL = 4 |
| Page miss: another row is open | PRECHARGE, ACTIVATE, READ | tRP + 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.
- Control / FSM
- Storage
- I/O
- Control
- Data
- A hit in bank 0
Row 5 is open in bank 0. A read of that row needs only READ.
- A hit in bank 1
Row 9 is open in bank 1 at the same time. A read there is a hit too.
- 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
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.
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.
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.
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 violationsRead 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
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.
localparam int T_RCD = 1;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.