Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 57 ยท Latches and Flip-Flops

JK and T Flip-Flops

Learn SR, JK, T and D flip-flops side by side: characteristic tables and equations, excitation tables, conversions between types, and toggling in Python.

The D flip-flop is not the only way to store a bit on a clock edge. Three relatives, the SR, JK and T flip-flops, give the designer different ways to control what happens: set it, reset it, hold it, or flip it. They look redundant, yet each one used to be the best fit for certain circuits, and the vocabulary survives in textbooks, exams and the design of counters and state machines.

This lesson compares all four types using the two standard descriptions: the characteristic table (given the inputs and the current state, what is the next state?) and the excitation table (given a wanted state change, which inputs do I need?). You will also convert one flip-flop type into another, and watch a toggle flip-flop divide a clock in half.

The characteristic table and equation

Let Q be the current state and Qโบ (or Q(next)) the state after the next active clock edge. A characteristic table lists Qโบ for each input combination, and the characteristic equation is its algebraic form.

Type Inputs Behaviour Characteristic equation
D D Qโบ = D Qโบ = D
T T T=0 hold, T=1 toggle Qโบ = T โŠ• Q
SR S, R 00 hold, 01 reset, 10 set, 11 not allowed Qโบ = S + Rโ€ฒQ (with SR = 0)
JK J, K 00 hold, 01 reset, 10 set, 11 toggle Qโบ = JQโ€ฒ + Kโ€ฒQ

The JK flip-flop is the SR flip-flop with the forbidden case fixed. J plays the role of S and K the role of R, but when both are 1 the flip-flop toggles: it switches to the opposite of its current state. That makes every input combination legal.

The T flip-flop (T for toggle) has only one input. With T=0 it holds, and with T=1 it flips on every active edge. Tying T to 1 turns it into a divide-by-two stage, the heart of every binary counter.

Four flip-flops, four personalities

D Copy the input at the edge.
T Toggle when T is 1.
SR Set or reset. Never both.
JK Set, reset, hold or toggle.

All four are clocked and edge-triggered here.

1 / 2

The program below defines each flip-flop as a function of its inputs and current state, prints the characteristic tables, and checks the characteristic equations against them for every case.

Python Characteristic tables, checked against the equations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The ? in the SR table marks the forbidden input, the only row where the next state is not defined. In the JK table the J=K=1 rows flip the state: 0 โ†’ 1 and 1 โ†’ 0.

Excitation tables: design in reverse

When you build a circuit such as a counter you know the sequence of states you want. The excitation table answers: for a transition from Q to Qโบ, what must the inputs be? An X means "don't care": either value works, which helps simplification (see the Karnaugh map lessons).

Q โ†’ Qโบ D T S R J K
0 โ†’ 0 0 0 0 X 0 X
0 โ†’ 1 1 1 1 0 1 X
1 โ†’ 0 0 1 0 1 X 1
1 โ†’ 1 1 0 X 0 X 0

Reading a row, 0 โ†’ 1 for a JK flip-flop needs J=1, and K can be anything: K=0 sets it, and K=1 toggles it, and both give 1. The X entries are why JK designs often need less logic than D designs. A D flip-flop, in contrast, has the simplest rule: the input is simply the next state. That is why modern design tools almost always use D flip-flops, even though the tables for others are shorter.

You do not have to memorise the table. It can be derived: for each transition, collect the input combinations that produce it, and mark a variable as X if both of its values appear.

Python Deriving the excitation tables by brute force

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output reproduces the table above, X entries included. The assertion inside confirms that each X is a legitimate don't-care and not a hidden dependency.

Converting one flip-flop into another

Sometimes only one type is available. To build type B out of type A, add logic in front of A that computes A's inputs from B's inputs and the current state Q. The excitation table of A tells you what to compute. Six common conversions:

Build From Logic in front
D JK J = D, K = Dโ€ฒ
T JK J = K = T
T D D = T โŠ• Q
D T T = D โŠ• Q
JK D D = JQโ€ฒ + Kโ€ฒQ
JK T T = JQโ€ฒ + KQ

The JK to D case is easy to see: if D=1 the JK gets J=1,K=0 (set), and if D=0 it gets J=0,K=1 (reset). The T flip-flop built from D needs an XOR gate: when T=1 the flip-flop is loaded with NOT Q, and when T=0 with Q itself.

Python Verifying flip-flop conversions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All six conversions are exact. The last one is a good puzzle: with a T flip-flop, you toggle only when the state must change. If Q=0 that means J=1, and if Q=1 it means K=1, which gives T = JQโ€ฒ + KQ.

One-bit memory, race-around and the master-slave JK flip-flop

