Catto / Topic Map · Digital Electronics III Year 6
Digital Electronics III · 144 h · Topic 5 of 7

Programmable systems and memories

Two topics that look different and are really the same: storing bits in one place and reading them back later. A memory stores data; a programmable logic device stores the function the circuit is going to perform.

Microcontrollers Memories Decoding FPGA

01The map of memories

TypeVolatileWriteCyclesWhere you find it
SRAMYesImmediateUnlimitedMicrocontroller variables, processor cache. Fast and expensive: six transistors per bit.
DRAMYesImmediateUnlimitedMain memory of a PC. One transistor and one capacitor per bit: cheap and dense, but it needs constant refreshing.
Mask ROMNoAt the factory—Burned into the silicon. Only justified in huge production runs.
PROMNoOnce1Internal fuses are “blown.” Historical.
EPROM (UVPROM)NoElectrical~100The one with the little quartz window: it is erased with ultraviolet light in 20 minutes. Still found in old industrial equipment.
EEPROMNoByte by byte~106Configuration and calibration. Slow to write (milliseconds per byte).
Flash NORNoBy blocks~105Microcontroller program memory and BIOS. It is read byte by byte, which allows executing code directly from it.
Flash NANDNoBy pages103–105USB flash drives, SD cards, SSDs. Much denser and cheaper, but it can only be read by pages.
FRAMNoImmediate1014Continuous data logging without wear-out. Expensive and low capacity.
The three questions that define a memory
  1. Does it lose its contents when power is removed? Volatile or non-volatile.
  2. How many times can it be written? That number —the endurance— decides whether it is suitable for storing a value that changes all the time.
  3. How fast does it respond? Nanoseconds in SRAM, microseconds when reading Flash, milliseconds when writing an EEPROM.
Wear-out is not a minor detail

A NAND Flash cell in a cheap USB flash drive withstands about 3000 cycles of erasing. If a program always wrote to the same location, the drive would die within minutes. What prevents this is wear leveling: the controller spreads the writes over the whole chip and keeps a map of which physical block corresponds to each logical address. It is a complete system, with its own processor, inside every USB flash drive and every SSD.

02How it is organized and how it is selected

A memory is an array of cells with three groups of pins: address, data and control. Capacity is written as “words × bits”: a 62256 is 32 K × 8, that is, 32,768 locations of one byte.

locations=2ncapacity=2n·mbits n is the number of address lines and m the word width. With 15 lines: 215 = 32,768 locations.
SignalNameWhat it does
CS̄ / CĒChip selectEnables the chip. This is what allows several memories on the same bus: only the selected one responds.
OĒOutput enablePuts the data on the bus. Without it, the outputs stay in high impedance.
WĒWrite enableWrites what is on the data bus to the address that is present.
A0…AnAddressSelect the location.
D0…D7DataBidirectional, with three-state outputs.
address bus A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 A15 selects the chip A14…A0 select the location Memory 1 32 K · 0x0000–7FFF CS̄ Memory 2 32 K · 0x8000–FFFF CS̄ 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 selected address 0x0100 → memory 1 responds · location 0x0100 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 selected address 0x7FFF → memory 1 responds · last location 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 selected address 0x8000 → A15 goes to 1: memory 2 responds 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 selected address 0xC000 → memory 2 responds · internal location 0x4000
Figure 1. Address decoding, animated. The high lines of the bus choose which chip responds and the low ones, which location inside it. A 74HC138 decoder handles the split: it is the same circuit from combinational logic.
Example · Splitting 64 KB between two 32 KB memories
  • Each 32 K chip needs 15 address lines (A0 to A14), because 215 = 32,768.
  • Line A15 does not go to the chips: it is used to choose which one responds. With A15 = 0 the first is enabled (addresses 0000 to 7FFF) and with A15 = 1 the second (8000 to FFFF).
  • With four chips, A15 and A16 would be used with a 2-to-4 decoder; with eight, three lines and a 74HC138.

