Digital System Design
RAM & ROM Structures
Every digital system needs somewhere to keep data and instructions. Memory chips and memory blocks inside programmable devices all follow the same basic organization: an array of storage cells, a way to pick one word from the array, and control lines that decide whether to read or write. Once you understand this structure, you can size a memory, read a data sheet and build larger memories from smaller ones.
Learning objectives
By the end of this lesson you will be able to:
- Calculate the capacity of a memory from its address and data widths.
- Describe the address, data and control signals of a RAM and a ROM.
- Explain how a decoder selects one word, including row and column decoding.
- Compare SRAM, DRAM and the main ROM types.
- Use a ROM as a look-up table for logic functions.
Memory as an array of words
A memory stores words. Each word has a fixed width of m bits and its own address. With n address lines you can select 2^n different words, so:
- Number of words = 2^n
- Capacity in bits = 2^n x m
A memory described as "1K x 8" has 1,024 words of 8 bits each. In digital design, K means 1,024, M means 1,048,576 (2^20), and G means 2^30.
The signals of a memory chip
| Signal | Purpose |
|---|---|
| Address lines (A) | Select which word is accessed |
| Data lines (D) | Carry the word being read or written |
| Chip select / chip enable (CS or CE) | Turns the chip on so it responds to the address |
| Write enable (WE) | Selects a write cycle instead of a read cycle (RAM only) |
| Output enable (OE) | Lets the chip drive the data lines during a read |
When CS is inactive, the data lines of a chip are in a high-impedance state. That is what allows several chips to share one data bus, which is the basis of memory expansion in the next lesson.
RAM: read and write memory
RAM (random-access memory) can be read and written, and any word can be reached in the same time regardless of its address. RAM is volatile: it loses its contents when power is removed.
- SRAM stores each bit in a small latch of several transistors. It is fast, needs no refresh, and is used for caches and for the block RAM inside FPGAs. It takes more chip area per bit.
- DRAM stores each bit as charge on a capacitor with one transistor. It is much denser and cheaper per bit, but the charge leaks away, so every row must be refreshed periodically. It is used for the main memory of computers.
ROM: read-mostly memory
ROM (read-only memory) keeps its contents without power. The types differ by how the contents are written:
| Type | How it is programmed | Can it be rewritten? |
|---|---|---|
| Mask ROM | Fixed during chip manufacturing | No |
| PROM | Programmed once by the user | No |
| EPROM | Programmed electrically, erased with ultraviolet light | Yes |
| EEPROM | Programmed and erased electrically, byte by byte | Yes |
| Flash | Programmed and erased electrically in blocks | Yes |
How a word is selected: decoders
Inside a memory, the cells form a grid. A row decoder turns on one word line, and the cells in that row put their bits on the bit lines.
A simple memory with a single decoder needs one output line per word. A 1,024-word memory would need a 10-to-1,024 decoder with 1,024 outputs, which is large. Real memories use two-dimensional decoding instead. The address is split into a row part and a column part, and each part feeds a smaller decoder.
For 1,024 words arranged as 32 rows by 32 columns:
- Row address: 5 bits (2^5 = 32)
- Column address: 5 bits (2^5 = 32)
- Decoder outputs: 32 + 32 = 64 instead of 1,024
This is the same idea you saw with multiplexers and decoders: a bigger selection problem is split into two smaller ones.
Worked example 1: Sizing a 1K x 8 memory
Question. How many address lines, how many bits, and what address range?
- Words = 1,024 = 2^10, so there are 10 address lines.
- Data lines = 8.
- Capacity = 1,024 x 8 = 8,192 bits, which is 1,024 bytes.
- Addresses run from 0 to 1,023. In 10-bit binary that is 0000000000 to 1111111111, and in hexadecimal it is 000 to 3FF.
If the memory were 4K x 8 instead, there would be 12 address lines and the range would be 000 to FFF. Hex is useful here because each hex digit covers exactly 4 address bits, and you can check conversions with the number converter.
Worked example 2: Capacity of a 64K x 16 memory
- Words = 64K = 65,536 = 2^16, so there are 16 address lines.
- Data lines = 16.
- Capacity = 65,536 x 16 = 1,048,576 bits.
- In bytes: 1,048,576 / 8 = 131,072 bytes, which is 128 KB.
Notice that the number of address lines depends only on the number of words, and the number of data lines depends only on the word width. The two are independent.
Worked example 3: A ROM as a logic function
A ROM with n address lines and m data lines can implement any m functions of n variables. The inputs are the address, and the stored word at each address is the output. This is the same idea as the look-up tables in an FPGA from the CPLD vs FPGA lesson.
Implement a full adder with inputs a, b, cin and outputs cout and sum. There are 3 inputs and 2 outputs, so an 8 x 2 ROM is needed, holding 8 x 2 = 16 bits.
| Address (a b cin) | Stored word (cout sum) |
|---|---|
| 000 | 00 |
| 001 | 01 |
| 010 | 01 |
| 011 | 10 |
| 100 | 01 |
| 101 | 10 |
| 110 | 10 |
| 111 | 11 |
Each stored word is the binary value of a + b + cin. For address 111 the sum is 3, which is 11 in binary. No gates are needed other than the ROM itself, but the cost doubles with every added input, since the number of words is 2^n.
Common mistakes
- Confusing bits and bytes. Capacity in bits is 2^n x m. Divide by 8 for bytes.
- Counting the data width into the address lines. A 1K x 8 memory has 10 address lines, not 18.
- Using decimal K as 1,000. In memory sizes, K is 1,024.
- Assuming ROM cannot change. EEPROM and Flash are called ROM but can be rewritten.
- Forgetting the enable signals. A chip with CS inactive ignores its address and does not drive the bus.
Practice problems
Problem 1. A memory has 64K words of 16 bits. How many address lines and how many bytes?
Answer: 16 address lines. 65,536 x 16 / 8 = 131,072 bytes (128 KB).
Problem 2. How many address lines does a memory with 2M words need?
Answer: 2M = 2^21 = 2,097,152, so 21 address lines.
Problem 3. A ROM implements a 4-bit adder with carry-in, taking inputs a (4 bits), b (4 bits) and cin, and giving a 4-bit sum and a carry-out. How big is the ROM?
Answer: There are 9 inputs, so 2^9 = 512 words. There are 5 outputs, so the ROM is 512 x 5 = 2,560 bits.
Problem 4. A 4 x 4 multiplier takes two 4-bit inputs and gives an 8-bit product. What ROM size does it need as a look-up table?
Answer: 8 inputs give 2^8 = 256 words of 8 bits, which is 256 x 8 = 2,048 bits.
Frequently asked questions
What does "random access" mean? It means any word can be read or written in about the same time, no matter where it is. This differs from a tape, which must be wound to the right place.
Why is DRAM cheaper than SRAM? A DRAM cell uses one transistor and one capacitor, while an SRAM cell uses several transistors. More bits fit in the same area, at the cost of needing refresh.
Is Flash memory RAM or ROM? It is a type of non-volatile ROM that can be erased and rewritten, but writes are slower than in RAM and each cell supports a limited number of write cycles.
Next lesson: continue with Memory Expansion to combine small memory chips into larger memories.