Capacity, organisation, expansion with several chips and memory map
A memory is a table of locations (words), all of the same width. The address lines choose the location and the data lines carry its content. With n address lines there are 2n locations; if each one stores w bits, the capacity is:
That is why memories are named by their organisation: a 62256 is a 32K × 8 SRAM (15 address lines, 8 data lines, 256 Kbit) and a 27C512 is a 64K × 8 EPROM. They also have control signals: CS or CE (chip select), OE (output enable, to read) and WE (write enable), almost always active low.
Beware of units: memory manufacturers state capacity in bits (a "256K" chip holds 256 Kbit = 32 KB) and use K = 1024. IEC standards reserve Ki, Mi and Gi for powers of 2 and k, M and G for powers of 10, which is what disk manufacturers do.
The memory map tells which address belongs to each chip. Each block is placed at an address that is a multiple of its size: that way the low address lines go straight to the chip and its CS depends only on the high ones, which have a fixed value across the whole block. That condition is what is built with gates or with a decoder like the 74HC138. If not all the high lines are used (partial decoding), the circuit is simpler, but each chip appears repeated in several areas of the map, called images or mirrors.
| Type | Loses data without power? | Writing | Typical use |
|---|---|---|---|
| Mask ROM | No | At the factory only | Large series with fixed content |
| PROM (OTP) | No | Only once, with a programmer | Cheap OTP microcontrollers |
| EPROM | No | Programmer; erased with ultraviolet light | Older equipment, with a quartz window |
| EEPROM | No | Byte by byte, in circuit; around 106 cycles | Configuration, calibration, counters |
| NOR flash | No | By blocks that must be erased first; 104 to 105 cycles | Microcontroller program, firmware |
| NAND flash | No | By pages, with bad-block management | SD cards, USB sticks, SSDs |
| SRAM | Yes | Unlimited, very fast | Internal RAM of microcontrollers, caches |
| DRAM | Yes, and it also needs refreshing | Unlimited | Main memory of computers |
| FRAM / MRAM | No | Fast, 1012 cycles or more | Frequent data logging |
SRAM stores each bit in a six-transistor latch: fast but expensive per bit. DRAM stores it as the charge of a tiny capacitor, which leaks away in milliseconds and must be refreshed continuously, but much more fits in the same silicon. Non-volatile memories trap charge in a floating gate; each erase wears it, which is why they have a limited number of write cycles.
A microcontroller contains all three kinds: flash for the program, SRAM for variables and the stack, and often EEPROM (or a flash area emulating it) for data that must be kept. An ATmega328P has 32 KB of flash, 2 KB of SRAM and 1 KB of EEPROM; an ESP32 keeps its program in an external SPI flash of 4 MB or more. When it falls short, external memory is added over a serial bus: I²C EEPROM like the 24LC256 (32 KB), SPI flash like the W25Q32 (4 MB) or SPI FRAM. Keep write cycles in mind: saving a value to EEPROM every second wears out 106 cycles in less than two weeks.
Related: decoders and encoders, flip-flops and number system converter (to convert addresses to hexadecimal).