Codiode

Johnson Counter

MediumVerilog / SystemVerilogBuild

A Johnson (twisted ring) counter feeds the inverted last bit back to the front. With 4 flip-flops it steps through 8 states, and only one bit changes per step.

The module evaluates a 4-bit sequence. On every clock cycle, the current 4-bit value shifts left by one position. The new least significant bit is populated with the inverted value of the previous most significant bit.

The clock triggers on the positive edge. The reset is asynchronous and active-low. When reset is asserted, the output evaluates to 4'b0000. The output is registered. Priority is given to the asynchronous reset over the clock.

Cycle 1: rst_n=0 → out=4'b0000 (0)
Cycle 2: rst_n=1 → out=4'b0001 (1)
Cycle 3: rst_n=1 → out=4'b0011 (3)
Cycle 4: rst_n=1 → out=4'b0111 (7)
Cycle 5: rst_n=1 → out=4'b1111 (15)
Cycle 6: rst_n=1 → out=4'b1110 (14)
Cycle 7: rst_n=1 → out=4'b1100 (12)
Cycle 8: rst_n=1 → out=4'b1000 (8)
Cycle 9: rst_n=1 → out=4'b0000 (0)

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Asynchronous active-low reset; sets out to 4'b0000
out output 4 Registered counter output

Constraints

  • Clock edge is posedge.
  • Reset is asynchronous and active-low.
  • Output resets to 4'b0000.
  • Shift direction is left; out[0] receives the inverted value of out[3].
  • The design must infer exactly 4 flip-flops. Do not use a standard binary counter with combinational decoding.

Topics

sequentialfsmcounter

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Sequential RTL

Problem 18 of 26 in the Sequential RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.