Second Year Electronics Engineering

Introduction to Logic
Design with Verilog

Unit 1 · System Design using Verilog  |  Dept. of Electronics Engineering (VLSI D&T)

Subject Code: 2AF13/5PC412
Credits: 2
Hours: 8
HDL: Verilog
Scroll to explore
Unit 1 · 8 Hours

What Is This Chapter About?

🧠 Structural Models

Design circuits by connecting gates and modules, just like assembling a smartphone motherboard.

⚙️ Behavioural Models

Describe what a circuit does, not how it's built — like writing an app in code.

🔬 Logic Simulation

Test your design virtually before burning it to actual silicon or an FPGA chip.

📐 Design Verification

Truth tables, test methodology, propagation delay — ensure correctness before fabrication.

🔄 Sequential Logic

Logic with memory — flip-flops, latches, state machines (like OTP logic on your phone).

📦 Verilog Modules

The building blocks of Verilog — ports, data-flow, gate types, operators, operands.

Topic 1

What Is HDL & Verilog?

📖Hardware Description Language (HDL)

An HDL is a programming language used to model electronic systems. Unlike C or Python that run on CPUs, HDL code describes the actual hardware that you want to synthesise (build) on a chip or FPGA.

Indian Daily Life Analogy

Think of Verilog like a house blueprint (naksha). When you ask an architect to build a 3BHK flat in Mumbai, you give them a blueprint — it describes every room, wire, and pipe. The builder (synthesis tool) then constructs the actual flat (chip). Verilog is that blueprint for digital circuits!

🔧Why Verilog?

Verilog is the industry-standard HDL. It is used by companies like Intel, NVIDIA, Qualcomm (makers of chips in your Jio 5G phone) to design billions of logic gates. It has a C-like syntax, making it accessible for engineering students.

💡

Did you know? The Snapdragon processor inside most Indian flagship smartphones (OnePlus, Redmi, Realme) was designed using Verilog HDL before being manufactured in TSMC's fab in Taiwan!

🏗️Levels of Abstraction in Verilog

1. Gate Level (Structural)

Describes the circuit using primitive gates: and, or, not, nand, nor, xor. Like building a LEGO model piece by piece.

2. Data-Flow (RTL)

Describes how data flows using assign statements and expressions. Like writing the formula for a calculation.

3. Behavioural (Algorithmic)

Describes circuit behaviour using always blocks and procedural statements. Closest to software programming.

4. Switch Level

Describes circuits at the MOSFET transistor level — the most detailed, rarely used in typical design.

Topic 2

Structural Models

🔌Gate-Level Modelling

Structural modelling involves connecting basic logic gates like a circuit diagram. You instantiate gates and connect them using nets (wires).

Daily Life Example – UPI Transaction Logic

Imagine a UPI payment: the transaction succeeds only if your balance is sufficient AND the internet is available AND the receiver's UPI ID is valid. This is a 3-input AND gate!

// UPI Success = Balance_OK AND Internet_OK AND UPI_ID_Valid and upi_gate(success, balance_ok, internet_ok, upi_valid);
⚡ Verilog – 2-input AND Gate (Structural)
module and_gate (
    input  A, B,
    output Y
);
    and g1 (Y, A, B);  // primitive gate instantiation
endmodule
⚡ Verilog – Half Adder (Structural)
module half_adder (
    input  A, B,
    output Sum, Carry
);
    xor g1 (Sum, A, B);    // Sum = A XOR B
    and g2 (Carry, A, B);  // Carry = A AND B
endmodule
Half Adder Truth Table

Verifying the half adder — adding two single bits (like 1-bit processor flags):

ABSum (A⊕B)Carry (A·B)
0000
0110
1010
1101

📡Gate Delays & Propagation

In real hardware, gates are NOT instant. Signal takes time to pass through a gate — called propagation delay. In Verilog, we model this using #delay.

Example – WhatsApp Message Delay Analogy

When you send a WhatsApp message, it takes a small time to reach the server and then the recipient. Similarly, a signal through a NAND gate has a 2ns delay in real chips.

// Gate with propagation delay of 2 time units and #2 g1 (Y, A, B); // output Y appears 2 units after A,B change
Topic 3

Behavioural Models & Data-Flow

💻Data-Flow Modelling (assign statement)

Describes circuits using Boolean expressions with the assign keyword. This models how data flows through the circuit continuously.

⚡ Verilog – Half Adder (Data-Flow)
module half_adder_df (
    input  A, B,
    output Sum, Carry
);
    assign Sum   = A ^ B;   // XOR → bitwise exclusive-or
    assign Carry = A & B;   // AND → bitwise and
endmodule

🔄Behavioural Modelling (always block)

Uses always blocks with procedural statements. Can model both combinational and sequential circuits. Sensitive list controls when the block executes.

Daily Life Example – Zomato Order Status

Your Zomato app always watches (always @) the order status. Whenever it changes (Placed → Accepted → Out for Delivery → Delivered), the app updates the UI. Similarly, always @(A or B) means "run this block whenever A or B changes."

⚡ Verilog – 4:1 MUX (Behavioural)
module mux4to1 (
    input  [3:0] D,      // 4 data inputs
    input  [1:0] SEL,    // 2-bit select
    output reg  Y
);
    always @(D or SEL) begin
        case (SEL)
            2'b00: Y = D[0];
            2'b01: Y = D[1];
            2'b10: Y = D[2];
            2'b11: Y = D[3];
        endcase
    end
