Professional Documents
Culture Documents
Experiment 07
SAURABH KUMAR
190102065
Objective 1
Design a half adder in verilog and simulate the same in VIVADO using
testbench(simulation source).
Half Adder:
A Half adder adds two inputs bits, to give one Sum and one Carry output bit. Half
adders have the following truth table and logic circuit.
Circuit:
Verilog design code:
module half_adder(
Data_in_A,
Data_in_B,
Data_out_Sum,
Data_out_Carry
);
//Implement the Sum and Carry equations using Verilog Bit operators.
assign Data_out_Sum = Data_in_A ^ Data_in_B; //XOR operation
assign Data_out_Carry = Data_in_A & Data_in_B; //AND operation
endmodule
Testbench:
`timescale 1ns / 1ps
module tb_half_adder();
reg Data_in_A,Data_in_B;
wire Data_out_Sum,Data_out_Carry;
half_adder dut(Data_in_A,Data_in_B,Data_out_Sum,Data_out_Carry);
initial begin
Data_in_A = 0;
Data_in_B = 0;
#100 Data_in_A = 1;
Data_in_B = 0;
#100 Data_in_A = 0;
Data_in_B = 1;
#100 Data_in_A = 1;
Data_in_B = 1;
end
endmodule
Behaviour simulation output waveform:
Synthesis:
Synthesis report:
Timing report:
Power report:
Implementation:
Implementation report:
Timing report:
Power report:
Full Adder:
Full adder is a basic combinational circuit which is extensively used in many designs.
They are the basic building blocks for all kinds of adders. A full adder adds three
input bits, to give out, two output bits - Sum and Carry. They have the following truth
table:
Circuit:
half_adder.v
//Implement the Sum and Carry equations using Verilog Bit operators.
assign Data_out_Sum = Data_in_A ^ Data_in_B; //XOR operation
assign Data_out_Carry = Data_in_A & Data_in_B; //AND operation
endmodule
full_adder.v
//sum output from 2nd half adder is connected to full adder output
assign Data_out_Sum = ha2_sum;
//The carry's from both the half adders are OR'ed to get the final
//carry.
assign Data_out_Carry = ha1_carry | ha2_carry;
endmodule
Testbench:
tb_full_adder.v
`timescale 1ns/1ps
module tb_fullAdd;
// Inputs
reg Data_in_A;
reg Data_in_B;
reg Data_in_C;
// Outputs
wire Data_out_Sum;
wire Data_out_Carry;
initial begin
//Apply inputs. 8 combinations of inputs are possible.
//They are given below.
Data_in_A = 0; Data_in_B = 0; Data_in_C = 0; #100;
Data_in_A = 0; Data_in_B = 0; Data_in_C = 1; #100;
Data_in_A = 0; Data_in_B = 1; Data_in_C = 0; #100;
Data_in_A = 0; Data_in_B = 1; Data_in_C = 1; #100;
Data_in_A = 1; Data_in_B = 0; Data_in_C = 0; #100;
Data_in_A = 1; Data_in_B = 0; Data_in_C = 1; #100;
Data_in_A = 1; Data_in_B = 1; Data_in_C = 0; #100;
Data_in_A = 1; Data_in_B = 1; Data_in_C = 1; #100;
end
endmodule
Synthesis:
Synthesis report:
Timing report:
Power report:
Implementation report:
Timing report:
Power report:
Post implementation functional simulation waveform:
Objective 3
Design a 4-bit adder with the help of full adder designed in objective 2 in verilog and
simulate the same in VIVADO using testbench(simulation source).
half_adder.v
//Implement the Sum and Carry equations using Verilog Bit operators.
assign Data_out_Sum = Data_in_A ^ Data_in_B; //XOR operation
assign Data_out_Carry = Data_in_A & Data_in_B; //AND operation
endmodule
FullAdder.v
//sum output from 2nd half adder is connected to full adder output
assign Data_out_Sum = ha2_sum;
//The carry's from both the half adders are OR'ed to get the final
//carry.
assign Data_out_Carry = ha1_carry | ha2_carry;
endmodule
4BitAdder.v
`timescale 1ns/1ps
module full_adder_4b(a,b,cin,sum,cout);
input [3:0] a,b;
input cin;
output [3:0] sum;
output cout;
endmodule
Testbench:
tb_FourBitAdder.v
module TestModule;
// Inputs
reg [3:0] a;
reg [3:0] b;
reg cin;
// Outputs
wire [3:0] sum;
wire cout;
initial begin
// Initialize Inputs
a = 0;
b = 0;
cin = 0;
// Wait 100 ns for global reset to finish
#100;
a = 2;
b = 3;
cin = 1;
a = 3;
b = 5;
cin = 0;
a = 4;
b = 5;
cin = 1;
a = 5;
b = 7;
cin = 0;
a = 12;
b = 3;
cin = 1;
a = 14;
b = 3;
cin = 0;
a = 14;
b = 14;
cin = 1;
#100;
end
endmodule
Behaviour simulation output waveform:
Synthesis:
Synthesis report:
Timing report:
Power report:
Implmentation:
Implementation report:
Timing report:
Power report:
End of report