R9.1.1 The Counter That Hid Its Missing Reset

EasyFixIcarus Verilog + Yosys · serverReview the topic

A watchdog counter passed every power-on test and then ignored a reset in the lab. Give it a real reset.

Hardware context: A watchdog counter that reloads 12 and barks at 0; and a mask generator with a WIDTH parameter. Give the watchdog a real asynchronous reset in place of its start value.

A watchdog guards a bus bridge. Its counter starts at 12 and goes down by one at each clock edge. A kick reloads 12. When the count reaches 0 it stays there and bark goes to 1. Every simulation passed: the count started at 12 and no X ever showed.

In the lab the board resets the bridge while it runs. After such a reset the watchdog went on from its old count and barked early. The counter is declared with a two-state type and a start value, and nothing in the design reads rst_n.

This is a Fix problem. Change the design so that rst_n loads 12, without a clock edge, whenever it is low. Each test first runs the watchdog for a while and only then resets it. A start value cannot pass for a reset.

Brief: ports clk, rst_n and kick in, left[3:0] and bark out. Rising edge. Asynchronous active-low reset to 12. A kick wins over the countdown. The count stops at 0. bark is 1 exactly while left is 0. 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.

Signals in the Timeline

SignalWidthRole
script36input of each check
Full specification
The module (keep the name and the ports)
module watchdog (
  input  logic       clk,
  input  logic       rst_n,        // asynchronous, active-low
  input  logic       kick,         // 1: reload the count at this edge
  output logic [3:0] left,         // edges left before the watchdog barks
  output logic       bark          // 1 while left is 0
);
  // ...
endmodule
RuleCorrect watchdog
resetWhile rst_n is 0, left is 12 and bark is 0. The reset acts at once, with no clock edge.
kickAt an edge out of reset with kick = 1, left becomes 12.
countdownAt an edge out of reset with kick = 0, left goes down by 1. At 0 it stays 0.
bark1 exactly while left is 0.

Each test runs a previous life first: one kick and five more edges. Then rst_n is held low across one edge, and 12 steps of one edge each follow. The result is left and bark after every step.

A step may hold rst_n low across its edge, or pulse it low for 1 ns and release it before the edge. In both, left must be 12 and bark 0 one nanosecond after rst_n falls. The field reloaded_before_the_edge lists the steps where that held.

Examples

Example 1

Count Down After a Reset
Input
idle x12
Output
left_step0 = 11, left_step1 = 10, left_step2 = 9, left_step3 = 8, left_step4 = 7, left_step5 = 6, left_step6 = 5, left_step7 = 4, left_step8 = 3, left_step9 = 2, left_step10 = 1, left_step11 = 0, bark_step11 = yes

The previous life left the count at 7. The reset must load 12 again, so the twelve steps read 11 down to 0. bark is 1 at the last step.

Example 2

A Kick Reloads the Count
Input
idle x4, kick, idle x3, kick x2, idle x2
Output
left_step0 = 11, left_step1 = 10, left_step2 = 9, left_step3 = 8, left_step4 = 12, left_step5 = 11, left_step6 = 10, left_step7 = 9, left_step8 = 12, left_step9 = 12, left_step10 = 11, left_step11 = 10

Four edges take the count to 8. The kick loads 12, and the count goes down again from there.

Example 3

A Reset in the Middle of the Run
Input
idle x5, reset across the edge, idle x6
Output
left_step0 = 11, left_step1 = 10, left_step2 = 9, left_step3 = 8, left_step4 = 7, left_step5 = 12, left_step6 = 11, left_step7 = 10, left_step8 = 9, left_step9 = 8, left_step10 = 7, left_step11 = 6, reloaded_before_the_edge = {5}

The reset at step 5 loads 12 while rst_n is low, before the edge. The count goes down from 12 at the next step.

Constraints and Contract

  • kick is a known 0/1 value and changes while clk is low.
  • Keep the module name and the ports. You may change any declaration inside the module.

Hints

Hint 1

Search the design for rst_n. A port that nothing reads cannot reset anything.

Hint 2

The start value at the declaration runs once, at time 0 of a simulation. Ask what brings the count back to 12 the second time.

Hint 3

Put the reset in the sensitivity list and in the first branch: always_ff @(posedge clk or negedge rst_n), then if (!rst_n). Declare the state with a four-state type so that a missing reset shows as X.

What the grader checks: Six directed and ten seeded scripts of twelve steps each run after a previous life and a reset. left and bark after every edge, and their values one nanosecond after each reset begins, are compared with an independent model. Passing shows the reset reloads the count on these scripts; the synthesis check adds the latch count.

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

Count Down After a Reset

Input
idle x12
Expected output
left_step0 = 11, left_step1 = 10, left_step2 = 9, left_step3 = 8, left_step4 = 7, left_step5 = 6, left_step6 = 5, left_step7 = 4, left_step8 = 3, left_step9 = 2, left_step10 = 1, left_step11 = 0, bark_step11 = yes

The previous life left the count at 7. The reset must load 12 again, so the twelve steps read 11 down to 0. bark is 1 at the last step.

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

Icarus Verilog + Yosys · server