Where does a flip-flop's memory come from? The smallest memory cell is a bistable element: two inverters connected in a loop, each driving the other. If the first output is 0, the second inverter makes its output 1, and that 1 holds the first output at 0: a consistent state. The mirror state (1 and 0) is just as consistent. So the loop has two stable states and stays in whichever one it was put in: one bit of memory. The SR latch is exactly this loop with the inverters replaced by NOR or NAND gates, so that its inputs can force it into one state or the other.

The JK flip-flop adds a problem and a cure. The problem appears when J = K = 1 and the flip-flop is a level-triggered latch that is open for the whole time the clock is high. Its output toggles, the new output is fed back to the inputs, and since the inputs still say "toggle", it toggles again after one gate delay, and again, and again, for as long as the clock stays high. This is called race-around. The final state after a clock pulse then depends on how long the pulse lasts compared with the gate delay, which is useless.

The cure is the master-slave arrangement you already saw for the D flip-flop: two latches in series, driven by opposite clock phases. The master is open while CLK = 1 and computes the next state from J, K and the slave's output Q; the slave is closed while CLK = 1, so Q cannot change and the feedback stays still. When the clock falls the master closes and the slave opens and copies it. The state changes once, at the falling edge, however wide the pulse is. Modern edge-triggered JK flip-flops use a different internal structure but give the same once-per-cycle behavior.

Python Race-around versus master-slave

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first block shows the two stable states of the inverter loop, and the failure of a forced equal state. The second table is the race-around: with a gate delay of 2 ns a 3 ns pulse toggles Q once, a 5 ns pulse toggles twice (so Q ends where it started), and an 8 ns pulse four times. The result is decided by the pulse width, not by the design. The master-slave trace shows the cure: in each cycle the master takes the new value while the clock is high, but Q only changes in the following clock-low step, so three cycles give three toggles, and the output waveform is a clean divide-by-two.

Classic master-slave JK flip-flops have one more quirk called ones-catching: while the clock is high the master can be set by a brief glitch on J or K, and that stray 1 is passed on to the slave. For this reason, inputs of a master-slave device must be stable throughout the high phase. Edge-triggered flip-flops only look at the inputs at the clock edge and do not have this problem.

Toggling in action

A flip-flop with T=1 changes state at every rising edge, so its output has half the frequency of the clock. The next program simulates edge-triggered flip-flops of each type on a series of clock cycles, driving the JK one with a chosen J/K sequence, and chains two T flip-flops to divide by four.

Python Live flip-flops: JK sequence and clock dividers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each rising edge in the JK sequence produces the mode in the label. For the chain, Q1 completes one cycle for every two clock cycles, and Q2 one cycle for every four. Chaining toggle stages like this is how the counter lessons build binary counters.

Standalone JK and T flip-flop chips exist, but most FPGAs and standard-cell libraries provide only D flip-flops. A designer who wants "JK behaviour" writes the characteristic equation in front of a D flip-flop, which is exactly the JK-from-D conversion above.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A JK flip-flop has J=1 and K=1 at the active edge. What happens?

    J=K=1 is the case that the SR flip-flop forbids. The JK flip-flop uses it to toggle.
  2. 2. Which is the characteristic equation of a T flip-flop?

    When T=0 the state is kept, and when T=1 it is inverted. That is exactly an XOR of T with the current Q.
  3. 3. To change a JK flip-flop from Q=0 to Q=1, what must J and K be?

    J=1 sets or toggles from 0 to 1, whatever K is. K is a don't-care for this transition.
  4. 4. How can a D flip-flop behave like a T flip-flop?

    The next state of a T flip-flop is T xor Q, and a D flip-flop loads whatever is on D, so D = T xor Q.
  5. 5. A T flip-flop has T=1 and a 1 kHz clock. What is the output frequency?

    The output toggles once per clock edge, so a full output cycle needs two clock cycles, which halves the frequency.

Summary

  • A level-triggered JK flip-flop with J = K = 1 races around; the master-slave structure (or edge triggering) makes it change once per clock cycle.
  • The characteristic table (or equation) gives the next state from the inputs and the current state; the excitation table gives the inputs needed for a wanted transition.
  • D: Qโบ = D. T: Qโบ = T โŠ• Q. SR: Qโบ = S + Rโ€ฒQ with SR = 0. JK: Qโบ = JQโ€ฒ + Kโ€ฒQ.
  • JK repairs the SR forbidden case by turning J=K=1 into a toggle; excitation tables for JK and SR contain don't-cares that can simplify the logic.
  • One flip-flop type can be built from another by adding logic that follows the excitation table, such as D = T โŠ• Q for T from D.
  • A T flip-flop with T=1 divides the clock frequency by two, and chaining them divides it by four, eight and so on.

Next: Timing, Clock Skew and Metastability.