Read-only memory (ROM)
Look up fixed table values by address and compare combinational reads with reads that return data after a sampling edge. Use the synthesis report to identify the target’s implementation in logic or memory resources and document the coding patterns that tool supports.
A calibration table holds four fixed coefficients. A sensor supplies an index and receives one byte. The interface needs no write port, but the caller needs to know when the byte is available.
The RTL
Four case arms map addresses 0, 1, 2 and 3 to hex 31, 52, A4 and 0F. The comb output reads the lookup directly. The registered output samples that same byte at the rising clock edge.
module lookup_rom(
input logic clk,
input logic [1:0] addr,
output logic [7:0] comb,
output logic [7:0] registered
);
always_comb begin
case (addr)
2'd0: comb = 8'h31;
2'd1: comb = 8'h52;
2'd2: comb = 8'hA4;
2'd3: comb = 8'h0F;
default: comb = 8'h00;
endcase
end
always_ff @(posedge clk) registered <= comb;
endmodule
Trace the outputs
Hold address 1 across a rising edge. Both outputs read 52. Change the address to 2. The combinational output moves to A4 while the registered one holds 52 until the next edge.
| Rising edge | Inputs (hex) | Observed after edge (hex) |
|---|---|---|
| E0 | addr=0 | comb=31, registered=31 |
| E1 | addr=1 | comb=52, registered=52 |
| E2 | addr=2 | comb=A4, registered=A4 |
| E3 | addr=3 | comb=0F, registered=0F |
Design choices
A combinational lookup still has propagation delay. The case describes table contents and read behavior. Size, target and synthesis settings determine the implementation. The download includes an iCE40 mapping for this particular table.
Yosys synth_ice40 mapped this module to the following cell counts: SB_DFF: 8, SB_LUT4: 6. The download records the tool versions and the commands to reproduce this mapping. This small table used LUTs and flip-flops; the mapping used no block RAM.
Interactive lab
Sample address 1 on a rising edge, then switch to 2. Which output still holds 52?
- comb
- registered
Show the last eight observations
Teaching film
Run the RTL yourself
Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.
Download Read-only memory (ROM) RTL (.zip)