Digital Logic Design
From logic gates to FSMs and Verilog—understand how 1s and 0s drive complex hardware decisions. Digital logic is the foundation of all digital electronics, from simple flip-flops to modern processors.
Logic Gates
Logic gates are the fundamental building blocks of digital circuits. They perform basic boolean operations on binary inputs.
Basic Gates
AND OR NOT NAND NOR XOR XNOR
AND Gate Truth Table
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
XOR Gate Truth Table
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
💡 Universal Gates: NAND and NOR gates are called "universal gates" because any logic function can be implemented using only NAND gates (or only NOR gates)!
Boolean Algebra
Boolean algebra provides the mathematical foundation for analyzing and simplifying digital circuits.
Key Laws
- Identity: A + 0 = A, A · 1 = A
- Null: A + 1 = 1, A · 0 = 0
- Complement: A + A' = 1, A · A' = 0
- De Morgan's: (A · B)' = A' + B', (A + B)' = A' · B'
- Distributive: A · (B + C) = A·B + A·C
Simplification Example
Combinational Logic
Combinational circuits have outputs that depend only on current inputs—no memory or feedback.
Common Combinational Circuits
- Multiplexer (MUX): Selects one of many inputs based on select lines
- Demultiplexer (DEMUX): Routes one input to one of many outputs
- Decoder: Converts binary code to one-hot encoding
- Encoder: Converts one-hot to binary code
- Adder: Half-adder, Full-adder, Ripple-carry adder
- Comparator: Compares two binary numbers
Sequential Logic
Sequential circuits have memory—outputs depend on both current inputs and past states.
Flip-Flops
- SR Flip-Flop: Set-Reset, basic memory element
- D Flip-Flop: Data/Delay, captures input on clock edge
- JK Flip-Flop: No invalid state, toggle capability
- T Flip-Flop: Toggle mode, useful for counters
D Flip-Flop in Verilog
Finite State Machines (FSM)
FSMs model systems that transition between a finite number of states based on inputs. They're essential for control logic, protocol handling, and sequential behavior.
FSM Types
- Mealy Machine: Outputs depend on current state AND inputs
- Moore Machine: Outputs depend only on current state
FSM Example: Traffic Light Controller
Introduction to Verilog
Verilog is a Hardware Description Language (HDL) used to model, simulate, and synthesize digital circuits.
Verilog Basics
Key Verilog Concepts
- wire: Continuous assignment, combinational connections
- reg: Procedural assignment, can hold state
- assign: Continuous (combinational) assignment
- always @(*): Combinational logic block
- always @(posedge clk): Sequential logic block
- Blocking (=) vs Non-blocking (<=): Use = for combinational, <= for sequential
4-bit Counter in Verilog
Timing Concepts
- Setup Time: Data must be stable before clock edge
- Hold Time: Data must remain stable after clock edge
- Propagation Delay: Time for signal to travel through a gate
- Clock-to-Q Delay: Time from clock edge to output change
- Critical Path: Longest combinational path, determines max frequency
⚡ Timing Violation: If setup or hold times are violated, the flip-flop may enter a metastable state, leading to unpredictable behavior!
FPGA Implementation
FPGAs (Field-Programmable Gate Arrays) allow you to implement custom digital logic in hardware:
- LUTs (Look-Up Tables): Implement combinational logic
- Flip-Flops: Implement sequential logic
- Block RAM: On-chip memory
- DSP Blocks: Optimized for math operations
- I/O Blocks: Interface with external pins
Popular FPGA development boards:
Xilinx Artix-7 Intel Cyclone V Lattice iCE40 Gowin GW1N
🎯 Key Takeaway: Digital logic design bridges the gap between software concepts and physical hardware. Master gates, flip-flops, FSMs, and Verilog to design custom digital systems from scratch!