Electronics and Communication Engineering‹›⌂ 0:00 studied

Module 3 · 13 min read · Free chapter

Latches, flip-flops, counters and state machines

In short

A latch is transparent while enabled, while a flip-flop samples only at a clock edge. The JK flip-flop toggles when J = K = 1, which divides the clock by two. The clock period must cover clock-to-Q delay, the slowest logic path and setup time. Counters chain flip-flops, and Moore or Mealy state machines control sequential behaviour.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: circuits that remember

A lift does not decide where to go from the buttons pressed right now alone. It also remembers which floor it is on and which way it is moving. A circuit whose output depends on the past as well as the present is called sequential.

Memory in a digital circuit comes from feedback: two gates that hold each other in a fixed state. The simplest such element is a latch. Adding a clock gives the flip-flop, which changes state only at a chosen instant, so that thousands of them in a chip move together in step.

From flip-flops we build registers that hold words, shift registers that move data, counters that count events and finite state machines that control everything from traffic lights to processors.

This chapter covers these elements and the timing rules that limit how fast a clocked circuit can run.

Why it matters. Flip-flop conversions, counter sequences and maximum clock frequency appear in GATE EC and CS every year, and FSM design is a standard written question.

Latches and flip-flops

Connect two NOR gates so that each one's output feeds one input of the other. The pair has two stable states, Q=1Q = 1 and Q=0Q = 0, and stays in whichever it is put into. This is the SR latch. A 1 on S (set) forces Q=1Q = 1, a 1 on R (reset) forces Q=0Q = 0, and with both at 0 it holds.

Setting S=R=1S = R = 1 forces both outputs to 0, and when both inputs return to 0 together the final state is unpredictable. That input is therefore forbidden. A NAND version works the same way with active-low inputs.

A gated D latch adds an enable and feeds S with D and R with D‾\overline{D}, so the forbidden case cannot arise. While the enable is high, the output follows D, so the latch is transparent. When the enable goes low, the output holds the last value. This level-sensitive behaviour can let a signal race through several latches in one clock phase.

A flip-flop avoids that by responding only at a clock edge. A common build is the master-slave pair: the master latch is transparent while the clock is low, and the slave while it is high. The output therefore changes only at the rising edge, capturing whatever D was just before it.

Flip-flops come in four types:

  • D (data) copies its input.
  • T (toggle) flips when T = 1.
  • JK acts like SR but toggles when J = K = 1 instead of being forbidden.
  • SR sets or resets.

Most chips use D flip-flops only, building the others from them with a little logic.

Why it matters. Questions often show a latch or flip-flop with a waveform and ask for the output, so the difference between level and edge triggering is essential.

Characteristic and excitation tables

A flip-flop's behaviour is summed up by its characteristic equation, the next state Q+Q^+ in terms of the inputs and the present state QQ:

D: Q+=DT: Q+=T⊕QD:\ Q^+ = D \qquad T:\ Q^+ = T \oplus Q
JK: Q+=JQ‾+K‾QSR: Q+=S+R‾Q,  SR=0JK:\ Q^+ = J\overline{Q} + \overline{K}Q \qquad SR:\ Q^+ = S + \overline{R}Q,\ \ SR = 0

For design we need the reverse question: what inputs cause a given change from QQ to Q+Q^+? The answer is the excitation table.

Q→Q+Q \to Q^+ D T J K S R
0 → 0 0 0 0 X 0 X
0 → 1 1 1 1 X 1 0
1 → 0 0 1 X 1 0 1
1 → 1 1 0 X 0 X 0

The many don't-cares in the JK column make JK designs need the least logic, which is why JK flip-flops are popular in textbook counter design.

One flip-flop can be converted to another by adding logic at its input. To build a T from a D, set D=T⊕QD = T \oplus Q. To build a JK from a D, set D=JQ‾+K‾QD = J\overline{Q} + \overline{K}Q. To build a D from a JK, set J=DJ = D and K=D‾K = \overline{D}.

Worked example. A JK flip-flop with J=K=1J = K = 1 toggles on every clock edge, so its output is a square wave at half the clock frequency. This is the basic divide-by-two stage of every counter.

Why it matters. Characteristic equations, excitation tables and flip-flop conversions are among the most common GATE sequential questions.

Timing: setup, hold and the critical path

A flip-flop cannot capture data that changes at the very instant of the clock edge. Its data sheet gives three numbers.

The setup time tsut_{su} is how long the input must be stable before the edge. The hold time tht_h is how long it must stay stable after the edge. The clock-to-Q delay tcqt_{cq} is how long the output takes to change after the edge.

Consider two flip-flops with combinational logic between them. After a clock edge, data leaves the first flip-flop after tcqt_{cq}, passes through the logic, and must arrive at the second a setup time before the next edge. The slowest path, the critical path, sets the minimum clock period:

Tclk≥tcq+tlogic,max+tsuT_{clk} \ge t_{cq} + t_{logic,max} + t_{su}

The maximum clock frequency is 1Tclk,min\dfrac{1}{T_{clk,min}}. To run a processor faster, designers shorten the critical path, for example by pipelining, which splits long logic with extra registers.

