First Year Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Flip-flops and counters

Flip-flops (RS, JK, D, T), timing (setup/hold, propagation, metastability), and counters (ripple, synchronous, up/down, mod‑N, ring, Johnson), with design using excitation tables and timing limits.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Flip-flops and counters are the basic memory and counting elements inside digital systems. Engineers use them in timers, frequency dividers, sequence controllers, microcontroller peripherals, digital instruments (like oscilloscopes), communication timing recovery, and IoT data acquisition.

Key ideas

  • Latch: A level-sensitive 1‑bit storage element whose output can change as long as an enable (or the input) is active. Common latches are SR (using NOR or NAND) and D latches.
  • Flip-flop (FF): An edge-triggered 1‑bit storage element that samples input only on a clock edge (rising or falling) and holds it stable until the next active edge. Flip-flops are the standard memory cells in synchronous systems.
  • Asynchronous (ripple) vs synchronous systems: In asynchronous (ripple) counters, clocking ripples from one FF to the next; in synchronous counters, one common clock drives all FFs simultaneously, with next-state logic deciding state transitions.

Basic latches and flip-flops (what to draw in exams):

  • SR latch with NOR gates: Draw two cross-coupled NOR gates. Label inputs S (set) and R (reset), outputs Q and Q̄ (complement). Truth behavior: S=1 forces Q=1; R=1 forces Q=0; S=R=0 holds state; S=R=1 is invalid (both outputs forced 0 for NOR latch). State the invalid condition.
  • SR latch with NAND gates (active-low inputs S̄, R̄): Draw two cross-coupled NANDs. Inputs are active-low: S̄=0 sets Q=1; R̄=0 resets Q=0; S̄=R̄=1 holds; S̄=R̄=0 is invalid (both outputs 1).
  • D latch (level-sensitive): Combine SR with a gate so that R and S are generated from D and enable (EN). For a positive level-sensitive latch: S = D·EN, R = D̄·EN. Draw EN gating into two AND gates feeding an SR latch.
  • Edge-triggered flip-flop: Typically built from a master-slave latch pair or transmission-gate design to ensure sampling only on clock edge. For a model diagram, draw master (level-sensitive when CLK=1) feeding slave (level-sensitive when CLK=0) for a negative-edge triggered FF, and label CLK, D, Q.

Named flip-flops and their excitation/characteristic behavior:

  • SR flip-flop (synchronous SR): Inputs S and R are sampled on the clock edge. S=1, R=0 sets Q=1; S=0, R=1 resets Q=0; S=R=0 holds; S=R=1 is invalid (for classic SR). Often avoided due to invalid state.
  • JK flip-flop: Like SR but with the invalid condition resolved. Inputs J and K. On active clock edge: J=1, K=0 sets; J=0, K=1 resets; J=K=0 holds; J=K=1 toggles (Q next = Q̄ current). Draw a block with J, K, CLK, Q.
  • D flip-flop: Data flip-flop. On active clock edge, Q next = D. Eliminates invalid input combinations. Most commonly used in synchronous design.
  • T flip-flop: Toggle flip-flop. On active clock edge, if T=1 then Q toggles; if T=0, Q holds. Can be built by tying J=K=T of a JK FF, or by feeding D = T ⊕ Q into a D FF.

Formal definitions and tables:

  • Characteristic equation (exact statement): The characteristic equation of a flip-flop gives the next state Q(n+1) as a function of present state Q(n) and inputs. For D: Q(n+1) = D. For T: Q(n+1) = T ⊕ Q(n). For JK: Q(n+1) = J·Q̄(n) + K̄·Q(n).
  • Excitation table (exact statement): The excitation table lists the required input values to cause a desired transition from present state Q(n) to next state Q(n+1). Students use it for flip-flop conversion and counter design. For example, for JK: Q(n)→Q(n+1) of 0→0 needs J=0, K=X; 0→1 needs J=1, K=X; 1→0 needs J=X, K=1; 1→1 needs J=X, K=0 (X = don’t care).

Timing terms (with exact statements):

  • Propagation delay (t_pd): Time from a defined input change (e.g., clock edge) to the corresponding valid output change. For flip-flops, clock-to-Q delay t_clk→Q is used.
  • Setup time (t_setup): Minimum time interval before the active clock edge during which the data input must be stable.
  • Hold time (t_hold): Minimum time interval after the active clock edge during which the data input must remain stable.
  • Metastability: A temporary, unstable analog state of a flip-flop output when setup/hold are violated, during which Q is neither valid logic 0 nor 1 for an unbounded time. Practical designs add synchronizers (two D FFs in series) for asynchronous inputs to reduce probability of failure.
  • Race-around condition (JK FF, level-sensitive): In a level-sensitive JK latch with J=K=1 and long clock high time, Q can toggle repeatedly (race-around). Mitigation: use edge-triggered or master-slave FFs or limit clock pulse width to < propagation time.

