Problems

21. Find the bug: 101 detector

MediumFind the bugAbout 20 min
verificationfsmsequence detectiontest writing

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

The spec: one bit arrives on din at each rising clock edge. found is 1 for the clock cycle right after the edge that received the final 1 of the pattern 1, 0, 1, and 0 otherwise (a Moore output). Matches may overlap: in 10101 the middle 1 ends the first match and starts the second, so found is 1 twice.

rst (synchronous, active high) forgets everything received so far. Registers start unknown, so begin with a reset.

Ports

Module det101

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
dinin1Serial input.
foundout11 for one cycle after each 101.

Example

Input 1, 0, 1, 0, 1: found is 1 after the third bit and again after the fifth.

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 4 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: 101 detector: Verilog interview question | breadboardhub