About

4.5 Sequential Circuits: Clocks & Flip-Flops

Theory: Sequential Circuits: Clocks & Flip-Flops

Combinational circuits are perfect when we want the immediate result of a Boolean function applied to the current inputs. But a computer also has to remember: register contents, the program counter, which step of an instruction it is executing. A sequential circuit produces outputs that depend on its current inputs and its current state, the stored result of what happened before. Memory is created by feedback: feeding a gate’s output back into the circuit’s own inputs (Null & Lobur, Ch. 3).

CombinationalSequential
Output depends oncurrent inputs onlycurrent inputs and current state
Memorynoneyes (flip-flops)
Feedback pathsnoneyes
Timingoutput follows inputs after a gate delaystate changes only on clock ticks
Examplesadder, decoder, mux, ALUflip-flop, register, counter

The Clock

Sequential circuits need a way to sequence events: to decide when the state is allowed to change. This is the job of a clock, a special circuit that sends a regular train of electrical pulses through the system.

        ┌───┐   ┌───┐   ┌───┐   ┌───┐
clock   │   │   │   │   │   │   │   │
     ───┘   └───┘   └───┘   └───┘   └───
        ↑   ↓
     rising falling
      edge   edge
        |<----->|
        one clock cycle (period)

When exactly does a circuit react?

TypeChanges state…
Edge-triggeredat the instant of the rising edge (low → high) or the falling edge (high → low)
Level-triggeredwhenever the clock is at its high level (the whole time the pulse is high)

Edge-triggered devices sample their inputs at one precise instant per cycle, so inputs may change freely at other times without affecting the state. Flip-flops in a CPU are usually edge-triggered.

Mini-example

A rising-edge-triggered device with a 2 ns period changes state at t=0,2,4,6,…t = 0, 2, 4, 6, \ldots ns, once per cycle, no matter how many times its inputs wiggle between edges.

The SR Flip-Flop: Memory from Feedback

The most basic memory element is the SR (Set/Reset) flip-flop. Its internals are two NOR gates cross-coupled so each one’s output feeds back into the other:

SR flip-flop from two cross-coupled NOR gatesSRNOR 1NOR 2Q'Q

Recall a NOR outputs 1 only when all its inputs are 0. So any input at 1 forces that gate’s output to 0.

Characteristic table (Q(t)Q(t) = output now, Q(t+1)Q(t+1) = output after the next clock pulse):

SSRRQ(t+1)Q(t+1)
00Q(t)Q(t) (no change)
010 (reset)
101 (set)
11undefined

Because the next state depends on the present state too, the SR flip-flop really has three inputs: SS, RR and Q(t)Q(t). Its full truth table:

SSRRQ(t)Q(t)Q(t+1)Q(t+1)
0000
0011
0100
0110
1001
1011
110undefined
111undefined

The block symbol of every flip-flop is a rectangle with its inputs on the left, a small triangle ”>” marking the clock input C, and two outputs QQ and Q′Q' (drawn Q‾\overline{Q}, often with a bubble) on the right.

The JK Flip-Flop

We cannot always guarantee that SS and RR will never both be 1. The JK flip-flop (named in honour of Jack Kilby, inventor of the integrated circuit) modifies the SR flip-flop so that every input combination is stable.

Construction: two AND gates in front of an SR flip-flop, with feedback from the outputs:

S=J⋅Q′,R=K⋅QS = J \cdot Q', \qquad R = K \cdot Q

Since QQ and Q′Q' are never both 1, SS and RR can never both be 1. With J=K=1J = K = 1: if Q=0Q = 0 then S=1,R=0S = 1, R = 0 → set to 1; if Q=1Q = 1 then S=0,R=1S = 0, R = 1 → reset to 0. Either way the output toggles.

JJKKQ(t+1)Q(t+1)
00Q(t)Q(t) (no change)
010 (reset)
101 (set)
11Q(t)′Q(t)' (complement / toggle)

The D Flip-Flop

The D (data) flip-flop is another modification of the SR flip-flop: a single input DD drives SS directly and RR through an inverter:

S=D,R=D′S = D, \qquad R = D'

So SS and RR are always opposite (never both 1), and the flip-flop simply stores whatever is on DD at the clock pulse:

DDQ(t+1)Q(t+1)
00
11

The output stays the same over later clock pulses until DD changes. The D flip-flop is the fundamental circuit of computer memory: each one stores one bit.

The T Flip-Flop (JK with J = K)

Tie JJ and KK together into one input TT (toggle). Only the rows JK=00JK = 00 and JK=11JK = 11 remain:

TTQ(t+1)Q(t+1)
0Q(t)Q(t) (hold)
1Q(t)′Q(t)' (toggle)

