Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Build a reloadable countdown timer

Q079·Free·SystemVerilog

Build a reloadable countdown timer

Difficulty
Medium
Topic
RTL Design
Language
SV
Interview prompt

Question

Design a parameterized countdown timer with load, load_value, busy, and a one-cycle expired pulse. Add a BFM task that starts a nonzero delay and waits for expiry. W is a positive integer. The environment resets the timer, initializes load=0, and serializes calls to the BFM task.

Candidate starting point

Implementation scaffold

module countdown_timer #(
  parameter int unsigned W = 16
) (
  input  logic         clk,
  input  logic         rst_n,
  input  logic         load,
  input  logic [W-1:0] load_value,
  output logic         busy,
  output logic         expired
);
  logic [W-1:0] count_q;

  always_ff @(posedge clk or negedge rst_n) begin : timer_state
    // TODO: Implement timer_state using the supplied state and interface.
  end
endmodule

interface timer_if #(parameter int unsigned W = 16) (input logic clk);
  logic load, busy, expired;
  logic [W-1:0] load_value;
  clocking cb @(posedge clk);
    default input #1step output #0;
    output load, load_value;
    input  busy, expired;
  endclocking
  modport TB (clocking cb);
endinterface

class timer_bfm #(int unsigned W = 16);
  virtual timer_if #(W).TB vif;
  function new(virtual timer_if #(W).TB vif); this.vif = vif; endfunction

  task start_and_wait(input logic [W-1:0] value);
    // TODO: implement this body.
  endtask
endclass
Reviewed example

Trace one case

Input
load value 3, observe three countdown edges; later load value 0
Expected output
busy during the first two countdown edges and expired pulses on the third; zero load pulses expired immediately and remains idle

A nonzero N expires after exactly N active edges, while load priority and the zero special case each produce one-cycle pulses.

What to cover

Requirements

  1. Loading has priority over counting.
  2. A value N expires after N active countdown edges.
  3. expired is a pulse, not a permanent idle indicator.
  4. A zero load expires immediately and leaves the timer idle.
Exact question handoffPractice Q079

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

RTL Logic and State

Review combinational logic, sequential state, counters, arithmetic, and finite-state machines.

  • RTL Design
  • Counter
  • Pulse
  • Priority
RTL Logic and State →
Continue practicing

Related questions

Q221 · FSMsDebounce a noisy active-low buttonMediumP→Q015 · FSMsControl a request/acknowledge handshakeMedium→
ASIC.FYI · Learn silicon end to end.info@asic.fyi