endmodule
MUX Analogy – DTH Set-Top Box Channel Selector

A 4:1 MUX is like your Tata Sky / Airtel DTH remote: you have 4 incoming channels (inputs D0–D3), and the channel number buttons (SEL) select which one appears on your TV screen (output Y). Only one channel is displayed at a time!

🧩Continuous vs. Procedural Assignment

Continuous (assign)

Always active. Used for combinational logic. Output updates automatically whenever any input changes.

assign Y = A & B;

Procedural (always)

Executes when triggered by sensitivity list. Used for both combinational and sequential logic.

always @(posedge clk)
Topic 4

Sequential Logic Basics

⏱️What is Sequential Logic?

Sequential circuits have memory — the output depends not just on current inputs, but also on past history. They are driven by a clock signal.

Example – ATM PIN Entry

When you enter your SBI ATM PIN, the machine remembers each digit you pressed (it stores state). After 4 digits, it checks the sequence. This is exactly how a sequential FSM (Finite State Machine) works — it remembers what happened before!

🔁D Flip-Flop – The Basic Memory Cell

A D flip-flop captures the value of input D on the rising edge of the clock and holds it until the next clock edge.

⚡ Verilog – D Flip-Flop (Behavioural)
module d_ff (
    input  D, clk, rst,
    output reg Q
);
    always @(posedge clk or posedge rst) begin
        if (rst)
            Q <= 1'b0;  // synchronous reset
        else
            Q <= D;     // capture D on rising clock edge
    end
endmodule
D Flip-Flop – IRCTC Ticket Booking Analogy

In IRCTC tatkal booking at 10:00 AM exactly: the moment the clock "ticks" to 10:00 (rising edge), whatever the system was holding (train & class selected = D input) gets confirmed into your booking (Q output) and held until you cancel. That's a D flip-flop!

clk (edge)rstDQ (next)
↑ Rising1X0 (Reset)
↑ Rising000
↑ Rising011
No edgeXXQ (hold)
Topic 5

Verilog Modules & Ports

📦Module Structure

A module is the fundamental building block of Verilog. Every design starts with module and ends with endmodule. Ports define the interface (inputs/outputs).

⚡ Verilog – Module Anatomy
module module_name (port_list);  // declaration

    // 1. Port declarations
    input  wire A, B;       // input ports
    output wire Y;          // output port
    inout  wire Z;          // bidirectional (e.g. I2C bus)

    // 2. Internal signals
    wire  temp;             // internal net
    reg   count;            // register (holds value)

    // 3. Logic (structural / data-flow / behavioural)
    assign Y = A & B;

endmodule
Example – Smartphone as a Module

Your Redmi smartphone is a module:
Inputs: touchscreen, mic, camera, USB-C charger
Outputs: speaker, display, vibration motor
Internal registers: RAM, storage (holds data)
Logic: the processor running MIUI (the always block!)

🔗Module Instantiation

A module can be used inside another module — called instantiation. Like reusing a standard LEGO block in multiple builds.

⚡ Verilog – Full Adder using 2 Half Adders
module full_adder (
    input  A, B, Cin,
    output Sum, Cout
);
    wire s1, c1, c2;

    // Instantiate half adder modules
    half_adder HA1 (.A(A),  .B(B),   .Sum(s1), .Carry(c1));
    half_adder HA2 (.A(s1), .B(Cin), .Sum(Sum),.Carry(c2));

    or g1 (Cout, c1, c2);
endmodule
Topic 6

Operators, Operands & Data Types

🔢Data Types

TypeUseExample
wireNets/connectionswire Y;
regHolds value in alwaysreg Q;
integerInteger loopsinteger i;
parameterConstantsparameter N=8;

⚙️Number Format

Format: size'base value

ExampleMeaning
4'b10104-bit binary 10
8'hFF8-bit hex 255
8'd2008-bit decimal 200
1'b01-bit binary 0

Operators in Verilog

CategoryOperatorsExampleResult
Bitwise& | ^ ~ ^~4'b1010 & 4'b11004'b1000
Logical&& || !1 && 00
Reduction&A |A ^A&4'b11111
Relational== != > < >= <=A == B1 or 0
Shift<< >>4'b0001 << 24'b0100
Arithmetic+ - * / %3 + 58
Conditional? :SEL ? A : BA if SEL=1
Concatenation{ }{A,B} A=1,B=02'b10
Operators – Phone Battery Analogy

Conditional operator: Your phone shows "Low Battery" warning — battery < 20 ? red_icon : green_icon
Shift left (<<): Doubling a value is like switching from 4G to 5G — double the speed, same data.
Concatenation {}: Like merging two Jio SIM contacts lists into one phone book.

Practice Zone

🎯 20 MCQs – Test Yourself!

Click an option to answer. Instant feedback with explanations!

⏱️ Take your time 0 / 20 answered ✅ 0 correct

Your Score: 0/20

Keep practicing — you've got this! 💪

Short Answer Questions

📝 10 Short Questions with Answers

Click on any question to reveal the answer. Ideal for 2–3 mark questions.

Long Answer Questions

📚 10 Long Questions with Detailed Answers

Click to expand. These cover 5–10 mark university questions.