If two chips were enabled at the same time, both would put data on the bus: it is a short circuit between outputs, exactly what the ERC of the schematic warns about.

03Programmable logic devices

A circuit with fifty gates can be built with fifteen 74-series ICs —taking up half a circuit board— or with a single programmable chip that is configured by software. That is the whole idea, and its evolution has three stages.

PAL and GAL

An array of programmable connections between the inputs and a set of AND-OR gates. They replace around ten 74-series ICs. The GAL22V10 was for years the wild card of any digital design.

CPLD

Several GAL-type blocks joined by an interconnect matrix. Hundreds of macrocells, non-volatile configuration —it works as soon as it is powered on— and very predictable timing. Ideal for glue logic and decoding.

FPGA

Thousands or millions of logic blocks with memory, multipliers and even processors inside. It is configured at power-up from an external Flash. This is what makes it possible to create custom hardware: twenty counters running in parallel, with none waiting for another.

0000 0 0001 0 0010 0 0011 0 0100 0 0101 0 0110 0 0111 0 1000 0 1001 0 1010 0 1011 1 1100 0 1101 1 1110 1 1111 1 16-bit memory D C B A output A B C D MUX output 1 1 0 0 0 inputs DCBA = 0011 row 3 is read 1 1 1 0 0 inputs DCBA = 0111 row 7 is read 1 1 0 1 1 inputs DCBA = 1011 row 11 is read 0 1 1 1 1 inputs DCBA = 1110 row 14 is read 1 1 1 1 1 inputs DCBA = 1111 row 15 is read 1 0 1 0 0 inputs DCBA = 0101 row 5 is read Changing the function means changing the 16 stored bits: the same silicon can do anything. An FPGA has thousands of these tables, plus flip-flops and an interconnect network that is also programmable.
Figure 2. The lookup table, animated. Inside an FPGA there are no hardwired gates: there are tiny memories that store the truth table. Changing the function means changing the stored bits, which is why the same silicon can be an adder or a decoder.
How they are programmed: HDL

You do not draw gates: you describe the behavior in a hardware description language —VHDL or Verilog— and a synthesis tool turns it into actual connections.

-- VHDL: an 8-bit counter. It is not a program: it is a circuit description.
process(clk)
begin
  if rising_edge(clk) then
    if reset = '1' then cuenta <= (others => '0');
    else cuenta <= cuenta + 1;
    end if;
  end if;
end process;

The conceptual difference from C is enormous: here there are no instructions that run one after another. Everything described happens at once, on every clock edge. If you write ten processes, all ten run simultaneously, like ten separate circuits.

MicrocontrollerFPGA
ExecutionSequential: one instruction at a timeParallel: everything at the same time
Programmed inC, assemblyVHDL, Verilog
CostDollarsTens to hundreds of dollars
Power consumptionLowHigh
Strong atComplex logic, arithmetic, communication, controlMany fast signals in parallel, video processing, high-speed acquisition
Typical exampleThermostat, control panel, instrumentLogic analyzer, image processing, software-defined radio
When to use each one

If the problem fits in a microcontroller, use a microcontroller: it is cheaper, simpler and easier to maintain. An FPGA is justified when you need true parallelism or nanosecond timing: counting twenty encoders at once, processing video frame by frame, generating signals with single-clock-cycle precision. Choosing an FPGA “because it is more modern” usually ends in an expensive project that does the same thing as a two-dollar chip.

04In the lab

Lab 1 · Reading a memory by hand

With an EPROM or SRAM on a breadboard, switches on the address lines and LEDs on the data lines, step through the locations and note down the contents. Drive CS̄ and OĒ by hand and observe what happens to the outputs when the chip is disabled: they go to high impedance, neither 1 nor 0.

Lab 2 · Decoding addresses

