BitFlow
← Academy·Memories and Programmable Logic
▦Core~45 min

Memories and Programmable Logic

How RAM and ROM store and find data, why DRAM forgets, sizing memories, and PLAs, PALs and FPGAs.

Interactive·Memory Read/Write Lab

16-byte SRAM array — pick an address, set data, and READ or WRITE. Watch cells light up on access!

Memory array (hex)

0x00

Ready — select address

How a memory is organised

A memory is a grid of cells that hold bits. An address selects one row, or word, through a decoder, which you met in Chapter 11. A write-enable says whether to store into that row or read from it.

capacity = 2^(address bits) × word width
So a 2¹⁰ × 8 memory is 1024 bytes, written 1K × 8.

Loading the animation…

Loading the circuit…

A 4-word, 4-bit RAM as one part. Writes happen at a clock edge while we is on, and the selected word always shows on q.
  • Set addr to 1 and data to 6, turn on we, and press Clock edge. Now q is 6.
  • Turn we off and change addr to 0. q shows that word's contents, then return to 1 and the 6 is still there.
Practice

A memory has 12 address lines and 8 data lines. What's its capacity?

SRAM and DRAM

RAM loses its contents without power, and comes in two kinds. SRAM stores each bit in the same kind of loop as a latch: two cross-coupled inverters, plus two access transistors. DRAM stores a bit as charge on a tiny capacitor, reached through a single transistor.

Loading the animation…

Loading the animation…

SRAMDRAM
Transistors per bit61, plus a capacitor
RefreshNot neededNeeded, about every 64 ms
SpeedFastSlower
Density and costLow density, expensiveHigh density, cheap
ReadsDon't disturb the bitDestroy the bit, so it's written back
Used forCaches, registersMain memory
NoteThat's why every computer uses both: a little fast SRAM cache close to the processor, and a lot of DRAM behind it.

ROM and its relatives

Non-volatile memory keeps its contents without power. The oldest form, a mask ROM, is fixed when the chip is made, and each later type made rewriting easier.

TypeHow it's writtenHow it's erased
Mask ROMAt the factoryIt can't be
PROMOnce, by blowing fusesIt can't be
EPROMElectricallyUltraviolet light, the whole chip
EEPROMElectricallyElectrically, a byte at a time
FlashElectricallyElectrically, a block at a time

A ROM is a look-up table: any combinational function of n inputs fits in a ROM with n address lines. Give it the inputs as an address, and the answer has been stored in advance.

Loading the circuit…

An 8 × 6 ROM holding squares. Nothing is calculated: the answer is just read out. Displays are in hex, so 5 gives 19, which is 25.

Building bigger memories

You combine chips in two ways. To get a wider word, put chips side by side, with the same address going to all. To get more words, stack chips and use the top address bits, through a decoder, to choose which one is active.

chips = (words needed ÷ words per chip) × (width needed ÷ width per chip)
Worked example: 64K × 8 from 16K × 4 chips

How many chips do you need, and how are they decoded?

  1. Width: 8 ÷ 4 = 2 chips side by side.
  2. Depth: 64K ÷ 16K = 4 rows of those.
  3. That's 4 × 2 = 8 chips.
  4. 64K needs 16 address lines, and each chip uses 14. The top 2 go to a 2:4 decoder that selects a row.

Answer:8 chips and a 2:4 decoder.

Practice

How many 1K × 4 chips make a 4K × 8 memory?

Programmable logic

So far, all our logic has been fixed at design time. Programmable logic devices let you change a chip's function after it's made, and they've become the main way to prototype digital systems. The early ones are all a programmable AND-OR array.

DeviceAND planeOR plane
PROMFixed (every minterm)Programmable
PALProgrammableFixed
PLAProgrammableProgrammable

Loading the animation…

A CPLD joins several PAL-like blocks with a switch matrix. An FPGA goes much further: thousands of small logic cells in a grid, and programmable wiring between them. Each cell holds a look-up table and a flip-flop.

Loading the animation…

A whole FPGA is a grid of these blocks with programmable wiring between them. Lift one block's table out in the 3D view and follow its result along the wiring.

Loading the animation…

An FPGA also has block RAM, multipliers and clock managers built in. Its configuration lives in SRAM, so it loads from flash at power-up, and you can reprogram it as often as you like.

Flash a real FPGA board →Build a design here and program it onto a board from your browser.
Practice

How many bits of memory does a 4-input LUT hold?

Exam numbersGATE: fine to skip at first

Questions on memories mostly come down to address lines, chip counts and refresh. The number of address lines is log₂ of the number of words. To size a ROM for a function, use the inputs as address lines and the outputs as data lines.

Practice · GATE-style

What size of ROM can hold a 4-bit by 4-bit multiplier?

Practice · GATE-style

How many address lines does a 2 MB memory organised in bytes need?

Practice · GATE-style

A 4K × 8 memory is built from 1K × 8 chips. What decoder selects the chips?

Practice · GATE-style

How many functions of 4 inputs can a single 4-input LUT implement?

Was this chapter helpful?