Digital LogicUnit 513 min read
Sequential Circuits & State Machines: Flip-Flops, Counters, FSMs, Timing
Unit 5 of Digital Logic covers sequential circuits (flip-flops, registers, counters) and state machines (Mealy/Moore), their timing diagrams, design methods, and real-world applications in memory, processors, and control systems.
TAKEAWAYS:
- Sequential circuits remember past inputs via feedback, unlike combinational circuits that depend only on current inputs.
- Flip-flops (D, JK, T, SR) are the building blocks of memory and sequential logic, with master-slave configurations for edge-triggering.
- Counters (ripple, synchronous) and registers (shift, ring) are designed using flip-flops and are critical in clocked systems (e.g., CPU program counters).
- Finite State Machines (FSMs) model sequential behavior with states, transitions, and outputs, classified as Moore (outputs depend only on state) or Mealy (outputs depend on state + input).
- Timing diagrams are essential for analyzing race conditions, glitches, and setup/hold violations in sequential circuits.
- Design methods include state reduction, state assignment, and excitation tables to convert FSM specifications into hardware.
Sequential vs. Combinational Circuits
Sequential circuits store information (memory) and their outputs depend on current inputs + past states, unlike combinational circuits (AND, OR, XOR gates) that depend only on current inputs.
flowchart LR
A["Combinational\nCircuits"] -->|"No Memory"| B["Output = f(Input)\n(AND, OR, XOR, MUX)"]
C["Sequential\nCircuits"] -->|"Memory (Flip-Flops)"| D["Output = f(Input, State)\n(Counters, Registers, FSMs)"]
B -->|"Example: ALU"| E["No clock needed"]
D -->|"Example: CPU<br/>Registers"| F["Clock-driven\n(Edge-triggered)"]Why does this matter?
- Combinational circuits are faster (no memory delay) but cannot remember.
- Sequential circuits are slower (due to clock) but enable memory, timing, and control (e.g., a bank ATM remembers your PIN across transactions).
Flip-Flops: The Memory Element
Flip-flops are clocked bistable multivibrators that store 1 bit and change state on a clock edge. They are the fundamental building blocks of sequential circuits.
Types of Flip-Flops
| Type | Symbol (Standard) | Inputs | Key Feature | Applications |
|---|---|---|---|---|
| SR | S, R, Clock | Asynchronous reset/set (level-triggered) | Simple memory elements | |
| D | D, Clock | Direct data transfer (D → Q) | Registers, data storage | |
| JK | J, K, Clock | Universal flip-flop (can emulate SR, D, T) | Counters, sequential circuits | |
| T | T, Clock | Toggle on T=1 | Binary counters |
Master-Slave Configuration
To avoid race conditions, flip-flops use a master-slave structure where:
- Master flip-flop captures input on the first clock edge.
- Slave flip-flop outputs the master’s state on the second edge. This ensures edge-triggered behavior (no glitches).
flowchart LR
A["Clock"] -->|"Rising Edge"| B["Master Flip-Flop\n(Captures Input)"]
B --> C["Slave Flip-Flop\n(Outputs on next edge)"]
C -->|"Q"| D["Output"]
A -->|"Falling Edge"| CWorked Example: D Flip-Flop Operation Assume a D flip-flop with initial state . Draw the timing diagram for inputs and clock pulses.
| Clock | D | Q (Output) | Explanation |
|---|---|---|---|
| 0 | 1 | 0 | Initial state |
| ↑ | 1 | 1 | Rising edge: |
| 1 | 0 | 1 | D changes but no edge |
| ↑ | 0 | 0 | Rising edge: |
Visual:
Counters: Sequential Circuit Applications
Counters are sequential circuits that increment/decrement on clock pulses. They use flip-flops and are classified as:
- Asynchronous (Ripple) Counters: Flip-flops connected in cascade (each flip-flop’s output clocks the next).
- Synchronous Counters: All flip-flops clocked simultaneously (faster, no propagation delay).
Ripple Counter (Asynchronous)
Design: Each flip-flop’s output is the clock input for the next flip-flop. Example: 3-bit binary counter using T flip-flops.
flowchart LR
A["Clock"] --> B["T Flip-Flop 0\n(Q0)"]
B --> C["T Flip-Flop 1\n(Q1)"]
C --> D["T Flip-Flop 2\n(Q2)"]
B -->|"Q0"| E["Output"]
C -->|"Q1"| E
D -->|"Q2"| EProblem: Propagation delay increases with bits (slow for large counters). Solution: Use synchronous counters.
Synchronous Counter
Design: All flip-flops clocked simultaneously; use AND/OR gates for control signals. Example: 3-bit up-counter using JK flip-flops.
Advantages:
- Faster (no ripple delay).
- Used in CPU program counters, timers, and digital clocks.
Registers: Temporary Data Storage
Registers store multiple bits (e.g., 8-bit, 16-bit) and are built using flip-flops + control logic. Types:
- Parallel Load Register: Loads data simultaneously on a load signal.
- Shift Register: Shifts data left/right on clock pulses.
- Ring Counter: Circular shift register (used in sequencers).
Example: 4-bit Parallel Load Register
Real-World Use:
- CPU registers (e.g., Accumulator, Program Counter).
- Memory buffers in Khalti transactions (storing temporary data during payment processing).
Finite State Machines (FSMs)
FSMs model sequential behavior with:
- States (e.g., "Idle", "Processing").
- Transitions (triggered by inputs).
- Outputs (Moore or Mealy).
Moore vs. Mealy Machines
| Feature | Moore Machine | Mealy Machine |
|---|---|---|
| Output | Depends only on state | Depends on state + input |
| Speed | Slower (output changes only on state change) | Faster (output can change with input) |
| Design | Simpler for control-dominated systems | Used in data-path systems |
| Example | Traffic light controller | Calculator (output depends on current operation) |
Example: Traffic Light Controller (Moore Machine) States: Red, Green, Yellow. Transitions:
- Red → Green (after timer).
- Green → Yellow (after timer).
- Yellow → Red (immediately).
stateDiagram-v2
[*] --> Red
Red --> Green: Timer
Green --> Yellow: Timer
Yellow --> Red: ImmediateWorked Example: Vending Machine (Mealy Machine)
- States: Idle, Selecting, Dispensing.
- Outputs: Display message, release product.
- Transition: If coin inserted in "Selecting" → go to "Dispensing" and output "Product released".
Designing FSMs: Step-by-Step
- State Diagram: Draw transitions and outputs.
- State Reduction: Merge equivalent states.
- State Assignment: Assign binary codes to states (e.g., Gray code to minimize glitches).
- Excitation Tables: Determine flip-flop inputs (J, K, D, T) for each state transition.
- Next-State and Output Equations: Use Boolean algebra to derive logic.
- Implementation: Use flip-flops + combinational logic.
Example: Binary Sequence Detector (Detects "101")
Excitation Table for D Flip-Flops:
| Present State | Next State | Input | D0 | D1 |
|---|---|---|---|---|
| S0 | S1 | 1 | 1 | 0 |
| S0 | S0 | 0 | 0 | 0 |
| S1 | S2 | 0 | 0 | 1 |
| S1 | S1 | 1 | 1 | 0 |
| ... | ... | ... | ... | ... |
Timing Diagrams and Hazards
Timing diagrams show signal transitions over time and are critical for debugging sequential circuits.
Common Issues:
- Race Condition: Multiple paths with different delays (e.g., in ripple counters).
- Glitches: Short unwanted pulses due to propagation delay mismatches.
- Setup/Hold Violations: Data not stable when clocked (causes metastability).
Example: Glitch in a Combinational Circuit
Solutions:
- Use synchronous designs (avoid ripple counters).
- Add delay elements or hazard-free logic.
- Use master-slave flip-flops for edge-triggering.
In the Real World
Khalti Payment System
- FSM Application: The transaction state machine manages:
- Idle → Processing (on user input).
- Processing → Complete (on bank confirmation).
- Complete → Idle (after receipt).
- Flip-Flops: Used in microcontroller registers to store transaction status.
- FSM Application: The transaction state machine manages:
Ncell’s Call Routing
- Sequential Circuit: The phone call state machine transitions through:
- Dialing → Connecting → Active → End.
- Counters: Used in call duration timers (e.g., prepaid call minutes).
- Sequential Circuit: The phone call state machine transitions through:
Daraz Order Fulfillment
- Registers: Store order IDs in temporary buffers during processing.
- Counters: Track inventory levels in real-time (e.g., "Only 3 left in stock").
NTC Traffic Light Control
- Moore FSM: Manages Red → Green → Yellow cycles with fixed timers.
- Flip-Flops: Store the current light state (Red/Green/Yellow).
Bank Loan Interest Calculation (Nepal Bank)
- Sequential Logic: The loan processing system uses FSMs to:
- Apply → Verify → Approve/Reject → Disburse.
- Registers: Store customer data (name, loan amount, interest rate).
- Sequential Logic: The loan processing system uses FSMs to:
Practical Example: Traffic Light Controller (Full Design)
Problem: Design a 3-state traffic light controller (Red, Green, Yellow) with:
- Red: 30 sec → Green: 20 sec → Yellow: 5 sec → Repeat.
- Use JK flip-flops and a 555 timer IC for timing.
Solution:
- State Diagram:
stateDiagram-v2 [*] --> Red Red --> Green: Timer=30s Green --> Yellow: Timer=20s Yellow --> Red: Timer=5s - State Assignment:
State Q2 Q1 Q0 Red 0 0 0 Green 0 0 1 Yellow 0 1 0 - Excitation Table (for JK flip-flops):
Present State Next State J2 K2 J1 K1 J0 K0 000 (Red) 001 (Green) 0 1 0 1 1 1 001 (Green) 010 (Yellow) 0 1 1 1 0 1 010 (Yellow) 000 (Red) 0 1 0 1 0 1 - Circuit Implementation:
- Use 3 JK flip-flops + AND/OR gates for control.
- 555 Timer generates clock pulses (e.g., 1 pulse per second).
Exam Tip
Understand Flip-Flop Behavior:
- Know D, JK, T, SR flip-flops and their characteristic equations.
- Always draw timing diagrams for sequential circuits (examiners love this!).
FSM Design Steps:
- State diagram → State reduction → State assignment → Excitation table → Logic equations.
- Moore vs. Mealy: Identify which is used in the question.
Counters:
- Ripple vs. Synchronous: Know when to use each (speed vs. complexity).
- Up/down counters: Be able to design both.
Timing Hazards:
- Glitches and race conditions are common exam questions. Explain how to avoid them (e.g., using synchronous design).
Real-World Applications:
- Traffic lights, vending machines, CPUs are classic examples. Relate theory to these in answers.
Shortcut for Excitation Tables:
- For JK flip-flops, use:
- For D flip-flops, .
Practical Exam Questions:
- Design a 4-bit counter (ripple or synchronous).
- Implement a binary sequence detector (e.g., "110").
- Analyze a given timing diagram (identify glitches, races).
Final Note: Sequential circuits are everywhere in digital systems. Master flip-flops, counters, and FSMs, and you’ll ace the exam—and understand how CPUs, smartphones, and even traffic lights work!
Based on the TU BIM syllabus for Digital Logic (IT233), unit 5.
Discussion
Loading…