C7 · Lesson 45 · Memory arrays and programmable logic
Organizing memory, and logic you can rewrite after it's built
A memory is a lookup table: give it an address and it returns the word stored there. Turn that around and a lookup table is a circuit: store a function's truth table in a small memory, feed the function's inputs to the address lines, and the memory computes the function. That's exactly what an FPGA does, thousands of times over, with programmable wiring between the tables, so one chip can become any digital circuit you describe. This lesson covers how memories are organized and combined, and how memory becomes logic.
- A 3-input lookup table, the heart of an FPGA: eight configuration bits to feed an 8-to-1 multiplexer whose select lines are the logic inputs A, B and C.
- It's configured as 3-input odd parity: , , and are 1. Flip A, B and C and Y follows .
- Now change the configuration bits: set only and it becomes a 3-input AND, with no change of wiring.
Predict
A memory chip holds 512K words of 8 bits. How many address lines does it need?
19: 512K is words (524,288), and each address line doubles the number of words. The 8 bits of width are the data lines, not address lines. The chip stores = 4 Mbit.
Name it
Organization
A memory of words of m bits has n address lines and m data lines, and stores bits. Physically it's a nearly square grid of cells: part of the address drives a row decoder that selects one word line, and the rest drives column multiplexers that pick the wanted bits from the long row, which keeps both the decoder and the lines short.
Building bigger memories
- Wider words: put chips side by side, sharing the address lines; each supplies some of the data bits.
- More words: put chips in parallel on the data lines and decode the extra (top) address bits into chip selects, so exactly one chip responds.
The number of chips is (words needed ÷ words per chip) × (width needed ÷ width per chip).
Memory as logic
A ROM implements any m functions of n inputs: the address is the input and each data bit is one function's truth table. A PLA (programmable logic array) saves space for sparse functions with a programmable AND plane producing product terms and an OR plane combining them.
FPGAs
An FPGA is a grid of configurable logic blocks, each with a few k-input lookup tables ( bits of configuration memory driving a :1 multiplexer, typically k = 4 to 6) and flip-flops, surrounded by programmable routing. Functions of more than k inputs are split across several LUTs. FPGAs add block RAMs, multiplier (DSP) blocks and clock managers. Loading a new bitstream changes every LUT and connection: the same chip becomes a different circuit.
Worked example
Build a 64K × 16 memory from 16K × 8 chips.
Show the solution
- Width. chips side by side.
- Depth. rows of chips, selected by a 2-to-4 decoder on the top 2 of the 16 address bits.
- Total. 8 chips, each seeing the low 14 address bits.
Answer 8 chips, in 4 rows of 2.
Worked example
A 4-input LUT implements a 7-input AND. How many LUTs does it take?
Show the solution
- First LUT. One LUT can AND 4 inputs.
- Second LUT. A second ANDs its output with the remaining 3.
- In general. An n-input AND needs 4-input LUTs.
Answer two LUTs.
Worked example
A full adder is stored in a ROM. How many address and data bits, and how many bits in all? What about a 4-bit adder with carry in?
Show the solution
- Full adder. Three inputs (A, B, carry in) address = 8 words, each holding two outputs (sum and carry):
- 4-bit adder. It has 9 inputs and 5 outputs (four sum bits and a carry out):
- Chained full adders. Chaining four full-adder ROMs needs only 64 bits: decomposing a function into small blocks is what keeps lookup-table logic practical.
Answer 3 address bits and 2 data bits, 16 bits in all; a 4-bit adder with carry in needs 2560 bits.
Check
How many address lines does a memory of words need, for k = 16?
Check
A memory holds 64K words of 8 bits. How many kibibytes is that?
Check
How many 32K × 8 chips make a 64K × 16 memory?
Check
How many bits must a ROM store to implement 1 functions of 8 inputs?
Check
How many configuration bits does a 5-input LUT hold?
Check
How many 4-input LUTs does a 19-input AND gate take?
Check
A 2-input LUT's configuration bits are = 0, = 1, = 1, = 0 (selected by AB). What function does it compute?
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
A 64K × 32 memory is built from 64K × 16 chips.
(a)
How many chips?
(b)
How many address bits drive the chip-select decoder?
Check
An n-input, m-output function is built as a ROM, or as an n-input AND from k-input LUTs.
Step 1
How many bits does the ROM need?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many k-input LUTs does the AND need?
Explain why
How can a lookup table replace any logic gate network?
Any combinational function of k inputs is completely described by its truth table, output values. A lookup table stores exactly those values in small memory cells and uses the inputs as an address, through a multiplexer, to read the one that belongs to the current input combination. Whatever gates the function would need, the LUT produces the same output for every input. Changing the stored bits changes the function, which is how an FPGA becomes a different circuit when it loads a new configuration.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.