Problems

10. Self-correcting Johnson counter

MediumWrite the moduleAbout 20 min
sequentialcountersjohnsonillegal states

A 4-bit Johnson (twisted ring) counter shifts left by one place on every clock edge and feeds the inverted top bit back into bit 0. From 0000 it visits eight states and repeats: 0000, 0001, 0011, 0111, 1111, 1110, 1100, 1000, then 0000 again.

The other eight 4-bit patterns are illegal. legal is a combinational output that is 1 when q holds one of the eight legal states.

On each rising clock edge, in priority order: 1. rst = 1: q becomes 0000. 2. load = 1: q becomes d, even if d is illegal (this is how a test can force a bad state). 3. q is illegal: q becomes 0000 (the counter recovers by itself). 4. Otherwise q takes the next state in the sequence.

rst is synchronous and active high.

Ports

Module johnson4

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
loadin1Load d into q.
din4Value to load.
qout4Counter state.
legalout11 when q is one of the eight legal states.

Example

After reset q = 0000; three edges later q = 0111. Loading 0101 gives legal = 0, and the next edge (with load = 0) gives q = 0000.

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

Verilogjohnson4.v
14px
Loading the editor…

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.

Self-correcting Johnson counter: Verilog interview question | breadboardhub