Showing posts with label Verilog. Show all posts
Showing posts with label Verilog. Show all posts

Friday, 9 January 2015

Design a Ripple Carry Adder using Full adders


An adder is a digital circuit that performs addition of numbers. These adders are not only used in Arithmetic and logic unit but also in various components of the computers. 

It is possible to create a logical circuit using multiple full adders to add N-bit numbers. Each full adder inputs a Cin, which is the Cout of the previous adder. This kind of adder is called a ripple-carry adder, since each carry bit "ripples" to the next full adder





Ripple carry adder verilog code:

module ripplecarryadder (a,b,cin,sum,cout);
input [3:0]a;
input [3:0]b;
input cin;
output [3:0]sum;
output  cout;
wire c1,c2,c3;
fulladder fa1(.a(a[0]),.b(b[0]),.c(cin),.sum(sum[0]),.carry(c1));
fulladder fa2(.a(a[1]),.b(b[1]),.c(c1),.sum(sum[1]),.carry(c2));
fulladder fa3(.a(a[2]),.b(b[2]),.c(c2),.sum(sum[2]),.carry(c3));
fulladder fa4(.a(a[3]),.b(b[3]),.c(c3),.sum(sum[3]),.carry(cout));

endmodule

Sunday, 28 December 2014

Swap / Buffer Circuit

Swap / Buffer circuit can be implemented by using a simple 2X1 Multiplexer.




Swap/Buffer circuit Verilog Code

module swap_buffer(a,b,s,out1,out2);
input a,b,s;
output out1,out2;
mux2x1 m1(.in1(a),.in2(b),.sel(s),.y(out1));
mux2x1 m2(.in1(b),.in2(a),.sel(s),.y(out2));
endmodule





Wednesday, 24 December 2014

Full adder design using Half adder in Verilog









Half adder Verilog code


module halfadder(sum,carry,a,b);
input a,b;
output sum,carry;

xor(sum,a,b);
and(carry,a,b);

endmodule


Full adder using Half adder verilog code

module fulladder(a,b,c,sum,carry);
input a,b,c;
output wire sum, carry;

wire w1,w2,w3;

halfadder h1(.sum(w1),.carry(w2),.a(a),.b(b));
halfadder h2(.sum(sum),.carry(w3),.a(w1),.b(c));

assign carry = w2 | w3;

endmodule

Sunday, 7 December 2014

Dataflow modelling in Verilog HDL




A Combinational logic can be modelled using continuous assignment statements.
In complex designs, the number of gates is very large. Currently, automated tools are used to create a gate-level circuit from a Dataflow design description. This process is called Logic Synthesis.

Syntax:
assign [drive_strength] list_of_assignments;

  • The continuous assignment creates a continuous relationship between a RHS expression and a LHS net. 
  • Continuous assignments can be used instead of primitives. 
  • Continuous assignments cannot contain timing controls. 
  • You can make an explicit or implicit continuous assignment.

Before getting into the actual dataflow assignments we need to know some of the rules while using this kind of modelling style:

  1. The left hand side of an assignment must always be a scalar or vector net. 
  2. It cannot be a scalar or vector register.
  3. Continuous assignments are always active.
  4. The assignment expression is evaluated as soon as one of the right-hand-side operands changes and the value is assigned to the left-hand-side net.
  5. The operands on the right-hand side can be registers or nets.


Different Types of Operators
Type of Operators                                              Symbols

Concatenate & Replicate                                      { }   {{ }}
Unary                                                                     !      ~     &     ^     ^~     |
Arithmetic                                                              *     /      %    +     -
Logical shift                                                           <<   >>
Relational                                                              <     <=    >    >=
Equality                                                                  ==   !=   ===  !==
Binary bit-wise                                                      &      ^      ^~     |
Binary logical                                                        &&    ||
Conditional                                                            ? :

Here are some of examples of continuous assignments

wire in_ = ~in; // implicit assignment
wire one = 1'b1; // constant assignment
tri AND = a&b, OR = a|b; // two assignments
assign ab = a & b; // explicit assignment
assign {COUT, SUM} = A + B + CIN ; // assignment to a concatenation
assign o2[7:4] = in[3:0], o2[3:0] = in[7:4]; // part-select



in-depth discussion of each operator will be discussed in the next post











Friday, 5 December 2014

Switch level modelling in verilog

It is also called as the lowest level of abstraction.

The important thing that has to be noted while writing a verilog code in Switch level are the Switch level primitives, which are as follows:

  
                        
                                                                 




       
 Cmos                           nmos                             pmos

Next thing that has to be learned is instantiation of these primitives...

nmos (drain, source, gate);
pmos (drain, source, gate);
cmos  (drain, source, ngate, pgate);


now let us write a Switch level verilog code for a NAND gate.



module nand2_1d (a, b, y); 
input a;
input b;
output y;
supply0 gnd;
supply1 vdd;
wire in1;
      pmos  g1 ( y, vdd, a );
      pmos  g2 ( y, vdd, b );
      nmos  g3 ( y, in1, a );
      nmos  g4 ( in1, gnd, b);
endmodule


Monday, 1 December 2014

Introduction to Verilog HDL

Verilog is a Hardware Description Language; a textual format for describing electronic circuits and systems. Applied to electronic design, Verilog is intended to be used for verification through simulation, for timing analysis, for test analysis (testability analysis and fault grading) and for logic synthesis.

The Verilog HDL is an IEEE standard - number 1364. The first version of the IEEE standard for Verilog was published in 1995. A revised version was published in 2001; this is the version used by most Verilog users. The IEEE Verilog standard document is known as the Language Reference Manual, or LRM. This is the complete authoritative definition of the Verilog HDL.

