Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

Sequence generator: a counter with decode logic, live

A sequence generator outputs a fixed pattern of bits, one per clock, over and over. This one generates 1, 0, 1, 1, 0, 0, 1, 0: a 3-bit counter steps through states 0 to 7, and a small decoder turns each state into that state's output bit, Z = Q2'Q0' + Q2'Q1 + Q1Q0'.

Counter plus decode is the most direct way to generate any repeating sequence: give each position in the sequence its own counter state, write a truth table from state to output, and minimize it. Here the counter is a 3-bit synchronous counter built from D flip-flops with a clear (Q0 toggles every clock, Q1 toggles when Q0 is 1, Q2 when Q1 and Q0 are both 1), and the output logic is the minimal sum of products of the pattern, which you can check with the Karnaugh map solver (minterms 0, 2, 3 and 6). A different pattern only changes the decoder. Another classic design feeds back a shift register (as in the ring counter or the LFSR), which can use fewer gates for some patterns; the counter design works for any pattern up to the counter's length. The live circuit opens with CLR on, because flip-flops start in an unknown state: turn CLR off and Z plays the sequence.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “Sequence generator”, https://digiwleea.wleeaf.dev/tools/build/sequence-generator/

What you need

Step by step

  1. Place a clock CLK, an input CLR, three D flip-flops with clear and probes Q2, Q1, Q0 and Z.
  2. Make a counter: D0 = NOT Q0, D1 = Q1 XOR Q0, D2 = Q2 XOR (Q1 AND Q0), all on one clock and one clear.
  3. Write the pattern's truth table, one row per state (below), and minimize it: Z = Q2'Q0' + Q2'Q1 + Q1Q0'.
  4. Build Z from three ANDs and two ORs. Turn CLR off and watch Z repeat 1, 0, 1, 1, 0, 0, 1, 0.

State and output

StateQ2 Q1 Q0Z
00001
10010
20101
30111
41000
51010
61101
71110

Before the page is built, a 22-clock run (a clear, the pattern twice and two more steps, then a clear in the middle and a restart) is checked on Q2, Q1, Q0 and Z after every clock.

You can also read the full theory in the lesson on counters. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

More builds: State machines

All 246 build guides, by topic

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the Sequence generator in the lab →

Frequently asked

What is a sequence generator?

A sequential circuit that outputs a predefined sequence of bits, one per clock cycle, repeating it. It is used for test patterns, control timing and serial codes.

How do you design a sequence generator?

One way is a counter plus decode logic: use a counter with at least as many states as the sequence is long, write a truth table from each state to its output bit, and minimize it. Another is a shift register with feedback logic chosen so it shifts out the sequence.

How many flip-flops does a sequence generator need?

With the counter method, enough to count the sequence length: 3 flip-flops for up to 8 bits, 4 for up to 16. Shift-register designs need enough flip-flops that every position in the sequence has its own distinct state.

What is the difference between a sequence generator and a sequence detector?

A generator produces a pattern on its output; a detector watches an input stream and signals when a pattern appears, like the 1011 sequence detector.