This “toggle when told to” behaviour is exactly what a binary counter needs.

Characteristic Equations

Each characteristic table can be written as a single equation for the next state Q+=Q(t+1)Q^+ = Q(t+1) (derived in Worked Example 7):

Flip-flopCharacteristic equation
SRQ+=S+R′QQ^+ = S + R'Q (with SR=0SR = 0)
JKQ+=JQ′+K′QQ^+ = JQ' + K'Q
DQ+=DQ^+ = D
TQ+=T⊕QQ^+ = T \oplus Q

Mini-example

JK with J=1,K=1,Q=1J = 1, K = 1, Q = 1: Q+=1⋅0+0⋅1=0Q^+ = 1\cdot 0 + 0 \cdot 1 = 0 (toggled) ✓. JK with J=0,K=0,Q=1J = 0, K = 0, Q = 1: Q+=0+1⋅1=1Q^+ = 0 + 1\cdot 1 = 1 (held) ✓.

Registers

A register is a group of flip-flops that store a multi-bit word together. A 4-bit register is four D flip-flops with a shared clock: inputs In0..In3In_0..In_3 go to the four DD inputs, and the outputs Out0..Out3Out_0..Out_3 are the four QQs. On each clock pulse all four bits are loaded at once; between pulses the stored word is held regardless of what the inputs do. Larger memories are arrays of such registers selected by address decoders.

Binary Counter

A binary counter is a sequential circuit that adds 1 to its stored number on every clock pulse: 0000,0001,0010,0011,…,1111,0000,…0000, 0001, 0010, 0011, \ldots, 1111, 0000, \ldots

The lecture’s 4-bit counter uses four JK flip-flops (B0B_0 = low-order bit) all on the same clock, each used as a T flip-flop (J=KJ = K):

Flip-flopJ=K=J = K =Toggles when…
B0B_0Count Enableevery clock pulse (while counting is enabled)
B1B_1Count Enable ⋅B0\cdot B_0B0=1B_0 = 1
B2B_2Count Enable ⋅B0B1\cdot B_0 B_1B0=B1=1B_0 = B_1 = 1
B3B_3Count Enable ⋅B0B1B2\cdot B_0 B_1 B_2B0=B1=B2=1B_0 = B_1 = B_2 = 1

Output Carry == Count Enable ⋅B0B1B2B3\cdot B_0B_1B_2B_3: it is 1 when the counter is at 11111111 and about to wrap to 00000000 (for chaining counters).

So the low-order bit is complemented at each clock pulse, and each higher bit is complemented exactly when all the bits below it are 1. This is ordinary binary “add 1”: adding 1 flips the trailing 1s to 0 and the first 0 to 1. Equivalently, each bit flips at the moment the bit below it changes from 1 to 0 (a carry out of the lower bit).

Mini-example

At 00110011: B0=1B_0 = 1 toggles; B1B_1 toggles (since B0=1B_0 = 1); B2B_2 toggles (since B0B1=1B_0 B_1 = 1); B3B_3 does not (B2=0B_2 = 0). New value B3B2B1B0=0100B_3B_2B_1B_0 = 0100, i.e. 3→43 \to 4 ✓.

Analysing a Clocked Sequential Circuit

Given a circuit diagram of flip-flops and gates, we describe its behaviour with a next-state table (state table).

Procedure:

  1. Identify the state variables (one per flip-flop output, e.g. AA, BB) and the external inputs (e.g. XX).
  2. Read the wiring and write the input equations: an expression for every flip-flop input (JAJ_A, KAK_A, DBD_B, …) in terms of the present state and the inputs.
  3. Make a table with one row for every combination of present state and input (2flip-flops+inputs2^{\text{flip-flops} + \text{inputs}} rows).
  4. For each row, evaluate the input equations.
  5. Apply each flip-flop’s characteristic table to get its next state.

All flip-flops share the same clock and change simultaneously. Every input equation must be evaluated with the present values of the state variables, never with a value another flip-flop is about to change to.

Mini-example

One D flip-flop with D=A⊕XD = A \oplus X. Row A=1,X=1A = 1, X = 1: D=0D = 0, so A+=0A^+ = 0. Row A=1,X=0A = 1, X = 0: D=1D = 1, A+=1A^+ = 1. When X=1X = 1 the flip-flop toggles; when X=0X = 0 it holds: a T flip-flop built from a D flip-flop.


Worked Examples

Exercise 1