With a 74HC138 and two memories, build the 64 KB map from the example. Use LEDs to check which chip is enabled according to A15. Then deliberately wire the two CS̄ lines together and observe on the oscilloscope the conflict on the data bus.

Lab 3 · EEPROM wear-out

Write the same location of the microcontroller's EEPROM in a fast loop and keep count of the writes, displaying it on the serial port. Calculate how long it would take to reach a million cycles. Then write the same data rotating among 16 locations and compare the resulting service life.

Lab 4 · A counter in a CPLD or FPGA

If a board is available, describe the counter from the previous section in VHDL, synthesize it and watch it run on LEDs. Then duplicate the process to get two counters with different dividers and check that they run in parallel, with neither delaying the other. That experiment is the difference between hardware and software.

05Common mistakes

SymptomUsual cause
The data bus shows strange valuesTwo chips enabled at the same time: output conflict. Check the decoding.
The memory always reads the same thingAn address line was left unconnected or shorted, and several addresses point to the same location.
The write is not savedWĒ and OĒ active at the same time, or the write time was not respected.
A value stored in EEPROM gets corruptedWrite interrupted by a voltage drop. Enable brown-out detection and do not write on every pass of the loop.
The USB flash drive “died”Worn-out cells, or a corrupted allocation table from unplugging it during a write.
The FPGA does not start at power-upIt is volatile: it needs to load its configuration from the external Flash. If that Flash is not programmed, there is no circuit.
The VHDL design “gets the order wrong”It was thought of as a sequential program. In hardware everything happens at once: the order of the lines does not define the order in time.

06Self-assessment

How many address lines does an 8 K × 8 memory need?

8 K = 8192 = 213, so 13 lines (A0 to A12) and 8 data lines.

What is the difference between SRAM and DRAM?

SRAM stores each bit in a six-transistor flip-flop: it is fast and needs no maintenance, but it is expensive and not very dense. DRAM uses one capacitor per bit: it is dense and cheap, but it discharges and needs permanent refreshing.

What is the CS̄ signal for?

To enable the chip. It allows several memories to be connected to the same bus: address decoding activates only one at a time, and the others keep their outputs in high impedance.

Why does a NAND Flash withstand fewer cycles than an EEPROM?

Because it prioritizes density and cost: smaller cells, even storing several bits per cell. That wears the oxide more with each erase. EEPROM is much less dense but withstands on the order of a million cycles per byte.

What is wear leveling and where is it implemented?

Spreading the writes among all the blocks so that none wears out first. It is done by the controller inside the USB flash drive, card or SSD, with its own processor and its translation table.

What is inside an FPGA instead of gates?

Lookup tables (LUTs): very small memories that store the truth table of the desired function, with an associated flip-flop. Programming the FPGA means writing those tables and the connections between blocks.

What is the essential difference between programming in C and describing in VHDL?

In C the instructions run one after another; in VHDL you describe hardware that works all at the same time. Ten processes in VHDL are ten simultaneous circuits, not ten steps.

When is an FPGA better than a microcontroller?

When you need true parallelism or nanosecond timing: many fast signals handled at once, video processing, high-speed acquisition. For control, communication and moderate computation, the microcontroller is cheaper and simpler.

A CPLD works as soon as it is powered on and an FPGA does not. Why?

Because the CPLD's configuration is non-volatile and lives inside the chip, whereas the FPGA loads its configuration at startup from an external Flash memory. If that memory fails, the FPGA is left without a function.

Why does an EPROM have a little quartz window?

Because it is erased by exposing the chip to ultraviolet light, which discharges the floating gates of the cells. That is why, once programmed, the window is covered with a label: sunlight would erase it over time.

Development of the topic “Programmable systems and memories” of Digital Electronics III (Year 6), based on the “Curriculum Proposal – Second Cycle of the Technical-Vocational Track, Secondary Education – Electronics,” Ministry of Education of the Province of Córdoba, DGETyFP. Back to the Topic Map · catto.ar