G8.6.1 A Sequencer in a ROM

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Build a crossing light as a 16-word ROM and a state register, with every word filled from the state table.

Hardware context: A crossing light for cars and walkers whose whole behaviour is a 16-word ROM and a state register. Build a state machine whose next state and outputs are the words of a ROM.

A crossing light for cars and walkers runs through four states. The designer wants no state logic at all. A ROM holds the whole state table, and a 2-bit register holds the state.

This is an Implement problem. Fill the 16 words of the ROM, form its address, and connect the word to the lights and to the state register.

The test drives the button and the timer and checks the three lights in every cycle. In some tests it rewrites a few ROM words in the middle of the run, as a field update would. The lights and the next state must follow the new words.

Signals in the Timeline

SignalWidthRole
ins48input of each check
Full specification
The module you write (keep the name, the ports and the array rom)
module rom_seq (
  input  logic clk,
  input  logic rst,             // synchronous, active high: back to state 0
  input  logic btn,             // the walk button
  input  logic tmo,             // 1: the light timer has run out
  output logic car_go,          // the three lights
  output logic car_slow,
  output logic walk
);
  logic [4:0] rom [16];
  // your design
endmodule
StateLights {car_go, car_slow, walk}Next state
0 cars go1 0 01 if btn is 1, else 0. The timer is ignored.
1 cars slow0 1 02 if tmo is 1, else 1. The button is ignored.
2 all stop0 0 03, always.
3 walk0 0 10 if tmo is 1, else 3. The button is ignored.
ROM ruleDefinition
Address{state, btn, tmo}: 4 bits, so word 6 is state 1 with btn = 1 and tmo = 0.
Word{next state (2 bits), car_go, car_slow, walk}: 5 bits.
LightsThe three low bits of the word at the current address. They do not wait for a clock edge.
ClockAt each rising edge the state register loads the two high bits of the word.
ResetAt a rising edge with rst = 1 the state becomes 0.

Each test resets the light, then drives btn and tmo for 24 cycles. The lights are checked just before each edge. The result has two fields.

FieldMeaning
rom_wrongHow many of the 16 ROM words differ from the state table.
wrong_cyclesHow many of the 24 cycles showed the wrong lights.

Examples

Example 1

One Press, One Full Crossing
Input
btn tmo per cycle: 00 10 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Output
rom_wrong = 0, wrong_cycles = 0, cycles = 24

The press moves the light from cars go to cars slow. Each timeout moves it on, through all stop and walk, and back to cars go.

Example 2

No Press
Input
btn tmo per cycle: 00 01 01 00 01 00 01 01 00 00 01 00 01 00 00 01 01 01 00 00 01 00 00 01
Output
rom_wrong = 0, wrong_cycles = 0, cycles = 24

With no press the light stays in cars go, even when the timer runs out. A table that lets tmo move state 0 fails here.

Example 3

The Button Held Down
Input
btn tmo per cycle: 10 10 10 11 10 10 11 10 10 10 11 10 10 10 10 11 10 10 11 10 10 10 10 10
Output
rom_wrong = 0, wrong_cycles = 0, cycles = 24

The button only matters in state 0. In the other states the words for btn = 1 must equal the words for btn = 0.

Constraints and Contract

  • btn and tmo are known 0/1 values. They change while the clock is low.
  • Keep the module name, the ports and the array logic [4:0] rom [16]. Fill it once, in an initial block. The test may write rom during the run and reads it at the end.

Hints

Hint 1

Write the 16 addresses in a column, grouped by state: four rows per state. Beside each one, write the next state and the three lights.

Hint 2

All four words of a state have the same lights. Only the next state depends on btn and tmo.

Hint 3

The address is {state, btn, tmo} in that order. Use the same order in the table and in the expression that reads the ROM.

What the grader checks: Six directed, three rewrite and eight seeded scripts of 24 cycles are compared with a JavaScript model that reads the 16-word table. In three tests the fixture rewrites four ROM words before cycle 12. So the lights and next state must come from the ROM. All 16 words are compared with the table after each run. Light timing, the timer itself and button debouncing are outside this problem.

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.

17 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 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Press, One Full Crossing

Input
btn tmo per cycle: 00 10 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Expected output
rom_wrong = 0, wrong_cycles = 0, cycles = 24

The press moves the light from cars go to cars slow. Each timeout moves it on, through all stop and walk, and back to cars go.

Run samples executes all 3 public checks. Check all tests runs 17 checks on the server.

Icarus Verilog + Yosys · server