The hold time gives a second rule, this time on the fastest path. New data must not reach the second flip-flop so quickly that it corrupts the value being captured:

tcq+tlogic,min≥tht_{cq} + t_{logic,min} \ge t_h

A hold violation cannot be fixed by slowing the clock; it needs extra delay in the short path.

In real chips the clock does not arrive everywhere at once. This clock skew helps one rule and hurts the other, depending on its direction.

If setup or hold is violated, a flip-flop can become metastable, hanging between 0 and 1 for an unpredictable time. This is a real danger when a signal arrives from outside or from another clock domain. Such signals pass through a synchroniser of two flip-flops in series, giving the first one a full clock period to settle.

Worked example. With tcq=1t_{cq} = 1 ns, tlogic,max=6t_{logic,max} = 6 ns and tsu=1t_{su} = 1 ns, the minimum period is 8 ns, so the maximum clock frequency is 125 MHz.

Why it matters. Maximum-frequency and hold-check numericals are now a regular GATE item.

Registers and shift registers

A register is a group of flip-flops sharing a clock, holding one word. An 8-bit register is eight D flip-flops side by side.

A shift register connects each flip-flop's output to the next one's input, so on every clock the stored bits move one place. Shift registers are named by how data enters and leaves:

  • SISO (serial in, serial out) delays a bit stream by n clocks.
  • SIPO (serial in, parallel out) turns a serial stream into a word, as in a receiver.
  • PISO (parallel in, serial out) turns a word into a stream, as in a transmitter.
  • PIPO (parallel in, parallel out) is a plain register.

A universal shift register can shift left, shift right, load in parallel or hold, chosen by mode inputs.

Feeding the last output back to the first input makes a ring counter. Starting with a single 1, an n-bit ring counter has n states, with the 1 circulating, and gives decoded outputs with no extra logic. Feeding back the complement instead makes a Johnson counter, or twisted-ring counter, which has 2n2n states.

Shifting left by one place multiplies an unsigned number by 2, and shifting right divides by 2, which processors use for fast scaling.

Worked example. A 4-bit Johnson counter starting at 0000 steps through 1000, 1100, 1110, 1111, 0111, 0011, 0001 and back to 0000, eight states in all.

Why it matters. Ring and Johnson state counts and shift-register outputs after n clocks are quick GATE and JE questions.

Counters: ripple and synchronous

A T flip-flop with T=1T = 1 divides its clock by 2. Chain nn of them, each clocked by the previous one's output, and you get an nn-bit ripple counter (asynchronous counter). It counts from 0 to 2n−12^n - 1 and then wraps to 0.

The ripple counter is simple, but each flip-flop waits for the one before it. The last bit settles only after nn propagation delays, and during that time the outputs show false intermediate counts. This limits the clock frequency to about 1n tpd\dfrac{1}{n\,t_{pd}} when all outputs must be read.

A synchronous counter clocks every flip-flop from the same clock, so they all change together. Logic decides which ones toggle. In a binary up-counter, bit ii toggles when all lower bits are 1:

T0=1,Ti=Q0Q1⋯Qi−1T_0 = 1, \quad T_i = Q_0 Q_1 \cdots Q_{i-1}

The delay no longer grows with the number of bits, apart from the AND logic.

A mod-N counter cycles through N states. It needs ⌈log⁡2N⌉\lceil \log_2 N \rceil flip-flops. One way is to detect state N and reset the counter, as in a decade counter that resets at 1010. A cleaner way is to design the next-state logic directly from a state table and excitation tables, so the unused states lead back into the cycle.

Counters can count down, by toggling when lower bits are 0, and can be up-down with a control input. They are used as frequency dividers, timers, address generators and event counters.

Worked example. A ripple counter with 10 flip-flops, each with 10 ns delay, needs up to 100 ns to settle, so it should not be read faster than 10 MHz. A synchronous design of the same size settles in about one flip-flop delay plus the gate delay.

Why it matters. Counter sequences, mod-N design and maximum frequency are among the most common GATE sequential questions.

Finite state machines

A finite state machine (FSM) is a sequential circuit described by its states, the transitions between them and its outputs. Two models are used.

In a Moore machine the output depends only on the present state. Outputs are written inside the state bubbles, and they change only after a clock edge, so they are glitch-free.

In a Mealy machine the output depends on the present state and the present input. Outputs are written on the transition arrows. A Mealy machine usually needs fewer states and responds in the same cycle as the input, but its output can glitch if the input does.

The design follows fixed steps:

  1. Draw the state diagram from the word description.
  2. Write the state table, giving next state and output for each present state and input.
  3. Reduce the states by merging any two that have the same outputs and go to equivalent next states for every input.
  4. Assign binary codes to the states; kk states need ⌈log⁡2k⌉\lceil \log_2 k \rceil flip-flops.
  5. Use the excitation table of the chosen flip-flop to find its input equations, and minimise them with K-maps.
  6. Derive the output logic.

A classic example is a sequence detector. To detect 101 in a serial input with overlap, a Mealy machine needs three states: nothing matched, "1" matched and "10" matched. A Moore machine needs a fourth state to hold the output after "101".