Counters (classification and operation):

  • Counter: A sequential circuit that goes through a predefined sequence of states on each clock pulse, usually representing binary numbers.
  • Modulus (mod-N): The number of unique states in the counter’s sequence before it repeats. For an n-bit binary counter without skipping, N = 2^n. A decade counter has mod‑10.
  • Ripple (asynchronous) counter: Each FF’s output clocks the next FF. LSB FF is driven by the main clock; higher bits toggle when the previous bit transitions. Simple but suffers from cumulative delay and glitches on intermediate states.
  • Synchronous counter: All FFs are clocked from the common clock; combinational logic determines each FF’s toggle or D input so that the entire state changes simultaneously at the clock edge. Faster and glitch-resistant at outputs (still, decoding logic must be designed carefully).
  • Up, down, and up/down counters: Up counts incrementing binary numbers; down decrements; up/down can switch direction via a control signal.
  • Ring counter: A shift-register-based counter in which a single ‘1’ circulates through n FFs, giving mod‑n behavior. Requires preset/clear to initialize a single ‘1’.
  • Johnson (twisted-ring) counter: The inverted output of the last FF feeds the input of the first. Produces 2n distinct states with n FFs; easier to decode than pure binary for some applications.

What to draw for counter diagrams in exams:

  • Ripple counter: Draw three JK FFs with J=K=1, Q of each feeding clock of the next; clock on the first FF only. Label Q0 (LSB), Q1, Q2. Show active edge (falling or rising) as given.
  • Synchronous counter: Draw three D FFs with a common clock. Show next-state logic into D0, D1, D2 using XOR/AND gates as per design (e.g., D0 = Q̄0, D1 = Q1 ⊕ Q0, D2 = Q2 ⊕ (Q1·Q0)). Label all signals.
  • Mod‑N counter: Show feedback reset logic that detects the terminal count and asynchronously clears or synchronously loads the next state to 0 (for decade, detect 1010₂=10 and reset to 0000₂).

Design flow you must know (commonly asked):

  1. Write the required state sequence (e.g., 000, 001, 010, …). 2) Choose FF type (JK or D are common). 3) Make a state table with present state (PS), next state (NS), and excitations per FF (use the excitation table). 4) Minimize input logic using Karnaugh maps. 5) Draw the final circuit. 6) Verify illegal states handling (self-correcting if possible).

Formulas

N = 2^n

  • N: number of states for a full binary counter (unitless). n: number of flip-flops (unitless). Applies to simple up/down binary counters without truncation.

n = ceil(log2 N)

  • n: number of flip-flops required (unitless). N: desired modulus (unitless). Applies when designing a mod‑N counter.

f_out = f_in / 2^n

  • f_out: output frequency at the nth stage (Hz). f_in: input clock frequency (Hz). n: number of cascaded divide-by-2 stages (unitless). Applies to binary ripple/synchronous counters used as frequency dividers.

T_clk(min) ≥ t_clk→Q(max) + t_comb(max) + t_setup

  • T_clk(min): minimum clock period for correct synchronous operation (s). t_clk→Q(max): maximum clock-to-Q delay of launching flip-flop (s). t_comb(max): maximum propagation delay of combinational logic between FFs (s). t_setup: setup time of receiving FF (s). Applies to synchronous designs.

t_hold ≤ t_clk→Q(min) + t_comb(min)

  • t_hold: required hold time of receiving FF (s). t_clk→Q(min): minimum clock-to-Q delay of launching FF (s). t_comb(min): minimum delay of combinational path between FFs (s). Ensures no hold violation.

f_max(ripple) ≈ 1 / (n · t_pdFF)

  • f_max(ripple): approximate maximum input clock frequency of an n-stage ripple counter (Hz). t_pdFF: propagation delay per stage (s). Assumes worst-case additive delay through n toggles and active edge sensitivity.

t_reset_pulse ≥ t_async_clear(min)

  • t_reset_pulse: applied asynchronous clear/preset pulse width (s). t_async_clear(min): minimum width from datasheet (s). Applies when using asynchronous reset.

P_dynamic ≈ α · C_L · V_DD^2 · f_clk

  • P_dynamic: dynamic power (W). α: average switching activity (unitless). C_L: load capacitance (F). V_DD: supply voltage (V). f_clk: clock frequency (Hz). Useful to compare ripple vs synchronous power qualitatively.

Worked examples

Example 1: Maximum input clock for a 4-bit ripple counter Given: A 4-bit ripple counter uses JK FFs (J=K=1) with clock-to-Q propagation delay t_pdFF = 40 ns per FF. What is the maximum input clock frequency without counting errors? Also, what is the output frequency at Q3 when driven at f_in(max)?

