10. Self-correcting Johnson counter
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
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
load | in | 1 | Load d into q. |
d | in | 4 | Value to load. |
q | out | 4 | Counter state. |
legal | out | 1 | 1 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.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
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.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.