← Back to Studying Paths

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.

[Diagram: Digital system with combinational and sequential logic blocks]

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

Simplification Example

// Original expression F = A'BC + AB'C + ABC' + ABC // Factor out common terms F = A'BC + AB'C + AB(C' + C) F = A'BC + AB'C + AB // This is the simplified Sum-of-Products form // Can be further simplified using K-maps

Combinational Logic

Combinational circuits have outputs that depend only on current inputs—no memory or feedback.

Common Combinational Circuits

[Diagram: 4-to-1 Multiplexer with select lines S1, S0]

Sequential Logic

Sequential circuits have memory—outputs depend on both current inputs and past states.

Flip-Flops

D Flip-Flop in Verilog

// Positive-edge triggered D Flip-Flop with reset module d_ff ( input wire clk, input wire rst_n, // Active-low reset input wire d, output reg q ); always @(posedge clk or negedge rst_n) begin if (!rst_n) q <= 1'b0; else q <= d; end endmodule

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

[Diagram: State diagram for a traffic light controller]

FSM Example: Traffic Light Controller

// Traffic Light FSM in Verilog module traffic_light ( input wire clk, input wire rst_n, output reg [2:0] light // {Red, Yellow, Green} ); // State encoding localparam S_GREEN = 2'b00; localparam S_YELLOW = 2'b01; localparam S_RED = 2'b10; reg [1:0] state, next_state; reg [3:0] counter; // State register always @(posedge clk or negedge rst_n) begin if (!rst_n) state <= S_RED; else state <= next_state; end // Next state logic always @(*) begin case (state) S_GREEN: next_state = (counter == 10) ? S_YELLOW : S_GREEN; S_YELLOW: next_state = (counter == 3) ? S_RED : S_YELLOW; S_RED: next_state = (counter == 10) ? S_GREEN : S_RED; default: next_state = S_RED; endcase end // Output logic (Moore - depends only on state) always @(*) begin case (state) S_GREEN: light = 3'b001; // Green on S_YELLOW: light = 3'b010; // Yellow on S_RED: light = 3'b100; // Red on default: light = 3'b100; endcase end endmodule

Introduction to Verilog

Verilog is a Hardware Description Language (HDL) used to model, simulate, and synthesize digital circuits.

Verilog Basics

// Module definition module my_module ( input wire [7:0] data_in, input wire enable, output reg [7:0] data_out ); // Combinational logic using assign wire [7:0] inverted = ~data_in; // Sequential logic using always block always @(posedge clk) begin if (enable) data_out <= data_in; end endmodule

Key Verilog Concepts

4-bit Counter in Verilog

module counter_4bit ( input wire clk, input wire rst_n, input wire enable, output reg [3:0] count ); always @(posedge clk or negedge rst_n) begin if (!rst_n) count <= 4'b0000; else if (enable) count <= count + 1; end endmodule

Timing Concepts

⚡ 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:

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!