Friday, 15 November 2013

VERILOG CODE FOR HALF ADDER WITH TEST BENCH


  • VERILOG CODE FOR HALF ADDER WITH TEST BENCH, TECHNOLOGY SCHEMATIC
Half Adder is a combinational circuit which are used to add any 2 binary numbers and generate two results.
  1. SUM
  2. CARRY
SUM is generated by XOR operation of two input Signals, whereas CARRY is generated by AND operation between two input Signals.

Half Adder is basic building block for other high level ADDERS which are more faster, complex in nature.

The circuit diagram for implementation of Half Adder using Logic Gates is shown below:


  • VERILOG CODE FOR HALF ADDER

module ha(a, b, sum, carry);
// save file with ha.v extension 


input a;
input b;
output sum;
output carry;

assign carry=a&b;                           
assign sum=a^b;                             

endmodule

  • VERILOG TESTBENCH FOR HALF ADDER

module halfaddert_b;
// save file with  halfaddert_b.v extension

reg a,b;
wire sum,carry;
ha m1 (a,b,sum,carry);

initial begin
$monitor ($time, ,"a=%b,b=%b,sum=%b,carry=%b",a,b,sum,carry);

a = 0; b = 0;

#10 b = 1;
#10 a = 1;
#10 b = 0;

end
endmodule

  • SIMULATION OF HALF ADDER (VERILOG APPROACH)
After compiling both codes, the simulation results can be viewed as under, 

The truth table inset within the simulation results would be helpful for  understanding picture more clearly.





  • SYNTHESIS OF HALF ADDER (VERILOG APPROACH)
After simulation, next step would be generation of synthesis logic schematic and technology schematic.

The working of  Half Adder can be decided by Technology schematic (LUT - Look Up Table)

The Snap-Shots of Technology Schematic and 2 LUTs for Half Adder (Verilog Approach) is shown below 









Note: Look-up tables (LUTs) are used to implement function generators in CLBs.

 An n-bit LUT can encode any n-input Boolean function by modeling such functions as truth tables. This is an efficient way of encoding Boolean logic functions, and LUTs with 4-6 bits of input are in fact the key component of modern field-programmable gate arrays (FPGAs).




















No comments: