DSD Report

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

DIGITAL SYSTEM DESIGN

Introduction to Verilog HDL

Introduction

Verilog, standardized as IEEE 1364, is a hardware description language used to model electronic

systems. It is most commonly used in the design and verification of digital circuits at the

register-transfer level of abstraction.


Importance of Verilog HDL in Digital Design

● Industry Standard
Verilog has become the industry standard for digital design and verification.

● Design and Verification


Verilog HDL allows for efficient design and verification of complex digital systems.

● Reusability and Modularity


Verilog HDL promotes reusability and modularity, enabling faster development and
easier mainenance.

2
Verilog HDL vs. Traditional Programming Languages

Now, if we will talk about the verilog comparison with any traditional
programming language we will see that-

Hardware Description
Verilog HDL is specially designed for hardware description and digital
circuit modeling unlike any Traditional Programming Language.

Parallel Execution
Verilog HDL allows for parallel execution while Traditional
Programming Language is sequential.

3
Timing and Synchronization
Verilog HDL provides precise control over timing and
synchronization, unlike any Traditional Programming Language.

Different Types Of Verilog HDL

Now , if we will talking about its various type…the verilog is comprised of three
types-

● Structural Modeling

● Data-flow Modeling

● Behavioral Modeling

Let’s define them-

Structural Modeling-

It is the most basic type of Verilog modeling. It is used to describe the physical
structure of a digital circuit by using primitive gates and predefined modules.
Structural modeling is the most efficient type of Verilog modeling, but it can be the
most difficult to write.

DataFlow Modeling-

4
It is a more abstract type of Verilog modeling. It is used to describe the behavior of
a digital circuit by using conditional statements and assignment statements.
Dataflow modeling is easier to write than structural modeling, but it can be less
efficient.

Behavioral Modeling-

It is the most abstract type of Verilog modeling. It is used to describe the behavior
of a digital circuit by using a combination of conditional statements, assignment
statements, and procedural statements. Behavioral modeling is the easiest type of
Verilog modeling to write, but it can be the least efficient.

The following are examples of each type of Verilog modeling:


(Implementing FULL ADDER)

● Structural modeling:

module full_adder (
input a,
input b,
input cin,
output sum,
output cout);
wire half_adder_sum;
wire half_adder_cout;
half_adder (a, b, half_adder_sum, half_adder_cout);
xor (sum, half_adder_sum, cin);
and (cout, half_adder_cout, cin);
endmodule

● Dataflow modeling:

module full_adder (

5
input a,
input b,
input cin,
output sum,
output cout);
assign sum = (a ^ b) ^ cin;
assign cout = (a & b) | (a & cin) | (b & cin);
endmodule

● Behavioral modeling:

module full_adder (
input a,
input b,
input cin,
output sum,
output cout);
reg half_adder_sum;
reg half_adder_cout;
always @ (a, b) begin
{half_adder_sum, half_adder_cout} = a + b;
end
always @ (a, b, cin) begin
sum = (half_adder_sum ^ b) ^ cin;
cout = (a & b) | (a & cin) | (b & cin);
end
endmodule

Verilog HDL Simulation and Synthesis

It consists of three parts-


1. SIMULATION
2. SYNTHESIS
3. VERIFICATION

Defining them

● Simulation-Verilog HDL can be used to simulate the behavior of a


digital system before implementation.

● Synthesis-Verilog HDL can be synthesized to generate a hardware


description that can be implemented in silicon.

6
● Verification-Verilog HDL allows for the verification of digital designs
through the use of testbenches and assertions.

Verilog HDL Design Flow

It consists of three parts-


1. DESIGN SPECIFICATION
2. DESIGN ENTRY
3. SIMULATION AND VERIFICATION

Defining them-

● Design specification-Define the specifications and requirements


of the digital system using Verilog HDL.

● Design entry-Write the Verilog HDL code to describe the


behavior, data flow, and structure of the digital system.

● Simulation and verification-Simulate and verify the functionality


and performance of the digital system using testbenches and
assertions.

Commonly used Verilog HDL Constructs

1. Module- Defines the top-level entity in Verilog HDL.


