Store a 16-word gamma table in a ROM with a synchronous read, and return each word one clock edge later.
Hardware context: An eight-word register file of a small processor, with two read ports and a fixed zero register. Store the gamma table of an LED dimmer in a ROM read at the clock edge.
An LED dimmer has 16 brightness levels. The eye does not see light in a straight line, so each level maps to a PWM duty through a gamma table. The table is fixed, so it lives in a ROM.
This is an Implement problem. Write gamma_rom. Fill a 16-word array with the table and read it at the clock edge, as a block RAM in an FPGA does.
The test asks for one level per cycle and checks each word just after the edge. Every level is read in some test.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
levels | 32 | input of each check |
Full specification
module gamma_rom (
input logic clk,
input logic [3:0] level, // the brightness the user asked for, 0 to 15
output logic [7:0] duty // the PWM duty from the table, one clock edge later
);
// your design
endmodule
| level | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| duty (hex) | 00 | 01 | 03 | 07 | 0e | 17 | 22 | 30 |
| level | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|
| duty (hex) | 40 | 53 | 69 | 81 | 9c | ba | db | ff |
| Port rule | Definition |
|---|---|
| Read | At each rising edge, duty takes the word at the level present before that edge. |
| Between edges | duty holds its value while level changes. |
Each test reads eight levels, one per cycle. The result shows the eight words read, in order. It also counts the cycles in which duty changed before the clock edge: that count must be 0.
Examples
Example 1
Low Levels- Input
levels: 0, 1, 2, 3, 4, 5, 6, 7
- Output
read0 = 0x0, read1 = 0x1, read2 = 0x3, read3 = 0x7, read4 = 0xe, read5 = 0x17, read6 = 0x22, read7 = 0x30, changed_between_edges = 0
Levels 0 to 7 in order. Each word appears just after the edge that took its level.
Example 2
High Levels- Input
levels: 8, 9, 10, 11, 12, 13, 14, 15
- Output
read0 = 0x40, read1 = 0x53, read2 = 0x69, read3 = 0x81, read4 = 0x9c, read5 = 0xba, read6 = 0xdb, read7 = 0xff, changed_between_edges = 0
Levels 8 to 15. These words hold the hex letters a to f, so a table typed as decimal fails here.
Example 3
Up and Down- Input
levels: 15, 0, 14, 1, 13, 2, 12, 3
- Output
read0 = 0xff, read1 = 0x0, read2 = 0xdb, read3 = 0x1, read4 = 0xba, read5 = 0x3, read6 = 0x9c, read7 = 0x7, changed_between_edges = 0
The level jumps between the ends of the table. The word must follow the level of the last edge, not the level of the edge before.
Constraints and Contract
- level is a known 0/1 value. It changes while the clock is low.
- Keep the module name and the ports. The words are the table above, in hexadecimal.
Hints
Hint 1
Declare the ROM as an array of 16 words of 8 bits. The size form [16] numbers the words 0 to 15.
Hint 2
Fill it in an initial block, one line per word, with the hex prefix 8'h.
Hint 3
One always_ff line reads the array at the clock edge.
What the grader checks: Eight tests of eight reads each cover every level several times, and the word is checked just after every edge. Loading the table from a file is outside this problem: the browser simulator runs one source file.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
8 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone