DRAM in One Picture
DRAM holds the most bits for the money, because one bit is one tiny charge. The charge leaks, and everything else about DRAM follows from that.
You Will Be Able To
- Describe a DRAM cell, and say why it is much smaller than an SRAM cell.
- Explain why a read must be followed by a write back, and why every row needs a refresh.
- Work out how long a row may wait for its refresh, and what a late refresh does.
- Lesson
- S3.14
- Time
- 22 min
- Runs on
- Your browser
- Check
- 6 questions
A phone holds four gigabytes of working memory. Suppose the chip stopped tending that memory. The content would start to fade within a fraction of a second, with the power still on.
Before You Start
You need S3.1: the six kinds of memory, and that an SRAM bit is a loop of transistors.
You also need the idea of a capacitor: a part that holds an electric charge for a while.
| Question | |
|---|---|
| 1 | How does a DRAM cell hold a bit, and why is it so small? |
| 2 | What does a read do to a cell, and what must follow it? |
| 3 | Why must a DRAM be refreshed? |
| 4 | What happens when a refresh comes too late? |
| 5 | Why does DRAM sit in chips of its own, behind a controller? |
The Idea: A Bit That Is Only a Charge
An SRAM bit is a loop of transistors that drives its own value. So it holds for as long as the power is on. It needs six transistors. A DRAM bit is far simpler: one capacitor and one switch. A charge on the capacitor means 1. No charge means 0.
That cell is tiny, and so DRAM packs ten to twenty times more bits into the same area. It is the only way to give a phone gigabytes of memory. The price comes in two parts.
First, a read destroys what it reads. The charge of one cell is so small that reading it empties it. So every read is followed at once by a write back of the same value. The chip does this by itself.
Second, the charge leaks. A full cell slowly empties, even when nobody touches it. After some milliseconds, a 1 can no longer be told from a 0. So the chip must visit every row in time, read it and write it back. That visit is called a refresh, and it never stops.
A memory that must be visited on a schedule cannot simply sit on a bus. It needs a controller that keeps the schedule and fits the reads of the processor in between.
New Words
| Word | Meaning |
|---|---|
| Capacitor | A part that holds an electric charge. A small one holds little charge, and loses it within milliseconds. |
| Cell of a memory | The circuit that holds one bit. A DRAM cell is one capacitor and one switch. |
| Row of a memory | The cells that one row line opens together. A read or a refresh always handles a whole row. |
| Bit line | The wire that connects all cells of one column to the edge of the memory. |
| Sense amplifier | A circuit at the end of a bit line. It turns a tiny change of voltage into a clear 1 or 0. |
| Sense level | The charge that a cell needs for a 1 to be read as a 1. |
| Destructive read | A read that empties the cell it reads. The value must be written back. |
| Refresh | To read a row and write the same values back, at full charge. |
| Refresh interval | The longest time a row may wait between two refreshes. |
| DRAM controller | The logic that sends reads, writes and refreshes to a DRAM, each at its proper time. |
One Picture: The Cell and Its Refresh
- Control / FSM
- Bus
- Memory
- Processor
- One cell
A bit is a charge on a capacitor, behind one switch. A full capacitor is a 1, and an empty one is a 0. That is the whole cell.
- A read empties it
The row line opens the switch. The charge runs out onto the bit line, which is far larger than the capacitor. The cell is now empty.
- The sense amplifier decides, and writes back
The bit line changed by a tiny amount. The sense amplifier decides 1 or 0 from that, and writes a full value back into the cell.
- The charge leaks
Even with the switch closed, the charge slowly leaks away. After some milliseconds a 1 looks like a 0.
- The refresh
So every row is read and written back before that happens, again and again, for as long as the power is on.
Read the diagram as text
- Row line: opens every switch of one row
- Switch: one transistor
- Capacitor: charge means 1, no charge means 0
- Bit line: a long wire shared by one column
- Sense amplifier: decides 1 or 0, and writes it back
- DRAM controller: refreshes every row in turn
- Row line → Switch: open
- Switch → Capacitor: closed: the charge stays
- Switch → Bit line: open: the charge runs out
- Bit line → Sense amplifier: a small change
- Sense amplifier → Capacitor: written back, full
- DRAM controller → Row line: one row at a time
One cell of a DRAM and what keeps it alive. A real chip has billions of cells.
The Smallest Example, Worked by Hand
One cell, in a model with small numbers. A 1 is written as a charge of 8. One unit leaks away in each tick. A read sees a 1 when the charge is 4 or more: that is the sense level.
| Tick | Charge | Read as | A refresh now would write back |
|---|---|---|---|
| 0 | 8 | 1 | 1, at charge 8 |
| 1 | 7 | 1 | 1 |
| 2 | 6 | 1 | 1 |
| 3 | 5 | 1 | 1 |
| 4 | 4 | 1 | 1: the last safe tick |
| 5 | 3 | 0 | 0: the bit is lost |
The charge may fall from 8 to 4, which takes 4 ticks. So the refresh interval of this cell is 4 ticks.
Look at the last row. At tick 5 the cell reads as 0. A refresh at that moment does not help. It reads 0 and writes 0 back, at full strength. From then on the wrong value is perfectly stable.
A cell that holds a 0 has no charge to lose. In this model it stays at 0 for ever, so only the 1s are in danger.
The Rules
Rule 1: A DRAM bit is a charge on a capacitor, behind one switch.
The cell is tiny, so DRAM holds many times more bits than SRAM in the same area.
Rule 2: A read empties the cell.
So the chip writes the value back at once, after every read.
Rule 3: The charge leaks, with the power on.
A 1 that is left alone turns into a 0.
Rule 4: A refresh reads a row and writes it back.
Every row must get one before any of its 1s falls below the sense level.
Rule 5: A late refresh makes the error permanent.
It reads the wrong value and writes that back at full charge.
Rule 6: The refresh schedule belongs to a controller.
A row that is being refreshed cannot serve a read, so the controller fits both in.
Sources for These Rules
The textbook "Computer Organization and Design" by Patterson and Hennessy, section 5.2, "DRAM Technology". It gives one transistor for each bit and a charge that must be refreshed. A refresh reads a row and writes it back.
The textbook "Digital Design and Computer Architecture" by Harris and Harris, section 5.5.2. It gives the cell of one transistor and one capacitor, the read that destroys the content, and a refresh every few milliseconds.
The textbook "CMOS VLSI Design" by Weste and Harris, section 12.3: the cell, the bit line and the sense amplifier. It also gives the special manufacturing process that makes DRAM 10 to 20 times denser than SRAM.
The charge of 8, the leak of one unit in each tick and the sense level of 4 are numbers of our model. A real cell leaks unevenly, faster when it is hot, and its refresh interval is some milliseconds.
Our reference library holds no DRAM standard. This page states no command, no timing value and no refresh interval of a real part.
Now Run It
The lab at the end of this page is test code. It models one row of four cells, each as a number for its charge. It writes 1011 into the row, and then lets time pass.
t=0 write 1011 | charge 8 0 8 8 | reads as 1011
t=3 wait 3 | charge 5 0 5 5 | reads as 1011
t=3 refresh | charge 8 0 8 8 | reads as 1011
t=7 wait 4 | charge 4 0 4 4 | reads as 1011
t=7 refresh | charge 8 0 8 8 | reads as 1011
t=11 wait 4 | charge 4 0 4 4 | reads as 1011Rule 3 at work: the second row. After 3 ticks, each 1 has fallen from 8 to 5. The cell that holds a 0 stays at 0.
Rule 4 at work: the rows that say "refresh". Each one brings the three 1s back to 8. The row is refreshed after 3 ticks and then after 4 more.
The rows at t=7 and t=11 show the limit from the hand table. The charge is exactly 4, the row still reads as 1011, and one more tick would lose it.
This lab leaves out the electronics. Charge is a whole number, the leak is steady, and a refresh takes no time. It also leaves out the controller. A later page shows one on a large chip.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| One capacitor and one switch for a bit | The loop of six transistors of an SRAM | Ten to twenty times more bits in the same area. Reads that destroy, and a leak. |
| A refresh for every row, all the time | A cell that holds its charge | The tiny cell stays usable. The memory uses power even when idle, and is sometimes busy with itself. |
| DRAM in chips of its own | DRAM on the same chip as the processor | A factory that is tuned for capacitors. A fast and difficult link between the two chips. |
| A controller in front of the DRAM | The DRAM straight on the bus | Refresh is hidden from the processor. One more block to design and to check. |
The Trap: The Refresh That Came Late
A power-saving feature stretches the refresh by one tick, from four ticks to five. On the bench the memory test still passes, because the bench is cool and real cells leak slowly then. In a warm room, the product starts to crash. Here is the row of the lab with a refresh after five ticks:
t=0 write 1011 | charge 8 0 8 8 | reads as 1011
t=5 wait 5 | charge 3 0 3 3 | reads as 0000
t=5 refresh | charge 0 0 0 0 | reads as 0000
t=6 wait 1 | charge 0 0 0 0 | reads as 0000Rule 5 at work. At t=5 the charges are 3, below the sense level, and the row reads as 0000. The refresh then writes 0000 back: the charges become 0. One tick later the row is still 0000, and it will stay so.
Nothing reported an error. The memory accepted every command and answered every read. This is why refresh settings are never tuned by trying them out on one board.
At Scale
This section looks ahead. A real DRAM has billions of cells, and a controller that does far more than refresh.
The controller and its link
The commands, the fast link and its tuning: the memory of a large chip.
Sleep
A sleeping phone must still refresh its DRAM, or lose everything. The DRAM can do it alone, in a special low-power state.
Small chips do without
A chip like ap_soc has 64 KiB of SRAM and no DRAM. Below a few mebibytes, SRAM on the chip is simpler and cheaper.
Errors
With billions of leaking cells, single wrong bits do happen. Large memories carry extra bits to find and repair them.
Try It
Run the lab. Check the charges after each wait against the hand table.
Change the first leak(3) to leak(5). Predict what the row reads as at the end.
Set SENSE to 2. Work out the new refresh interval, and test it with one long wait.
t=0 write 1011 | charge 8 0 8 8 | reads as 1011 t=3 wait 3 | charge 5 0 5 5 | reads as 1011 t=3 refresh | charge 8 0 8 8 | reads as 1011 t=7 wait 4 | charge 4 0 4 4 | reads as 1011 t=7 refresh | charge 8 0 8 8 | reads as 1011 t=11 wait 4 | charge 4 0 4 4 | reads as 1011Check Yourself
Common Mistakes
Wrong Treat DRAM like a large SRAM.
Its charge leaks, and a read empties the cell.
Fix Plan for a controller that refreshes every row in time.
Wrong Expect a late refresh to repair a weak bit.
A refresh writes back what it reads. Below the sense level it reads 0.
Fix Keep every row inside its refresh interval, in every state of the chip.
Wrong Stop the refresh while the processor sleeps.
The cells leak whether or not anybody reads them.
Fix Keep the refresh running, or accept that the content is lost.
Remember
- A DRAM bit is a charge on a capacitor behind one switch: tiny, so DRAM is very dense.
- A read empties the cell, so the value is written back at once.
- The charge leaks, so every row is refreshed on a schedule, for as long as the power is on.
- A late refresh writes the wrong value back. A controller owns the schedule.