Example-
module mux_2to1 (
input wire a,
input wire b,
input wire select,
output wire y);

7
assign y = (select == 1'b0) ? a : b;
endmodule

2. Wire- Defines a net for connecting modules.


Example-
module WireExample;
// Declare a 4-bit input bus
reg [3:0] input_bus;
// Declare a 4-bit output bus
wire [3:0] output_bus;
// Assign the wire to the input bus
assign output_bus = input_bus;
// Your logic goes here (you can manipulate input_bus)

3. Reg- Defines a register for storing data.


Example-
module RegExample;
// Declare a 4-bit register
reg [3:0] my_reg;
// Initial block to initialize the register
initial begin
// Assign a value to the register
my_reg = 4'b1010;
// Display the initial value
$display("Initial value of my_reg: %b", my_reg);
end
// Always block to simulate some logic that modifies the register
always @(posedge clk) begin
// Example: Increment the register on each positive clock edge
my_reg <= my_reg + 1;
end
endmodule

4. Always- Defines a procedural block that executes continuously.


Example-module AlwaysExample;

8
// Declare a 4-bit input bus
reg [3:0] input_bus;

// Declare a clock signal


reg clk;

// Declare a 4-bit output bus


reg [3:0] output_bus;

// Always block triggered by positive edge of the clock


always @(posedge clk) begin
// Sequential logic: Increment the output_bus on each clock edge
output_bus <= input_bus + 1;
end

endmodule

5. If-else- Conditional statement for making decisions.


Example-module IfElseExample;

// Declare a 4-bit input bus


reg [3:0] input_bus;

// Declare a 4-bit output bus


reg [3:0] output_bus;

// Always block triggered by positive edge of the clock


always @(posedge clk) begin
// Example: Check if the input is greater than 8
if (input_bus > 8) begin
// If true, set the output to the input minus 1
output_bus <= input_bus - 1;
end else begin
// If false, set the output to the input plus 1
output_bus <= input_bus + 1;
end
end
endmodule

9
SOME ADVANCED VERILOG CONCEPTS

There are mainly three concepts-

1. PARAMETERIZATION

2. HIERARCHICAL DESIGN

3. TIMING AND SYNCHRONIZATION

Explaining them-

● Parameterization- Engineers often use parameterized modules to


create flexible and scalable designs. This allows them to instantiate
modules with varying sizes and configurations, enhancing reusability.

● Hierarchical design- The concept of hierarchy is crucial in managing


the complexity of digital designs. Engineers organize their code in a
hierarchical manner, breaking down a large system into smaller, more
manageable modules. This promotes clarity, maintainability, and team
collaboration.

● Timing and synchronization- Engineers employ methodologies


such as dual-clock FIFOs, synchronizers, and metastability reduction
circuits to manage data transfers between different clock domains.
This ensures that data is properly synchronized and avoids issues
related to clock domain crossing.

10
HALF ADDER USING VERILOG HDL

=(A^B)

=(A.B)

11
Circuit Diagram for HalfAdder

Simulation of Half Adder

Let's break down the simulation diagram for a half


adder:

1.Input Signals (r_BIT1 and r_BIT2):

These are your input bits representing the binary


numbers to be added.
Input Signals

12
In the diagram, you can see that r_BIT1 and r_BIT2
change their values at different time points. Each
transition in the input signals may trigger a change in
the output signals.

2.Output Signals (w_sum and w_carry):

w_sum represents the sum of r_BIT1 and r_BIT2.


w_carry represents the carry-out from the addition.
Output Signals

In this part of the diagram, you can observe the


changes in w_sum and w_carry based on the inputs.
The transitions in w_sum occur due to the XOR
operation, and the transitions in w_carry are due to the
AND operation.

3.Time Axis:

The horizontal axis represents time. Each vertical line or


tick on the axis corresponds to a specific time unit.
Time progresses from left to right.
Time Axis

In the diagram, you can see how the input and output
signals change at different time points. The simulation

13
captures the dynamic behavior of the half adder as it
processes input bits and produces corresponding sum
and carry-out bits.

By examining the simulation diagram, you can


understand how the half adder responds to different
input combinations and observe the resulting changes
in the output signals over time.

14

You might also like