Steps:

  1. Formula: f_max(ripple) ≈ 1 / (n · t_pdFF).
  2. Substitute numbers: n = 4, t_pdFF = 40 ns = 40 × 10^−9 s.
  3. Compute: n · t_pdFF = 4 × 40 ns = 160 ns = 160 × 10^−9 s.
  4. f_max ≈ 1 / 160 ns = 1 / (160 × 10^−9) Hz = 6.25 MHz.
  5. Output frequency at Q3 (MSB) in a binary counter is f_out = f_in / 2^n = f_in / 16.
  6. Substitute: f_in = 6.25 MHz → f_Q3 = 6.25 MHz / 16 = 0.390625 MHz = 390.625 kHz.

Answer: f_max ≈ 6.25 MHz, and at that input, Q3 toggles at about 390.625 kHz. Final: f_max = 6.25 MHz; f_Q3 = 390.625 kHz.

Example 2: Design a synchronous mod‑10 (decade) counter using JK flip-flops Task: Design a 4-bit synchronous up-counter that counts 0000 to 1001 (0 to 9) and then rolls over to 0000. Show equations and a labeled diagram description.

Steps:

  1. Choose FF type: JK FFs.
  2. States used: 0000 (0) to 1001 (9). Unused: 1010–1111. Ensure unused states go to valid sequence (self-correct with logic or reset when 1010 is detected).
  3. Write PS→NS for 0000→0001→0010→0011→0100→0101→0110→0111→1000→1001→0000.
  4. Determine excitations per bit using JK excitation table:
  • For Q0 (LSB): toggles every count → J0 = 1, K0 = 1.
  • For Q1: toggles when Q0 = 1 (on 01→10 and 11→00 transitions). For a synchronous binary counter up to 15, J1 = K1 = Q0. But for mod‑10, need to inhibit after 1001.
  • For Q2: in full binary, J2 = K2 = Q1·Q0. For mod‑10, adjust.
  • For Q3: in full binary, J3 = K3 = Q2·Q1·Q0. For mod‑10, adjust.
  1. Detect terminal count 1001 (Q3 Q2 Q1 Q0 = 1 0 0 1). Define a reset condition R10 = Q3 · Q0 · Q̄2 · Q̄1.
  2. Two approaches:
  • Asynchronous clear when R10 = 1: Drive CLR̄ inputs low via R10 (through gating to get active-low). This forces next state to 0000 immediately after reaching 1001. Simple but asynchronous.
  • Synchronous reset: Use R10 to force next-state inputs so that at the next clock edge after 1001 the state becomes 0000.
  1. Synchronous method (preferred in exams): Derive JK equations constrained by R10.
  • Start from full binary J/K: J0 = 1, K0 = 1. J1 = Q0, K1 = Q0. J2 = Q1·Q0, K2 = Q1·Q0. J3 = Q2·Q1·Q0, K3 = Q2·Q1·Q0.
  • Modify so that transition from 1001 goes to 0000. In state 1001, the desired NS is 0000, so all higher bits must reset instead of following binary increment. One common way is to gate each Jx/Kx with R̄10 so normal toggles are inhibited when at 1001, and additionally force clears in that state: Let N = R̄10 = (Q̄3 + Q2 + Q1 + Q̄0). Then use: J1 = N · Q0, K1 = N · Q0. J2 = N · (Q1·Q0), K2 = N · (Q1·Q0). J3 = N · (Q2·Q1·Q0), K3 = 1 when R10 = 1 (to reset Q3). Practically, K3 = N · (Q2·Q1·Q0) + R10. Similarly, K2, K1 may be augmented with R10 so they reset when at 1001.
  1. Final equations (one acceptable set): J0 = 1, K0 = 1. J1 = Q0 · N, K1 = Q0 · N + R10. J2 = Q1·Q0 · N, K2 = Q1·Q0 · N + R10. J3 = Q2·Q1·Q0 · N, K3 = Q2·Q1·Q0 · N + R10. where R10 = Q3·Q̄2·Q̄1·Q0 and N = Q̄3 + Q2 + Q1 + Q̄0.
  2. Draw the diagram: Four JK FF blocks with common clock. Connect J0=K0=1. Build logic gates to implement R10 and N. Feed each Jx/Kx as per equations. Label Q0..Q3, CLK, and show that from state 1001 next state is 0000 in your state table annotation. Note: Multiple equivalent minimal forms exist; any logically correct set earns full marks.

Answer: A synchronous decade counter can be realized with the above gated JK equations or by decoding 1001 and synchronously clearing to 0000. Show truth/state table and final logic for full credit.

