Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

How to build a frequency divider: divide a clock by 2, 4 and 3

A frequency divider, or clock divider, turns a clock into a slower one. A D flip-flop that feeds its own Q' back to D toggles on every clock edge, so its output runs at half the clock frequency; a second toggle stage clocked by the first divides by 4; and a mod-3 counter divides by 3. This live circuit has all three, side by side, driven by one CLK.

Each toggle stage halves the frequency, so a chain of n stages divides by 2 to the n: that chain is exactly a ripple counter, read one output at a time. To divide by a number that is not a power of two, use a counter that wraps after N states and take one of its bits: here a two-flip-flop counter steps 00, 01, 10 and back, and its top bit is high for one clock in three. That output has a one-third duty cycle; a 50% duty cycle for an odd divisor needs a second set of flip-flops on the falling edge, combined with the first. Larger divisors work the same way, as in the mod-5 counter and the decade counter (divide by 10). Microcontrollers use dividers like these, often called prescalers, to run timers and serial ports at a fraction of the main clock. Every output is checked at the end of each of 24 clock cycles before the page is built.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

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 →

What you need

Step by step

  1. Place a clock CLK, an input CLR, and probes DIV2, DIV4 and DIV3.
  2. Divide by 2: a D flip-flop clocked by CLK with its Q' wired back to D. Its Q is DIV2.
  3. Divide by 4: a second toggle flip-flop clocked by the first one's Q', so it flips each time DIV2 falls. Its Q is DIV4.
  4. Divide by 3: two flip-flops on CLK with D0 = NOR(Q1, Q0) and D1 = Q0. Q1 is DIV3.
  5. Wire CLR to every flip-flop's clear, pulse it once, then run the clock: DIV2 flips every edge, DIV4 every second edge, DIV3 is high one edge in three.

Outputs after each clock edge

Edges since CLRDIV2DIV4DIV3
0000
1100
2011
3110
4000
5101
6010
7110
8001
9100
10010
11111

DIV2 repeats every 2 clock edges, DIV4 every 4 and DIV3 every 3, so with a 12 MHz clock they would run at 6, 3 and 4 MHz. Because each toggle stage waits for the one before it, DIV4 changes a little after DIV2 in real hardware; when that skew matters, clock every stage from CLK as in a synchronous counter.

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.

Build more parts from gates

half adderfull adderhalf subtractorfull subtractor2:1 multiplexer4:1 multiplexerXOR gate from NAND gates2-to-4 decoderSR latchD flip-flopJK flip-flopT flip-flop4-bit shift register4-bit ripple carry adderD latch1-to-4 demultiplexer4-bit magnitude comparator4-bit ring counter4-bit Johnson counter4-to-2 priority encoder4-bit synchronous counter3-to-8 decoder8-to-1 multiplexer4-bit carry lookahead adderhalf adder from NAND gates2-bit comparatorBCD to 7-segment decoder4-bit up/down counterdecade counter2-bit multiplier4-bit ALU4-bit array multiplierNOT, AND, OR and NOR from NANDNOT, OR, AND and XOR from NORfull adder from NAND gatesSR latch from NAND gatesparity generator and checker4-bit adder/subtractorBCD adder4-bit universal shift registermod-6 counter4-bit ripple counterbinary to Gray code converterhalf adder from NOR gatesfull adder from NOR gates4-bit register with parallel load1011 sequence detectorbinary to BCD converterD flip-flop from NAND gates1-bit ALUCMOS inverterCMOS NAND gateCMOS NOR gatePISO shift registerSR flip-flop from NAND gatesBCD to excess-3 code converterHamming (7,4) code encoder and correctortraffic light controller4-bit barrel shifterCMOS AND gateCMOS OR gateCMOS XOR gate1-bit magnitude comparatorhalf subtractor from NAND gatesfull subtractor from NAND gates8-to-3 encoderGray to binary converter4-to-16 decoderfull adder using 4:1 multiplexersedge detectorserial adder4-bit carry-select adder4-bit Kogge-Stone adder4-bit carry-skip adder4x4 Wallace tree multiplier8-bit adderswitch debouncer (SR latch)3-bit Gray code counterMealy machine (1011 detector)master-slave JK flip-flop (NAND)half subtractor from NOR gates1-to-8 demultiplexerexcess-3 to BCD code convertervending machine FSM4-bit carry-save adder3-bit synchronous counter (JK)CMOS transmission gatetri-state buffer (CMOS)2-to-1 mux from transmission gatesmod-5 counterflip-flop conversion (JK to D)8-bit ALUdecimal to BCD encoderBCD to decimal decoder4-to-1 mux from 2-to-1 muxesXOR gate from NOR gates4-bit LFSR74LS138 decoderBCD subtractor

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 frequency divider (by 2, 4 and 3) in the lab →

Frequently asked

What is a frequency divider?

A circuit whose output clock runs at an exact fraction of its input clock: 1/2, 1/4, 1/3 and so on. In digital logic it is built from flip-flops, as a toggle stage for divide by 2 or as a counter that wraps after N states for divide by N.

How do you divide a clock frequency by 2?

Use one D flip-flop with its Q' output wired back to its D input. On every clock edge it stores the opposite of its current state, so it toggles once per clock period and its output has half the frequency, with a 50% duty cycle.

How do you divide a clock by 3?

Build a counter with three states, such as two flip-flops that go 00, 01, 10 and back, and use one of its bits as the output. Here D0 = NOR(Q1, Q0) and D1 = Q0, and Q1 is high for one clock in three. For a 50% duty cycle, add flip-flops on the falling clock edge and combine their output with the rising-edge one.

Is a frequency divider the same as a counter?

Essentially yes: every counter is a frequency divider, since its lowest bit runs at half the clock, the next at a quarter, and its wrap-around repeats once every N clocks. A divider is a counter used for its timing rather than its count.

What is a clock prescaler?

A frequency divider in front of a timer or peripheral, usually with a selectable ratio such as 1, 8, 64 or 256, so the peripheral can count slowly without slowing the main clock.