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

The race-around condition in a JK flip-flop, live

The race-around condition is what happens when a level-triggered JK latch has J = K = 1 while its clock is high: the output toggles, the new value feeds straight back to the gates, it toggles again, and it keeps toggling for as long as the clock stays high, so the final value is unpredictable. This live latch shows it: the simulator reports the output as oscillating.

A JK latch made of four NAND gates feeds its own outputs back to its input gates (J is gated with Q' and K with Q), which is what makes J = K = 1 a toggle instead of the SR latch's forbidden input. But with a level-triggered clock, the toggle is not a single event: as soon as Q changes, the input gates see the new Q and Q' and start the next toggle, and this repeats every few gate delays while CLK is 1. In real hardware the output oscillates and settles at whatever value it happens to have when the clock falls; in this zero-delay simulator the loop never settles, and the simulator marks the outputs as oscillating instead of 0 or 1. The cure is to make sure the toggle can happen only once per clock pulse: the master-slave JK flip-flop (two latches with opposite clocks), or an edge-triggered flip-flop, or a clock pulse shorter than the gate delay round the loop, which is hard to guarantee. This latch also has an active-low clear, CLR, on the Q' gate: without it, a latch that has just powered up could not be set at all in this simulator, because J is gated by Q' and K by Q, and both start unknown. Try it: the circuit opens with CLR = 0 (Q cleared to 0) and J = K = 1. Set CLR to 1, then set CLK to 1 and watch Q race. Before the page is built, a 12-step sequence is checked: clear, set, hold, reset, hold, the oscillation with J = K = 1 and CLK = 1, a clear that stops it, and a clean set afterwards.

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 inputs J, K, CLK, CLR and probes Q and Qbar.
  2. Cross-couple two NAND gates as an SR latch with active-low inputs n1 and n2, and give the Q' gate a third input, CLR, so that CLR = 0 clears the latch.
  3. Gate the inputs with the clock and the outputs: n1 = NAND(J, CLK, Q'), n2 = NAND(K, CLK, Q).
  4. Clear it (CLR = 0, then 1) and check the normal cases with CLK = 1: J = 1, K = 0 sets Q; J = 0, K = 1 resets it; CLK = 0 holds.
  5. Now hold CLK at 1 with J = K = 1: Q never settles. That is the race-around condition.

The checked sequence

StepCLRJKCLKQWhat happens
100000Clear
210000Clear released: hold
311011Set
411001Clock low: hold
510101Inputs change, still holding
610110Reset
710100Hold
811100J = K = 1, but the clock is low: hold
91111oscillatesRace-around: toggles for as long as CLK is 1
1011100 or 1Clock low again: the latch keeps whichever value it had
1101100Clear: a known state again
1211011A normal set works

Step 10 cannot be predicted, which is the whole problem: the value left behind depends on exactly when the clock fell during the oscillation. A master-slave or edge-triggered JK flip-flop gives a single, predictable toggle per clock instead; see the JK flip-flop lesson and the JK flip-flop build.

You can also read the full theory in the lesson on the JK flip-flop. 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 adderfrequency divider (by 2, 4 and 3)switch 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 subtractor74181 ALUCMOS AOI gate (AOI21)D latch vs D flip-flop74LS47 BCD to 7-segment decoder74HC595 shift register7400 quad NAND gate chip7402 quad NOR gate chip7404 hex inverter chip7408 quad AND gate chip7432 quad OR gate chip7486 quad XOR gate chip7474 dual D flip-flop74HC165 shift registerCD4017 decade counter74LS283 4-bit adder74LS90 decade counter74HC161 4-bit counter74HC151 8-to-1 multiplexer74HC157 quad 2-to-1 multiplexer74HC139 dual 2-to-4 decoderCD4511 BCD to 7-segment decoder7492 divide-by-12 counter7493 4-bit binary counter74HC244 octal buffer74HC373 octal latch74HC374 octal D flip-flopTurnstile state machine1-to-2 demultiplexerhalf adder using 2:1 multiplexersregister file (4 x 4-bit)

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 Race-around condition (JK latch) in the lab →

Frequently asked

What is the race-around condition?

In a level-triggered JK latch with J = K = 1, the output toggles while the clock is high, and because the outputs feed back to the input gates, it toggles again and again until the clock goes low. The final state is unpredictable.

Why does the race-around condition occur?

Because the clock pulse is longer than the time it takes a change of Q to travel back through the input gates. During one long clock pulse the latch can toggle many times instead of once.

How do you avoid the race-around condition?

Use a master-slave JK flip-flop, where the master latch is open while the clock is high and the slave only while it is low, so the output can change only once per clock; or use an edge-triggered flip-flop. Making the clock pulse shorter than the loop delay also works in theory but is hard to guarantee.

Does the race-around condition happen in an SR latch?

No. In an SR latch the input S = R = 1 is simply forbidden; there is no feedback from the outputs into the input gates, so there is nothing to race. The JK latch adds that feedback to turn J = K = 1 into a toggle, and the race comes with it.