An SR flip-flop built from two cross-coupled NOR gates (Q′=(S+Q)′Q' = (S + Q)', Q=(R+Q′)′Q = (R + Q')') starts with Q=0Q = 0. Trace both gate outputs for the input sequence SR=10SR = 10, then 0000, then 0101, then 0000.

Show solution ↓
Solution

Evaluate the gate whose input is forced first (a NOR with any input 1 outputs 0), then the other.

StepSSRRFirst gate settlesSecond gate settlesQQQ′Q'Meaning
start01stored 0
110NOR 1: (1+0)′=0=Q′(1 + 0)' = 0 = Q'NOR 2: (0+0)′=1=Q(0 + 0)' = 1 = Q10set
200NOR 1: (0+1)′=0=Q′(0 + 1)' = 0 = Q'NOR 2: (0+0)′=1=Q(0 + 0)' = 1 = Q10hold (remembers the 1)
301NOR 2: (1+0)′=0=Q(1 + 0)' = 0 = QNOR 1: (0+0)′=1=Q′(0 + 0)' = 1 = Q'01reset
400NOR 2: (0+1)′=0=Q(0 + 1)' = 0 = QNOR 1: (0+0)′=1=Q′(0 + 0)' = 1 = Q'01hold (remembers the 0)

Steps 2 and 4 have the same inputs (SR=00SR = 00) but different outputs: the output depends on the history. That is memory, and it is why a flip-flop is a sequential, not combinational, circuit.

If we had applied SR=11SR = 11: both NOR gates would be forced to 0, giving Q=Q′=0Q = Q' = 0; on returning to 0000 the final state would depend on gate timing, which is why SR=11SR = 11 is undefined.

Exercise 2

A JK flip-flop starts with Q=0Q = 0. The following (J,K)(J, K) values are present at six successive clock pulses: (1,0),(0,0),(1,1),(1,1),(0,1),(1,1)(1,0), (0,0), (1,1), (1,1), (0,1), (1,1). Give QQ after each pulse.

Show solution ↓
Solution

Apply the JK table with Q(t)Q(t) = the value before the pulse.

PulseJJKKQ(t)Q(t)RuleQ(t+1)Q(t+1)
1100set1
2001no change1
3111toggle0
4110toggle1
5011reset0
6110toggle1

Output sequence: 1,1,0,1,0,11, 1, 0, 1, 0, 1.

Cross-check with internals at pulse 3 (J=K=1J = K = 1, Q=1Q = 1): S=JQ′=1⋅0=0S = JQ' = 1 \cdot 0 = 0, R=KQ=1⋅1=1R = KQ = 1 \cdot 1 = 1 → SR reset → Q=0Q = 0 ✓.

Exercise 3

A 4-bit register of rising-edge-triggered D flip-flops holds 00000000. The inputs In3In2In1In0In_3In_2In_1In_0 change as follows: 10111011 just before clock edge 1; 01100110 halfway between edges 1 and 2; 11101110 shortly after that, still before edge 2; unchanged before edge 3. Give the register output after each edge and in between.

Show solution ↓
Solution

Each D flip-flop copies its DD input only at a rising edge (Q+=DQ^+ = D). Between edges, input changes are ignored.

TimeInputsRegister output Out3..Out0Out_3..Out_0
initially(anything)0000
edge 110111011 (all four bits loaded at once)
between edges 1 and 20110, then 1110still 1011 (no edge, so no change)
edge 211101110
edge 311101110 (same input, same stored value)

The intermediate value 01100110 is never stored, because it was not present at an edge. This is what “edge-triggered” buys us: the inputs only have to be stable around the edge. (A level-triggered register would instead follow the inputs for the whole time the clock is high.)

Exercise 4

The lecture’s 4-bit JK binary counter (Count Enable =1= 1) holds B3B2B1B0=0110B_3B_2B_1B_0 = 0110. For the next four clock pulses, give each flip-flop’s J=KJ = K input and the new count. Also give the value of Output Carry when the counter holds 11111111.

Show solution ↓
Solution

J0=K0=1J_0 = K_0 = 1; J1=K1=B0J_1 = K_1 = B_0; J2=K2=B0B1J_2 = K_2 = B_0B_1; J3=K3=B0B1B2J_3 = K_3 = B_0B_1B_2 (all with Count Enable =1= 1). A flip-flop with J=K=1J = K = 1 toggles, with J=K=0J = K = 0 holds. All inputs use the present count.

PulsePresent B3B2B1B0B_3B_2B_1B_0T3=B0B1B2T_3 = B_0B_1B_2T2=B0B1T_2 = B_0B_1T1=B0T_1 = B_0T0T_0Next B3B2B1B0B_3B_2B_1B_0decimal
10110000101116 → 7
20111111110007 → 8
31000000110018 → 9
41001001110109 → 10

Pulse 2 is the interesting one: all three lower bits are 1, so all four flip-flops toggle at once: 0111→10000111 \to 1000, exactly like the carry in 7+1=87 + 1 = 8.

At 11111111: Output Carry == Count Enable ⋅B0B1B2B3=1\cdot B_0B_1B_2B_3 = 1, and the next pulse toggles all four bits to 00000000 (15 → 0, wrap-around), with the carry signalling the overflow to a following counter stage.

Exercise 5

Analyse the circuit with two D flip-flops AA and BB, input XX, and input equations

DA=A⊕(X⋅B),DB=B⊕X.D_A = A \oplus (X \cdot B), \qquad D_B = B \oplus X.

Build the next-state table and describe what the circuit does.

Show solution ↓
Solution

Step 1: state variables A,BA, B; input XX. Step 2: input equations given. Steps 3-5: 8 rows; for D flip-flops A+=DAA^+ = D_A, B+=DBB^+ = D_B.

AABBXXXBXBDA=A⊕XBD_A = A \oplus XBDB=B⊕XD_B = B \oplus XA+A^+B+B^+
00000000
00100101
01000101
01111010
10001010
10101111
11001111
11110000

Interpretation: read ABAB as a 2-bit number.

  • X=0X = 0: AB+=ABAB^+ = AB (00→00, 01→01, 10→10, 11→11): the state holds.
  • X=1X = 1: 00→01→10→11→00: the state counts up by 1 and wraps.

This is a 2-bit binary counter with count enable XX, the same structure as the lecture’s counter (BB toggles when enabled; AA toggles when enabled and B=1B = 1).

Exercise 6

Analyse the circuit with two JK flip-flops AA and BB, input XX, and input equations

JA=XB,KA=X,JB=X,KB=A.J_A = X B, \quad K_A = X, \qquad J_B = X, \quad K_B = A.
Show solution ↓
Solution

Evaluate the four flip-flop inputs from the present A,B,XA, B, X, then apply the JK rule (00 hold, 01 reset, 10 set, 11 toggle) to each flip-flop separately.

AABBXXJA=XBJ_A = XBKA=XK_A = XA+A^+JB=XJ_B = XKB=AK_B = AB+B^+
000000 (hold)000 (hold)
001010 (reset)101 (set)
010000 (hold)001 (hold)
011111 (toggle 0→1)101 (set)
100001 (hold)010 (reset)
101010 (reset)111 (toggle 0→1)
110001 (hold)010 (reset)
111110 (toggle 1→0)110 (toggle 1→0)

Next-state summary (AB→A+B+AB \to A^+B^+):

Present ABABX=0X = 0X=1X = 1
000001
010111
101001
111000

Check one row with characteristic equations, row ABX=101A B X = 101: A+=JAA′+KA′A=0⋅0+0⋅1=0A^+ = J_AA' + K_A'A = 0\cdot0 + 0\cdot1 = 0 ✓; B+=JBB′+KB′B=1⋅1+0⋅0=1B^+ = J_BB' + K_B'B = 1\cdot1 + 0\cdot0 = 1 ✓.

Exercise 7

Derive the characteristic equations of the SR and JK flip-flops from their full truth tables using K-maps, and show that a JK flip-flop with J=K=TJ = K = T satisfies Q+=T⊕QQ^+ = T \oplus Q.

Show solution ↓
Solution

SR (Q+Q^+ as a function of S,R,QS, R, Q; the two “undefined” rows can never occur, so they are don’t-cares d):

S\RQS \backslash RQ00011110
00100
111dd
  • Group A: whole bottom row (using both d’s) → SS.
  • Group B: column 01 (both rows) → R=0,Q=1R = 0, Q = 1 → R′QR'Q.
Q+=S+R′QQ^+ = S + R'Q

JK (1s at JKQJKQ = 001 hold-1, 100 set, 101 set, 110 toggle 0→1):

J\KQJ \backslash KQ00011110
00100
11101
  • Group A: cells JKQ=100J KQ = 100 and 110110 (bottom row, columns 00 and 10, joined by wrap-around) → J=1,Q=0J = 1, Q = 0 → JQ′JQ'.
  • Group B: column 01 (both rows) → K=0,Q=1K = 0, Q = 1 → K′QK'Q.
Q+=JQ′+K′QQ^+ = JQ' + K'Q

Every 1 is covered (cell 101 is in group B) ✓. Read it as: “become 1 if told to set while 0, or stay 1 if not told to reset”.

T flip-flop: substitute J=K=TJ = K = T:

Q+=TQ′+T′Q=T⊕QQ^+ = TQ' + T'Q = T \oplus Q

(definition of XOR). Check: T=0T = 0 gives Q+=QQ^+ = Q (hold), T=1T = 1 gives Q+=Q′Q^+ = Q' (toggle) ✓.