Part IV: Digital Electronics | Chapter 11

Flip-Flops & Counters

SR latch, D, JK, and T flip-flops, timing diagrams, synchronous and asynchronous counters, binary, ring, and Johnson counters

1. SR Latch — The Basic Memory Cell

The SR (Set-Reset) latch is the simplest bistable circuit. Built from two cross-coupled NOR or NAND gates, it has two stable states and forms the foundation of all flip-flop circuits.

S=0, R=0
Q (hold)
No change
S=1, R=0
1 (set)
Output set HIGH
S=0, R=1
0 (reset)
Output reset LOW
S=1, R=1
? (invalid)
Forbidden state

The forbidden state (S=R=1) can lead to metastability — a circuit that takes an indeterminate time to settle. The D flip-flop eliminates this by ensuring S and R are always complementary.

2. Flip-Flop Types

DFFDCLKQDQCLKDQQ follows D after rising CLK edge (1 cycle delay)
D flip-flop: captures D input on rising clock edge, holds until next rising edge
D Flip-Flop
\( Q_{n+1} = D \)
Data input D is captured on the active clock edge. Most common type; used in registers and pipelines.
JK Flip-Flop
\( Q_{n+1} = J\overline{Q} + \overline{K}Q \)
J=K=1 toggles output — eliminates the SR invalid state. Versatile but slower than D type.
T Flip-Flop
\( Q_{n+1} = T \oplus Q \)
Toggle: when T=1, output flips each clock cycle. Built from JK with J=K=T.
SR Flip-Flop
\( Q_{n+1} = S + \overline{R}Q \)
Clocked SR: edges control when set/reset occur. Forbidden state S=R=1 still exists.

3. Counters

Counters are registers whose state advances through a defined sequence. An N-bit binary counter cycles through \( 2^N \) states. The key distinction is synchronous vs asynchronous:

Synchronous Counter

All flip-flops clocked simultaneously. No ripple delay. Faster and easier to analyze. Used in most modern designs.

\( T_i = Q_0 Q_1 \cdots Q_{i-1} \)
Asynchronous (Ripple) Counter

Each flip-flop clocked by the output of the previous. Simpler to build but introduces cumulative propagation delay (ripple).

\( t_{prop} = N \times t_{FF} \)

Specialty counters include the ring counter (single 1 bit circulating — N states from N FFs) and the Johnson counter (complemented output fed back — 2N states from N FFs, no glitches).

4. Python: 4-Bit Counter & D Flip-Flop Timing Diagram

Simulate a 4-bit synchronous binary counter over 16 clock cycles, plot Q0–Q3 timing waveforms, and show D flip-flop capture behavior with a random data input.

Python
script.py123 lines

Click Run to execute the Python code

Code will be executed with Python 3 on the server