Worked example. In the Mealy 101 detector, from state "10" an input 1 gives output 1 and moves to state "1", because the last 1 can start the next match. An input 0 instead returns to the start state.

Why it matters. Sequence detectors and counting the minimum number of states are favourite GATE questions, and FSM design is a standard ESE written question.

Descriptive lens: how this topic is asked in written papers

Written papers ask this topic in four ways:

  1. Explain the difference between latches and flip-flops, the race-around problem, or metastability.
  2. Convert one flip-flop type to another using characteristic and excitation tables.
  3. Design a synchronous mod-N counter or a sequence detector, with state table, assignment and equations.
  4. Compute the maximum clock frequency of a circuit, or check it for hold violations.

Practice questions (our own, not previous-year questions).

  1. Design a synchronous mod-6 counter using JK flip-flops. Show the state table, excitation entries, K-maps and final circuit. (15 marks)
  2. Design a Mealy machine that detects the sequence 1101 with overlap, and state how many states a Moore version would need. (10 marks)
  3. Two flip-flops with tcq=0.5t_{cq} = 0.5 ns, tsu=0.3t_{su} = 0.3 ns and th=0.2t_h = 0.2 ns are joined by logic with delays between 0.1 ns and 3.2 ns. Find the maximum clock frequency and check the hold condition. (10 marks)

Answer plan for question 3.

  • Write the setup rule T≥tcq+tlogic,max+tsu=0.5+3.2+0.3=4.0T \ge t_{cq} + t_{logic,max} + t_{su} = 0.5 + 3.2 + 0.3 = 4.0 ns.
  • Conclude that the maximum frequency is 14 ns=250\dfrac{1}{4\ \text{ns}} = 250 MHz.
  • Write the hold rule tcq+tlogic,min=0.5+0.1=0.6t_{cq} + t_{logic,min} = 0.5 + 0.1 = 0.6 ns, which is at least th=0.2t_h = 0.2 ns.
  • State that hold is met with 0.4 ns of margin.
  • Note that clock skew would reduce one margin, and that hold failures cannot be fixed by slowing the clock.

Quick revision

  • A latch is level-sensitive and a flip-flop is edge-triggered, and SR = 11 is forbidden in an SR latch.
  • The characteristic equations are Q+=DQ^+ = D, Q+=T⊕QQ^+ = T \oplus Q and Q+=JQ‾+K‾QQ^+ = J\overline{Q} + \overline{K}Q.
  • J = K = 1 makes a JK toggle, giving a divide-by-two stage.
  • The setup rule is Tclk≥tcq+tlogic,max+tsuT_{clk} \ge t_{cq} + t_{logic,max} + t_{su}, and the hold rule is tcq+tlogic,min≥tht_{cq} + t_{logic,min} \ge t_h.
  • An n-bit ring counter has n states and a Johnson counter has 2n.
  • A ripple counter is slow because delays add, while a synchronous counter uses Ti=Q0⋯Qi−1T_i = Q_0 \cdots Q_{i-1}.
  • A mod-N counter needs ⌈log⁡2N⌉\lceil \log_2 N \rceil flip-flops.
  • A Moore output depends on the state alone, while a Mealy output also depends on the input and needs fewer states.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 12 answered

  1. The main difference between a latch and a flip-flop is that:

  2. In a NOR-based SR latch, which input combination is forbidden?

  3. The characteristic equation of a JK flip-flop is:

  4. To convert a D flip-flop into a T flip-flop, the D input should be driven by:

  5. For a JK flip-flop to go from Q=1Q = 1 to Q+=0Q^+ = 0, the required inputs are:

  6. Flip-flops with tcq=2t_{cq} = 2 ns and tsu=1t_{su} = 1 ns are joined by logic with a worst-case delay of 7 ns. The maximum clock frequency is:

  7. A circuit fails its hold-time check. Which action fixes it?

  8. How many distinct states does a 5-bit Johnson counter have?

  9. The minimum number of flip-flops needed for a mod-12 counter is:

  10. A 4-bit ripple counter is driven by a 16 kHz clock. The frequency at the output of the last flip-flop is:

  11. Compared with a Mealy machine for the same sequence detector, a Moore machine usually:

  12. Why is an asynchronous external input passed through two flip-flops in series before use?

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

How many states does a Johnson counter have?

An n-bit Johnson counter has 2n states, twice as many as an n-bit ring counter.

How is the maximum clock frequency found?

Add clock-to-Q delay, the longest logic delay and setup time to get the minimum period; its reciprocal is the maximum frequency.

Can a hold violation be fixed by slowing the clock?

No. The hold condition does not involve the clock period, so extra delay must be added to the shortest path.

What is the difference between Moore and Mealy machines?

A Moore output depends only on the state, while a Mealy output also depends on the input, so Mealy usually needs fewer states and responds a cycle sooner.

More in this module: Digital circuits

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Electronics and Communication Engineering (EC) syllabus, IIT Guwahati
  2. NPTEL Digital Electronic Circuits (IIT Kharagpur, 108105132): latches, flip-flops, counters, registers, sequential machines