EN

Memories

Capacity, organisation, expansion with several chips and memory map

1. Capacity of a memory

Organisation

2. Expanding memory with several chips

Available chip
Memory to build

3. Memory map

Bus and devices

Organisation: locations and width

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:

\[ C = 2^{n} \cdot w\ \text{bits} \qquad n = \log_2(\text{locations}) \]

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.

Expanding in width and depth

Memory map

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.

Memory types

TypeLoses data without power?WritingTypical use
Mask ROMNoAt the factory onlyLarge series with fixed content
PROM (OTP)NoOnly once, with a programmerCheap OTP microcontrollers
EPROMNoProgrammer; erased with ultraviolet lightOlder equipment, with a quartz window
EEPROMNoByte by byte, in circuit; around 106 cyclesConfiguration, calibration, counters
NOR flashNoBy blocks that must be erased first; 104 to 105 cyclesMicrocontroller program, firmware
NAND flashNoBy pages, with bad-block managementSD cards, USB sticks, SSDs
SRAMYesUnlimited, very fastInternal RAM of microcontrollers, caches
DRAMYes, and it also needs refreshingUnlimitedMain memory of computers
FRAM / MRAMNoFast, 1012 cycles or moreFrequent 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.

Memory in a microcontroller

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).