A further revision of the Verilog standard was published in 2005, though it has little extra compared to the 2001 standard. SystemVerilog is a huge set of extensions to Verilog, and was first published as an IEEE standard in 2005. See the appropriate Knowhow section for more details about SystemVerilog.

IEEE Std 1364 also defines the Programming Language Interface, or PLI. This is a collection of software routines which permit a bidirectional interface between Verilog and other languages (usually C).

Note that VHDL is not an abbreviation for Verilog HDL - Verilog and VHDL are two different HDLs. They have more similarities than differences, however.




Features of Verilog HDL
  • Ability to mix different levels of abstract freely.
  • One language for all aspects of design, testing, and verification.
  • Verilog has been developed for describing digital circuits and systems.
  • Verilog treats a system as black box with an interface.
  • The specifications of a system are referred to as Verilog modules.

Levels of Abstraction

1. Behavioral or Algorithmic level
  • This is the highest level of abstraction provided by Verilog HDL.
  • A module can be implemented in terms of the desired design algorithm without concern for the hardware implementation details.
  • Designing at this level is very similar to C programming.

2. Dataflow level
  • At this level, the module is designed by specifying the data flow.
  • The designer is aware of how data flows between hardware registers and how the data is processed in the design.

3. Gate level
  • The module is implemented in terms of logic gates and interconnections between the gates.
  • Design at this level is similar to describing a design in terms of a gate-level logic diagram.

4. Switch level
  • This is the lowest level of abstraction provided by Verilog.
  • A module can be implemented in terms of switches, storage nodes, and the interconnections between them.
  • Design at this level requires knowledge of switch-level implementation details. 

What is HDL?

HDL stands for Hardware Description Language. It is a Language that is used to describe the components in designing Hardware. HDL is a programming language that can describe the functionality and timing behavior of the hardware.


So the question.... Why use an HDL?

  1. It is becoming very difficult to design directly on hardware.
  2. It is easier and cheaper to different design options.
  3. Reduce time and cost.

What the Properties of HDL that makes it stand alone?

1. Concurrency
          In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. The same thing lies with the hardware design of any electronic chip. When we power on the components in the chip have to be activated at a same time. Whereas if we try to design the circuit using a simple C program each line in it will be executed one after another which is sequential line execution which useless in hardware designs.

2. Sequentiality
         Sequentiality is an important property in the hardware design because the chip is made up of numerous modules which have different operation capabilities and these modules operations might be dependent upon various output of primary modules in the design which means there is some dependency on the previous outputs which is nothing but a sequential operation. hence HDL also consists of this kind of property.

3. Timing Analysis
           Static timing analysis (STA) is a method of computing the expected timing of a digital circuit without requiring simulation.

4. Waveform Generation
         HDL also has  the important characteristic of generating the waveform during the simulation process in designing phase.

5. Netlist Generation
          Nets in VLSI are basically the components that are present in the design. HDL generates the list of components that are present in the logic circuit.

There are two types of HDL....
  • VHDL ( Very High Speed Integrated Circuit Hardware Description Language)
  • Verilog HDL

Both has its own way to design the hardware…Verilog is somewhat easy compared to VHDL but for verification you need to learn a language called System VerilogVHDL will not allow any silly mistakes whereas Verilog allows and may cause serious mistakes unknowingly. VHDL is so strict like a military conversation…where as Verilog is like a casual talk VHDL is English like one and Verilog looks like C. Requirement or your client interest decides which one to take In a single phrase..Both HDL are Equal ways to reach a destination.

Sunday, 30 November 2014

3-BIT Array Multiplier

A Multiplier is a electronic circuit used in computers for multiplication of two numbers.

let us see how multiplication actually works.

Write the multiplication down and you'll know what to do. For example A1A2A3*B1B2B3

            A1   A2   A3
         x  B1   B2   B3
-------------------------
          B3A1 B3A2 B3A3
+    B2A1 B2A2 B2A3
B1A1 B1A2 B1A3
---------------------------------
as we can see in the above example that we are performing logical AND operation and addition of the partial products..... for which in digital electronics we have adder circuits such as Half adder and Full adder.

Verilog Code for the 3-Bit Multiplier is as follow:

module halfadder(sum,carry,a,b);
input a,b;
output sum,carry;
xor(sum,a,b);
and(carry,a,b);
endmodule

module multiply3bits(product,a,b);
input [2:0]a, b;
output [5:0] product;
wire s1,c1,s2,c2,s3,c3;
assign product[0]= (a[0] & b[0]);
halfadder ha1 (s1,c1,(a[1] & b[0]),(a[0] & b[1]));
fulladder fa1 ((a[2] & b[0]),(a[1] & b[1]),c1,s2,c2);
halfadder ha2 (s3,c3,(a[2] & b[1]),c2);
assign product[1]=s1;
halfadder ha3 (s4,c4,s2,(a[0] & b[2]));
fulladder fa2 (s3,(a[1] & b[2]),c4,s5,c5);

halfadder ha4 (s6,c6,c5,(a[2] & b[2]));
assign product[2]=s4;
assign product[3]=s5;
assign product[4]=s6;
assign product[5]=c4;
endmodule

CMOS Inverter using Verilog Switch level modelling


Truth Table:
 a
F
 0
1
 1
0

module cmos_inv(f,a);
//declaring the input and output variables
input a;                //'a' is the input and 'f' is the output
output f;
//syntax for declaring the power supply and ground
supply1 vdd;
supply0 gnd;
//instantiating pmos and nmos transistors (drain,source,gate)
pmos p1(f,vdd,a);
nmos n1(f,gnd,a);

endmodule