Experiment 10 - Half-Adder Using Verilog Devices and Digital IC
Experiment 10 - Half-Adder Using Verilog Devices and Digital IC
10.1 Objective
To design and implement a Half Adder using different modeling techniques in Verilog: Data
Flow, Structural, and Behavioral modeling, and to verify the functionality of the Half Adder
using a test bench.
10.3 Theory
Verilog HDL (Hardware Description Language) is one of the primary languages used
for digital design and verification. Developed in the mid-1980s by Gateway Design
Automation, Verilog has become a standard for electronic design automation (EDA). It was
later standardized as IEEE 1364 and has evolved to include features that make it suitable for
system-level design and verification. Verilog enables designers to describe a digital system at
various levels of abstraction and versatile modelling styles, making it easier to design, test, and
debug. Its event-driven simulation capabilities, modular design support, and rich syntax make
it an essential language for modern digital system development.
Modeling Styles in Verilog
Each model serves a different purpose and provides a unique abstraction level, offering various
methods to describe the functionality and structure of digital circuits.
Dataflow modeling in Verilog emphasizes the flow of data through the system. It is used
to describe the logic by specifying how data moves from inputs to outputs using continuous
assignments. It focuses on the relationship between inputs and outputs without explicitly
detailing the hardware structure. This model is particularly useful for describing combinational
logic. In dataflow modeling, the key construct is the `assign` statement, which allows the
designer to express the logic in terms of Boolean equations. These equations represent the
relationships between inputs and outputs, making it easier to translate mathematical
expressions directly into Verilog code.
Example
This example shows a simple AND gate, where the output `Y` is the logical AND of
inputs `A` and `B`. The ‘module’ command tells the compiler that we are creating something
which has some inputs and outputs. ‘and_gate_d’ is the identifier. The `assign` statement
continuously evaluates the expression and updates the output whenever any input changes.
‘endmodule’ terminates the module.
Dataflow modeling is efficient for simple combinational circuits but becomes complex
for larger designs with intricate timing and control requirements.
ii.) Structural modeling
Example
In this example ‘and’ is the operation performed on A, B, to get output Y. Verilog has
this functionality to describe the circuit at the gate level.
Structural modeling provides a clear view of the circuit's physical composition but can
be tedious for large designs due to the extensive detail required.
Behavioral modeling describes the functionality of the system in terms of algorithms and
high-level constructs, abstracting away the physical implementation details. This style uses
constructs like ‘always’ blocks, ‘if-else’ statements, and ‘case’ statements to describe the
functionality. Behavioral modeling abstracts the hardware to a greater extent and focuses on
the functionality rather than the physical connections or data flow. It uses procedural statements
within `always` blocks to define the behavior over time, making it suitable for both
combinational and sequential logic.
Behavioral modeling is the most abstract form of modeling and allows designers to focus
on the desired functionality without worrying about the hardware specifics. This model is often
used in the initial stages of design for simulation and verification purposes.
Example
In this example, level of abstraction is behavioral level, hence use ‘reg’ datatype in the
output ports. The reg data object holds its value from one procedural assignment statement to
the next. if (A == 1'b1 & B == 1'b1) states that if both A and B are 1, then Y has to be 1, else
0.
Behavioral modeling provides high-level abstraction and simplicity but might not offer
insights into the actual hardware structure, which can be critical for detailed hardware design
and optimization.
Importance of Testbenches
In Verilog, testbenches are essential for verifying the correctness of the design. A
testbench is a piece of code written to apply stimuli (input signals) to the design under test
(DUT) and observe the outputs to check if they match the expected results. Testbenches help
identify and fix errors early in the design process. They are not synthesized into hardware but
are used in simulations to validate the design.
A Half Adder is a combinational circuit that performs the addition of two binary digits.
It has two inputs and two outputs. The inputs are the two binary digits to be added, and the
outputs are the Sum and the Carry.
Input Output
A B Sum Carry
0 0 0 0
0 1 1 0
Sum = 𝐴̅𝐵 + 𝐴𝐵̅ Carry = 𝐴𝐵
1 0 1 0
= 𝐴⨁𝐵
1 1 0 1 Fig 10.2 Boolean Expression of Half Adder
10.4 Procedure for Verilog Simulation of Digital Circuits using Xilinx 7.1e ISE
• Click Next.
• Simulator: ModelSim
• Click Next.
• Define the module’s inputs and outputs (you can also edit this later).
• In the left pane, under the Process for Source, expand the Synthesize-XST menu by
clicking the "+" icon.
• Click Launch ModelSim Simulator (integrated with ISE) to start the simulation
process.
• Choose Force from the context menu and assign values (1 or 0).
• Observe the waveform window to see how inputs affect the outputs.
10.4.1 Steps to Create and Simulate a Test Bench in Xilinx 7.1e ISE
• In the Project Navigator, right-click on choose the Verilog module you want to create
a test bench for from the list of existing modules and select New Source.
• Choose Verilog Test Fixture, enter a name for your test bench module and click Next.
• Write the stimulus to drive the inputs and monitor the outputs.
module halfadder_tb;
reg A, B;
wire Sum, Carry;
halfadder_s uut (.Sum(Sum), .Carry(Carry), .A(A), .B(B)); // Instantiate the Unit
Under Test (UUT)
initial
begin
#000 A=0; B=0;
#100 A=0; B=1;
#100 A=1; B=0;
#100 A=1; B=1;
end
endmodule
The Half Adder was successfully designed and implemented using Data Flow,
Structural, and Behavioral modeling techniques in Verilog, with functionality verified through
a test bench.
Prelab Questions
1. List the various types of EDA tools currently utilized in the VLSI design industry.
2. Why has Verilog HDL emerged as a prominent Hardware Description Language in digital
circuit design?
3. What is the importance of simulating a Verilog design before implementing it on hardware?
4. What are the primary components of a half adder circuit, and what is the function of each
component?
5. How does a half-adder differ from a full-adder?
6. Where are half-adders typically used in digital circuits?