Example 3: Clock period constraint in a synchronous counter and hold check Given: A 3-bit synchronous up-counter using D FFs. The next-state logic is: D0 = Q̄0, D1 = Q1 ⊕ Q0, D2 = Q2 ⊕ (Q1·Q0). Datasheet: t_clk→Q(max) = 90 ns, t_clk→Q(min) = 50 ns, t_setup = 20 ns, t_hold = 10 ns. Combinational delays: path to D2 has t_comb(max) = 60 ns, t_comb(min) = 15 ns; to D1: t_comb(max) = 40 ns, t_comb(min) = 10 ns; to D0: t_comb(max) = 20 ns, t_comb(min) = 5 ns. Find the minimum safe clock period and check hold for worst path.

Steps:

  1. Setup constraint per FF i: T_clk(min) ≥ t_clk→Q(max) + t_comb(max,i) + t_setup.
  2. Evaluate each path:
  • D0: 90 + 20 + 20 = 130 ns.
  • D1: 90 + 40 + 20 = 150 ns.
  • D2: 90 + 60 + 20 = 170 ns.
  1. Pick worst (largest): T_clk(min) = 170 ns.
  2. Maximum clock frequency: f_max = 1 / 170 ns ≈ 5.882 MHz.
  3. Hold check per path: Need t_clk→Q(min) + t_comb(min,i) ≥ t_hold.
  • D0: 50 + 5 = 55 ns ≥ 10 ns → OK.
  • D1: 50 + 10 = 60 ns ≥ 10 ns → OK.
  • D2: 50 + 15 = 65 ns ≥ 10 ns → OK.

Answer: Minimum clock period T_clk(min) = 170 ns (f_max ≈ 5.88 MHz). All hold checks pass.

Common mistakes

  • Forgetting invalid SR input (S=R=1 for NOR, or S̄=R̄=0 for NAND). Always state the invalid condition.
  • Ignoring setup/hold: Writing only propagation delay in timing answers; always include t_setup and t_hold constraints.
  • JK race-around confusion: Claiming race-around happens in edge-triggered FFs. It is a hazard of level-sensitive designs; edge-triggered FFs mitigate it.
  • Ripple counter decoding: Reading outputs mid-transition without considering ripple delays, causing wrong decoded numbers. For precise decoding, use synchronous counters or register the outputs before decoding.
  • Mod‑N design: Not handling unused states; the counter can get stuck. State what happens from any unused state (self-correct or reset).
  • Direction control in up/down counters: Forgetting to complement the carry chain or using wrong XOR polarity for D inputs, causing incorrect sequences.
  • Asynchronous clears: Driving CLR̄ directly from combinational logic without ensuring minimum pulse width or glitch filtering; prefer synchronous reset where possible.

For your exam

  • Short notes: JK FF and race-around; D FF internal structure; synchronizers for asynchronous inputs; ring and Johnson counters with state diagrams (draw n=4 cases).
  • Derivations: Characteristic equations of JK, T, and D FFs; T FF from JK: tie J = K = T (equivalently, J = T·Q̄ and K = T·Q); divide-by-2 property proof of T FF; T_clk(min) constraint for synchronous paths.
  • Designs: Synchronous mod‑N counter using JK or D FFs with K-map minimization; up/down counter with direction control; conversion (e.g., design T FF from D FF: D = T ⊕ Q).
  • Numericals: Maximum ripple counter frequency from given t_pd; output frequencies at each stage; timing budget problems including setup/hold.
  • Diagrams: Clearly labeled FF symbols, clocks (show rising/falling edge), preset/clear pins if used, and gating for decode/reset. For state diagrams, draw circles for states and arrows for transitions, label with input conditions if needed.
  • Full-marks answers include: neat diagram with labels, truth/state/excitation tables, minimized equations with justification (K-map or algebra), timing constraints calculated with units, and a concluding statement confirming operation (e.g., “sequence repeats after 10 states”).

Quick check

  1. How many flip-flops are needed for a mod‑12 synchronous counter? What is the MSB output frequency if driven by a 10 MHz clock?
  2. State the setup time and hold time constraints in a synchronous path between two D flip-flops.
  3. What is the main difference between a ring counter and a Johnson counter in terms of modulus with n flip-flops?

Answers: 1) n = ceil(log2 12) = 4; For a mod‑12 counter, the MSB does not divide by 16; its waveform repeats every 12 clock cycles, so f_MSB = 10 MHz / 12 ≈ 833.33 kHz (non‑50% duty cycle). 2) T_clk(min) ≥ t_clk→Q(max) + t_comb(max) + t_setup; and must have t_clk→Q(min) + t_comb(min) ≥ t_hold. 3) Ring counter has modulus n; Johnson counter has modulus 2n.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?