FPGA LAB (Testbench to Verify the Functionality of a Design (Full Adder))
FPGA LAB (Testbench to Verify the Functionality of a Design (Full Adder))
SECTION : B
Marks Obtain
Group Member 1 Group Member 2
NAME MAHNOOR
REGISTRATION NUMBER 220701002
LAB REPORT 2
PERFORMANCE
TOTAL MARKS
DATE OF SUBMISSION:
________________________________________________________________________
Experiment # 03 Page 1 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Objectives:
Testbench
A testbench is a simulation environment used in digital design to verify and validate the
functionality of a hardware description language (HDL) design, such as Verilog or
VHDL, before it is implemented on hardware. It serves as a virtual environment where
the behavior of the designed circuit can be tested under various conditions and scenarios.
The testbench generates input signals or stimuli to apply to the design under test (DUT).
These stimuli simulate different scenarios and test cases to ensure the DUT behaves as
expected. The testbench controls the simulation process, specifying when to start and
stop the simulation, as well as managing the timing and sequence of events. The actual
hardware design (DUT) is instantiated within the testbench. The testbench provides the
necessary inputs to the DUT and monitors its outputs. This involves comparing
simulated output waveforms with the expected behavior. This help identify and analyze
issues within the design. estbenches allow designers to identify and fix issues in the
design before it is implemented in hardware, reducing the risk of errors in the final
product.
Introduction
Full Adder is the adder that adds three inputs and produces two outputs. The first two
inputs are A and B and the third input is an input carry as C-IN. The output carry is
designated as C-OUT and the normal output is designated as S which is SUM. The C-
OUT is also known as the majority 1’s detector, whose output goes high when more than
one input is high. A full adder logic is designed in such a manner that can take eight
inputs together to create a byte-wide adder and cascade the carry bit from one adder to
another. we use a full adder because when a carry-in bit is available, another 1-bit adder
________________________________________________________________________
Experiment # 03 Page 2 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
must be used since a 1-bit half-adder does not take a carry-in bit. A 1-bit full adder adds
three operands and generates 2-bit results.
Algorithm 1:
This Verilog full adder module performs the binary addition of three input bits (A, B,
and CARRY_IN) and produces a SUM and a CARRY_OUT. The SUM is computed
using two XOR operations: SUM = (A ^ B) ^ CARRY_IN, which ensures correct
bitwise addition. The CARRY_OUT is determined using the formula (A & B) | (B &
CARRY_IN) | (A & CARRY_IN), which correctly accounts for all cases where a carry
is generated—when at least two of the three input bits are 1. The module is purely
combinational, using continuous assignments (assign) to perform logic operations
without requiring clock signals. The timescale 10ns / 100ps directive specifies the
simulation time unit and precision for accurate timing analysis.
________________________________________________________________________
Experiment # 03 Page 3 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
________________________________________________________________________
Experiment # 03 Page 4 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
________________________________________________________________________
Experiment # 03 Page 5 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
module full_adder_tb;
________________________________________________________________________
Experiment # 03 Page 6 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
.CARRY_OUT(CARRY_OUT)
);
// Test procedure
initial begin
$display("A B CIN | SUM COUT");
$display("-----------------");
A = 0; B = 0; CARRY_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 0; B = 1; CARRY_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 0; B = 1; CARRY_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 1; B = 0; CARRY_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 1; B = 0; CARRY_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 1; B = 1; CARRY_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
A = 1; B = 1; CARRY_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, CARRY_IN, SUM, CARRY_OUT);
________________________________________________________________________
Experiment # 03 Page 7 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
2. Add or create simulation sources and then click on Next and then click on create
File.
3. Write the File Name (exact same name as in the test bech in Algorithm 2
(full_adder_tb)) and then click on ok and then click on Finish .
4. Click on ok
________________________________________________________________________
Experiment # 03 Page 8 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
5. Click on yes
7. Write the code of test bench as from Algorithm 2 and click on Save.
________________________________________________________________________
Experiment # 03 Page 9 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Result:
As here the A=0 B=0 CARRY_IN=0 so the sum=A+B+Cin , sum = 0+0+0 ,sum=0
Here the A= 1 B=0 CARRY_IN=0 ,sum= 1+0+0 ,Sum=1 ,CARRY_OUT=0 Verifying truth
table
Here the A= 1 B=1 CARRY_IN=0 ,sum= 1+1+0 ,Sum=0 ,CARRY_OUT=1 Verifying truth
table
________________________________________________________________________
Experiment # 03 Page 11 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Here the A= 1 B=1 CARRY_IN=1 ,sum= 1+1+1 ,Sum=1 ,CARRY_OUT=1 Verifying truth
table
Conclusion:
The full adder testbench verifies the circuit’s functionality by applying all possible input
combinations with timescale 10ns / 100ps, ensuring accurate timing. Inputs (A, B,
CARRY_IN) are defined as reg for controlled assignment, while outputs (SUM,
CARRY_OUT) are wire, driven by combinational logic. The adder follows the expected
equations: SUM = (A ⊕ B) ⊕ CARRY_IN and CARRY_OUT = (A & B) | (B &
CARRY_IN) | (A & CARRY_IN), confirming logical correctness. A #10 delay ensures
stable output before each test case is recorded. The $display command prints results for
direct truth table comparison, and $finish terminates execution. The timing diagram
confirms correct operation, verifying the full adder’s accuracy.
Task
Write the design code and test bench for full subtrator. discuss its time
diagrame in detail.
FULL SUBTRACTOR:
This is one kind of combinational logic circuit, used to perform the subtraction of two
binary digits like 0s and 1s. Subtraction of binary digits from 0 to 0 or 0 to 1 does not
alter the result, subtraction of 1 to 1 will result as 0 but the subtraction of 1 to 0 needs
borrow.
A full Subtractor is a digital circuit that performs the subtraction of three single-digit
binary numbers. This is a three-input and two-output digital circuit.
For three single-bit binary numbers A, B, and Bin, the full subtractor circuit generates
two single-bit binary outputs D (Difference), and B_out(Borrow Output).
________________________________________________________________________
Experiment # 03 Page 12 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
DIFFERENCE Calculation
________________________________________________________________________
Experiment # 03 Page 13 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
MODULE WINDOW:
TESTBENCH WINDOW:
________________________________________________________________________
Experiment # 03 Page 14 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
TIMING DIAGRAMS:
Analysis:
when A = 0, B = 0, and BORROW_IN = 0, no subtraction occurs since both A and B are
zero, and no borrow is present. As expected, the DIFFERENCE remains 0, and
BORROW_OUT is also 0, confirming that the circuit correctly handles this trivial case.
Analysis:
For A = 0, B = 0, and BORROW_IN = 1, the result is DIFFERENCE = 1 with
BORROW_OUT = 1, confirming correct borrow handling as verified by the timing
________________________________________________________________________
Experiment # 03 Page 15 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
diagram.
Analysis:
For A = 0, B = 1, and BORROW_IN = 0, the result is DIFFERENCE = 1 with
BORROW_OUT = 1. When BORROW_IN = 1, the result becomes DIFFERENCE = 0
with BORROW_OUT = 1, confirming the truth
table.
Analysis:
The timing diagram confirms this behavior by displaying DIFFERENCE = 0 and
BORROW_OUT = 1, which matches the truth table perfectly. This validates that the
circuit correctly processes this input case, handling borrow propagation as expected.
Analysis:
For A = 1, B = 0, and BORROW_IN = 0, the result is DIFFERENCE = 1 with no
borrow. When BORROW_IN = 1, the result becomes DIFFERENCE = 0 with
BORROW_OUT = 0, confirming correct borrow handling..
Analysis:
For A = 1, B = 0, and BORROW_IN = 1, the operation 1 - 0 - 1 results in 0. No borrow
is needed as A already accommodates the subtraction. The expected output,
DIFFERENCE = 0 and BORROW_OUT = 0, confirms correct circuit
________________________________________________________________________
Experiment # 03 Page 16 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
operation.
Analysis:
For A = 1, B = 1, and BORROW_IN = 0, the operation 1 - 1 - 0 results in 0. No borrow
is needed as A and B are equal. The expected output, DIFFERENCE = 0 and
BORROW_OUT = 0, confirms correct circuit
behavior.
Analysis:
For A = 1, B = 1, and BORROW_IN = 1, the operation 1 - 1 - 1 results in 1 with a
BORROW_OUT of 1. The circuit correctly handles borrowing, confirming its expected
functionality.
DISCUSSION:
The full subtractor testbench verifies the circuit’s correctness by applying all possible
input combinations under the timescale 10ns / 100ps, ensuring precise timing. Inputs (A,
B, BORROW_IN) are defined as reg for controlled assignment, while outputs
(DIFFERENCE, BORROW_OUT) are wire, driven by combinational logic. The
subtractor follows the expected equations: DIFFERENCE = (A ⊕ B) ⊕ BORROW_IN
and BORROW_OUT = (~A & B) | ((~A | B) & BORROW_IN), confirming logical
accuracy. A #10 delay ensures stable output before recording each test case. The $display
command prints results for direct comparison with the truth table, and $finish terminates
execution. The timing diagram confirms correct operation, verifying the full subtractor’s
functionality.
Conclusion:
________________________________________________________________________
Experiment # 03 Page 17 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
________________________________________________________________________
Experiment # 03 Page 18 of 18
FPGA BASED EMBEDDED SYSTEM DESIGN