R10.5.1 The Reset That Looked Fine

MediumDebugIcarus Verilog + Yosys · serverReview the topic

A strobe generator passed every power-on test and then misbehaved after a warm reset. Find the first bad cycle, name the cause, and fix it.

Hardware context: A strobe generator with a run flag, a period register and a counter; and a command unit with a mode bit, an enable, a limit table and an opcode register. Find the first bad cycle of the strobe generator after a warm reset, name the cause, and fix it.

A strobe generator times a sensor. start sets it running and stop halts it. While it runs, count steps from 0 up to the period. tick is 1 for one cycle after count equals the period. A reset must leave it idle with the period at 3. Every power-on test passed, and Lint was clean.

In the lab the system resets the block again while it is running. After that warm reset the sensor received strobes that nobody had asked for. The bench below repeats the lab. It applies a power-on reset, a run, and a reset across a clock edge. Then come a second run and a short reset pulse between two edges.

Step 1: run the failing test. Find the first cycle where count or tick shows a value the brief does not give, and name the signal. Step 2: choose the cause from five real bugs. Each one first goes wrong in a different place.

Step 3 is optional: fix the design and run the tests. Each test first runs the design for a while, then resets it, so state that the reset misses is not hidden.

Signals in the Timeline

SignalWidthRole
script96input of each check
Full specification
The generator's ports (keep the name and the ports)
module strobe_gen (
  input  logic       clk,
  input  logic       rst_n,        // asynchronous, active-low
  input  logic       start,        // 1: begin counting from the next edge
  input  logic       stop,         // 1: stop; wins over start
  input  logic       cfg_we,       // 1: load the period from cfg_period
  input  logic [2:0] cfg_period,
  output logic [2:0] count,
  output logic       tick
);
  ...
endmodule
RuleCorrect generator
resetWhile rst_n is 0: not running, period 3, count 0, tick 0. Asynchronous: it acts without a clock edge.
run flagAt an edge out of reset: stop clears it; otherwise start sets it. stop wins when both are 1.
periodAt an edge out of reset with cfg_we = 1, the period becomes cfg_period.
runningThe run flag was 1 before the edge. If count equals the period, count becomes 0 and tick is 1. Otherwise count goes up by 1 and tick is 0.
idleThe run flag was 0 before the edge. count is 0 and tick is 0.

Cycle 0 is the time before the first rising edge. Each rising edge starts the next cycle. A signal's value in cycle N is its value at the end of that cycle. Inputs change while clk is low.

CyclesWhat the bench applies before the edge that starts them
1reset held low across the edge (power-on reset)
2 to 8writes period 2, starts, lets it run
9reset held low across the edge while it runs
10, 11idle: no start
12 to 17starts again with the default period
18a 2 ns reset pulse that ends before the edge
19, 20idle: no start

The fix tests first run a previous life: period 6, running. They reset the design across one edge, then apply 12 steps of one edge each. They record count and tick after every edge. In a step with a reset, count and tick must also be 0 one nanosecond after rst_n falls, before any edge. The field cleared_before_the_edge lists those steps. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.

Diagnose the Failing Run

The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.

Log

Waveform

Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.

Step 1 · The first bad cycle and signal
Step 2 · The cause

Step 3 is optional: fix the code in the editor, then run the tests.

Examples

Example 1

Idle After Reset
Input
idle x12
Output
count_step0 = 0, tick_step0 = no, count_step1 = 0, tick_step1 = no, count_step2 = 0, tick_step2 = no, count_step3 = 0, tick_step3 = no, count_step4 = 0, tick_step4 = no, count_step5 = 0, tick_step5 = no, count_step6 = 0, tick_step6 = no, count_step7 = 0, tick_step7 = no, count_step8 = 0, tick_step8 = no, count_step9 = 0, tick_step9 = no, count_step10 = 0, tick_step10 = no, count_step11 = 0, tick_step11 = no

The design ran in its previous life. The reset must stop it, so count and tick stay 0 for all twelve steps.

Example 2

Start with the Default Period
Input
start, idle x11
Output
count_step0 = 0, tick_step0 = no, count_step1 = 1, tick_step1 = no, count_step2 = 2, tick_step2 = no, count_step3 = 3, tick_step3 = no, count_step4 = 0, tick_step4 = yes, count_step5 = 1, tick_step5 = no, count_step6 = 2, tick_step6 = no, count_step7 = 3, tick_step7 = no, count_step8 = 0, tick_step8 = yes, count_step9 = 1, tick_step9 = no, count_step10 = 2, tick_step10 = no, count_step11 = 3, tick_step11 = no

The previous life used period 6. After the reset the period is 3 again: count goes 1, 2, 3, then 0 with tick = 1.

Example 3

A Reset While Running
Input
start, idle x3, reset across the edge, idle x3, start, idle x3
Output
count_step0 = 0, tick_step0 = no, count_step1 = 1, tick_step1 = no, count_step2 = 2, tick_step2 = no, count_step3 = 3, tick_step3 = no, count_step4 = 0, tick_step4 = no, count_step5 = 0, tick_step5 = no, count_step6 = 0, tick_step6 = no, count_step7 = 0, tick_step7 = no, count_step8 = 0, tick_step8 = no, count_step9 = 1, tick_step9 = no, count_step10 = 2, tick_step10 = no, count_step11 = 3, tick_step11 = no, cleared_before_the_edge = {4}

The reset at step 4 stops the generator. count stays 0 until the start at step 8.

Constraints and Contract

  • Inputs are known 0/1 values and change while clk is low.
  • Keep the module name and the ports.

Hints

Hint 1

The log names the first failing check. Read the waveform one cycle at a time from there, and ask what the brief gives for count in that cycle.

Hint 2

Nothing pulsed start after the reset in cycle 9. Which piece of state says "running", and what does the reset do to it?

Hint 3

Compare the power-on reset with the warm one. Before the first start, the state you suspect was unknown. Ask which branch an if takes for an unknown condition.

What the grader checks: The failing run is simulated live with the shipped design. The bench simulates the correct generator and each buggy one. The first bad cycle and every option's first wrong value come from those runs. The optional fix is compared with an independent model on seven directed and nine seeded scripts. Each script runs after a previous life and a reset.

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.

16 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

Report a problem with this page

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

Idle After Reset

Input
idle x12
Expected output
count_step0 = 0, tick_step0 = no, count_step1 = 0, tick_step1 = no, count_step2 = 0, tick_step2 = no, count_step3 = 0, tick_step3 = no, count_step4 = 0, tick_step4 = no, count_step5 = 0, tick_step5 = no, count_step6 = 0, tick_step6 = no, count_step7 = 0, tick_step7 = no, count_step8 = 0, tick_step8 = no, count_step9 = 0, tick_step9 = no, count_step10 = 0, tick_step10 = no, count_step11 = 0, tick_step11 = no

The design ran in its previous life. The reset must stop it, so count and tick stay 0 for all twelve steps.

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

Icarus Verilog + Yosys · server