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 direct output follows the lookup. The second output samples it on an edge.
The direct output follows the lookup. The second output samples it on an edge.

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.

Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Rising edgeInputs (hex)Observed after edge (hex)
E0addr=0comb=31, registered=31
E1addr=1comb=52, registered=52
E2addr=2comb=A4, registered=A4
E3addr=3comb=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

    Read the transcript

    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)

    Check your understanding

    1. Which coefficient is at address 2?
    2. Which output first reflects an address change between edges?
    3. What event samples a coefficient into registered?
    4. Does this ROM need a wd port?
    5. Where can you tell if this ROM used FPGA block memory?