Problems

15. Find the bug: pulse stretcher

MediumFind the bugAbout 15 min
verificationcounterspulse stretchingtest writing

Write a test that passes the correct design and fails every buggy version.

The spec: a one-cycle pulse on trig is too short for a slow receiver, so stretch it.

  • When a rising clock edge sees trig = 1, out goes to 1 after that edge and stays 1 for exactly 3 clock cycles, then returns to 0.
  • It is retriggerable: an edge that sees trig = 1 while out is already 1 restarts the 3-cycle window from that edge.
  • out comes from registers. rst (synchronous, active high) makes out 0 and cancels any window. Registers start unknown, so begin with a reset.

Ports

Module stretch3

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
trigin1Trigger pulse.
outout1Stretched pulse.

Example

trig is 1 at edge 1 only: out is 1 after edges 1, 2 and 3, and 0 after edge 4.

Writing the test

The test is a table of steps, as on the Verilog playground. Each step can set inputs, tick the clock (clk) a number of times, then check outputs. Inputs start at 0 and registers start unknown, so begin with a reset. It must pass the correct design and fail all 5 buggy versions.

{ "set": { "rst": 0, "en": 1 }, "tick": 3, "expect": { "count": 3 }, "note": "counts up" }

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Test (JSON)test.json
14px

1 step, 0 with checks.

Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.

Find the bug: pulse stretcher: Verilog interview question | breadboardhub