EN

Johnson code

Twisted ring counter: 2n states with n flip-flops, changing a single bit each time

Number systems: Binary and hexadecimal Gray code Johnson code BCD codes Floating and fixed point Parity, Hamming and CRC

Johnson counter step by step

Choose the number of bits and step with the clock. You can type the state or the code, or click a flip-flop in the drawing to change its bit, as if noise had changed it.

State

Each clock pulse shifts the bits one place to the left; the inverted most significant bit enters on the right (Q0). Ones enter until the register is full, then zeros enter until it is empty.

Timing diagram

Johnson code table

In red, the only bit that changes from the previous state. The two-input AND gate in each row is 1 only in that state. Click a row to load it into the counter.

Lock-up states and correction

If at power-up, or because of noise, the register holds a code that is not in the sequence, the shift with inverted feedback does not fix it: the counter runs round another cycle and the decoding gates give false outputs. Click a cycle to load it into the counter, or change a bit in the drawing.

There are three remedies: reset the register at power-up, detect an invalid code and force a reset, or change the feedback. The simulator's correction uses \(D_0 = \overline{Q_{n-1}}\cdot(Q_0 + \overline{Q_{n-2}})\): in valid states it equals \(\overline{Q_{n-1}}\), but it breaks the lock-up cycles. It is enough up to 5 bits, the case of the CD4017, which has similar logic; with more bits some cycles remain and another solution is needed.

What the Johnson code is

The Johnson code, also called twisted ring or Möbius code, is the sequence of a shift register whose input receives the inverted output of the last flip-flop. Starting from all zeros, ones enter until it is full and then zeros until it is empty: with 3 bits, 000, 001, 011, 111, 110, 100 and back to 000.

\[ D_0 = \overline{Q_{n-1}} \qquad k = \begin{cases} u & \text{if } Q_0 = 1 \\ 2n - u & \text{if } Q_0 = 0 \end{cases} \qquad u = \text{number of ones} \]
Example with 4 bits

1100 has Q0 = 0 and two ones: it is state 8 − 2 = 6. The boundary between ones and zeros is between Q2 and Q1, so it is detected by the gate \(Q_2\cdot\overline{Q_1}\). No other code in the sequence has Q2 = 1 and Q1 = 0.

Comparison with other counters

CounterStates with n flip-flopsFlip-flops for 10 statesDecoding one stateBits changing per step
Binary2ⁿ4n-input ANDup to n
Gray2ⁿ4n-input AND1
Johnson2n52-input AND1
Ringn10None: one output per state2

Where it is used

Related: shift registers, flip-flops, counters and Gray code.