Problems

9. Find the bug: mod-12 counter

EasyFind the bugAbout 15 min
verificationcounterstest writing

This time you write the test, not the design. Several engineers implemented the spec below; one version is correct and the others each hide one bug. Write a step table that passes the correct design and fails every buggy one.

The spec: a counter that counts 0, 1, ..., 11 and then wraps to 0, like the hours on a 12-hour clock face numbered from 0.

  • On each rising clock edge: rst = 1 sets count to 0; otherwise, when en = 1, count goes up by one, and from 11 it goes to 0; when en = 0, count holds (even at 11).
  • tc (terminal count) is combinational: it is 1 when count is 11 and en is 1, meaning "the next edge wraps".
  • rst is synchronous and active high. Registers start unknown, so begin your test with a reset.

Ports

Module mod12

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
enin1Count enable.
countout4The count, 0 to 11.
tcout1count is 11 and en is 1.

Example

After reset count = 0. With en = 1, eleven edges later count = 11 and tc = 1; one more edge gives count = 0 and tc = 0.

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: mod-12 counter: Verilog interview question | breadboardhub