Skip to content
BetterDL

State decoding

Also called: count decoding, counter decoding, full state decoding

Logic that watches a counter's outputs and produces a 1 in one particular state, for example to trigger a clear, a terminal-count flag or an event.

Counters are often used to make something happen at a particular count: clear at 9, flash a light at 0, fire an event every 1000 cycles. The logic that spots that count is a state decoder.

Full decoding uses every bit. To detect one state of an n-bit counter, AND all n outputs, complementing the ones that should be 0. State 5 of a 3-bit counter is 101, so its decoder is . Decoding every state at once is just a decoder on the counter's outputs.

Decoders are cheaper for some counters:

One warning: a decoder on a ripple counter also sees the transient states and can put out glitches. Decode a synchronous counter, or register the decoded output, when the signal must be clean.

0000
0010
0100
0110
1000
1011
1100
1110

Worked examples

Example

Decoding state 6 of a 4-bit counter

Build a signal that is 1 only when a 4-bit counter shows 6.

  1. 1.

    6 = 0110, so Q3 = 0, Q2 = 1, Q1 = 1, Q0 = 0.

  2. 2.

    AND the true bits and complement the false ones: .

  3. 3.

    Check 7 = 0111: Q0 = 1 makes = 0, so the output is 0 ✓.

Example

Decoding a Johnson counter

A 4-bit Johnson counter runs 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001 (bits A B C D, left to right). Decode 1100.

  1. 1.

    1100 is the only state where B = 1 and C = 0 next to each other.

  2. 2.

    So the decoder is just , a 2-input AND, even though the counter has 4 bits.

Common mistakes

  • Using only the 1 bits. For 0110, is also 1 at 1110 and 0111; you need the complemented bits unless those states never occur.

  • Decoding a ripple counter and using the output as a clock or clear without worrying about transient-state glitches.

Practice State decoding

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

State decoding is taught in Counters.