Module 9: Electronics · Lesson 9.6 · about 45 min
Flip-flops, counters and registers
Sequential logic at GATE depth: SR and D latches, edge-triggered D, JK and T flip-flops with characteristic and excitation tables, the race-around problem, setup and hold times and metastability, shift registers, ring and Johnson counters, ripple and synchronous counters, mod-N counters and their glitches, frequency division, timing limits on the clock, and Moore and Mealy state machines.
Module 9 · about 45 minutes. The circuits of lesson 9.5 forget their inputs as soon as the inputs change. Add feedback from outputs to inputs and a circuit can hold a bit: that is memory, and with a clock it becomes registers, counters and state machines. GATE asks for state tables, counter moduli, timing diagrams and clock limits.
1. Latches and flip-flops
SR latch. Two cross-coupled NOR gates. S = 1 sets Q = 1, R = 1 resets it, S = R = 0 holds, and S = R = 1 forces both outputs to 0 and leaves the next state undecided when both inputs drop together, so it is forbidden. (With NAND gates the inputs are active-low.) Gating it with an enable and feeding , gives the D latch, which is transparent while the enable is high.
Edge-triggered flip-flops change only at a clock edge. Their behaviour is summarised by a characteristic equation for the next state :
| Flip-flop | Characteristic equation | Excitation (inputs needed for Q → Q⁺) |
|---|---|---|
| D | D = Q⁺ | |
| T | T = Q ⊕ Q⁺ | |
| JK | 0→0: J=0, K=X; 0→1: J=1, K=X; 1→0: J=X, K=1; 1→1: J=X, K=0 | |
| SR | (SR = 0) | 0→1: S=1, R=0; 1→0: S=0, R=1 |
The JK flip-flop is the SR with the forbidden input made useful: J = K = 1 toggles. Built as a level-triggered latch, it would toggle over and over while the clock is high: the race-around condition. The master-slave arrangement (one latch enabled on each clock level) or true edge triggering cures it.
- setup time `$t_{su}$`
- the input must be stable this long before the clock edge
- hold time `$t_h$`
- and this long after it
- clock-to-Q `$t_{cq}$`
- delay from the edge to the new output
- metastability
- if the input changes inside the setup-hold window, the flip-flop can hang between 0 and 1 for an unpredictable time. Signals from outside the clock domain pass through two flip-flops in series (a synchroniser) to make the failure rate negligible.
2. Registers
A register is flip-flops sharing a clock. Connecting each output to the next input gives a shift register: one shift per clock edge.
| Type | Load | Read | Use |
|---|---|---|---|
| SISO | serial, n clocks | serial, n more clocks | delay line |
| SIPO | serial | parallel | serial-to-parallel (receivers) |
| PISO | parallel, one clock | serial | parallel-to-serial (transmitters) |
| PIPO | parallel | parallel | storage, buffers |
Shifting left by one place multiplies an unsigned number by 2; shifting right divides by 2 (an arithmetic shift keeps the sign bit for two’s complement).
Ring and Johnson counters. Feed the last output of a shift register back to the first. Preloaded with a single 1, the ring counter circulates it through states, one output high at a time, with no decoding needed. Feed back the complement instead and you get the Johnson counter, with states: a 4-bit one runs 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001, and each state is decoded by a two-input gate. Both waste most of their possible states and need a reset to avoid locking into an unused cycle.
3. Counters
Ripple (asynchronous) counters. Each flip-flop toggles (T = 1, or JK with J = K = 1) and is clocked by the output of the one before. Each stage divides the frequency by 2, so stages count to and divide by . The catch is delay: bit changes propagation delays after the edge, so between edges the count passes through wrong values (going from 0111 to 1000 shows 0110, 0100, 0000 on the way).
Synchronous counters. All flip-flops share the clock. For a binary up-counter with T flip-flops, bit toggles when all lower bits are 1:
All outputs change together one after the edge, with no wrong intermediate states.
Mod-N counters. A counter that cycles through states needs flip-flops. A ripple counter is made mod-N by detecting the count and clearing all flip-flops asynchronously: a decade counter (mod-10) uses a NAND of and (1010) to clear. The state therefore exists briefly, a glitch. A synchronous design instead loads 0 at the clock edge after , with no glitch. Design a synchronous counter from its state table: list present and next states, read off the flip-flop inputs from the excitation table, and minimise each with a K-map, using the unused states as don’t-cares.
Frequency division. Counters are dividers: cascaded mod- and mod- counters divide by . A 32 768 Hz watch crystal through 15 toggle stages gives exactly 1 Hz. The MSB of a counter whose modulus is not a power of two is not a symmetric square wave (a mod-6 counter’s MSB is high for 2 of 6 counts); a final divide-by-2 stage fixes that.
4. Timing limits
For a synchronous path from one flip-flop through logic to the next:
The first (setup) inequality sets the maximum clock frequency; the second (hold) inequality does not depend on the clock period at all, and a violation cannot be fixed by slowing the clock. For a ripple counter whose full count must be read, the clock period must exceed plus the time to read the count.
Worked example. A 4-bit ripple counter with 10 ns flip-flops settles 40 ns after an edge; with a 10 ns strobe it runs at most at 1/(50 ns) = 20 MHz. A synchronous version with ns, an AND chain of 8 ns and ns needs only 15 ns: 66.7 MHz, and adding bits only lengthens the AND chain (or not at all, with parallel carry gates).
State machines. In a Moore machine the outputs depend only on the state; in a Mealy machine they also depend on the present input, which can save states but lets input glitches through to the outputs. A sequence detector for 101 needs three states as a Mealy machine and four as a Moore machine.
“A ripple counter and a synchronous counter are equally good dividers, so why bother with the synchronous one?” As a pure frequency divider, the ripple counter is fine and uses less logic. The difference shows the moment the count is decoded: its outputs pass through wrong states for up to delays after every edge, and a decoder watching them produces glitches. Anything that acts on the count value needs a synchronous counter, or must wait for the ripple to settle.
- D: ; T: ; JK: (J = K = 1 toggles); SR forbids S = R = 1.
- Race-around: level-triggered JK with J = K = 1; cured by master-slave or edge triggering.
- Ring counter states; Johnson states; binary .
- Ripple: bit settles after , wrong intermediate counts; mod-N by asynchronous clear at N (glitch).
- Synchronous: ; ; hold violations do not depend on the clock.
- Cascaded counters divide by the product of their moduli.
Practise: exam questions on this lesson
Next: lesson 9.7 connects digital circuits to the analogue world with DACs and ADCs, several of which are built from the counters and registers here.
Check yourself
Sources
- M. M. Mano and M. D. Ciletti, Digital Design, 5th ed. (2013), chapters 5 and 6
- R. J. Tocci, N. S. Widmer and G. L. Moss, Digital Systems, 12th ed. (2017), chapters 5 and 7
- J. F. Wakerly, Digital Design: Principles and Practices, 4th ed. (2006), chapters 7 and 8
- GATE Physics (PH) syllabus, Electronics section, published by the organising IIT each year
Your ticks stay in this browser. Save them as a file on the course home.
Updated 2026-11-22. Not affiliated with the IITs, IISc or the GATE organising institute. The general aptitude part of GATE is not covered here. Check the official GATE website for the current pattern. All questions are original.