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

Friday, 12 December 2014

Behavioural modelling in Verilog HDL

Behavioural modelling is the highest level of abstraction in the Verilog HDL. Hardware description using behaviour modelling style requires the knowledge of working of that particular device. This modelling looks like a C programming language. In behavioural modelling we are introduced to a new concept called as Procedural block.

Basically Procedural blocks are of two types.  1. Initial block 2. Always block
Initial block and Always block both starts when simulation starts in arbitrary order. The main difference is that initial block executes and stops where as always block is a continuous loop.

Let us see the syntax how it looks like
Initial                                                     always
Begin                                                     Begin
----                                                         -------
----                                                         -------
End                                                        end

Initial block cannot be synthesized where as always blocks can be synthesized hence they are used in main code while initial blocks are used only in testbenches. Inside these blocks there are assignment statements called as Procedural assignments.

There are two types of procedural assignments: Blocking and Non-Blocking assignments.

Blocking assignments: A blocking assignment statements are executed in the order they are specified in a sequential block. The execution of next statement begin only after the completion of the present blocking assignments. A blocking assignment will not block the execution of the next statement in a parallel block. The blocking assignments are made using the operator =.

Let us see this with the help of an example:

initial
begin
    a = 1;
    b = #5 2;
    c = #2 3;
end

In the above example, a  is assigned value 1 at time 0, and b is assigned value 2 at time 5, and c is assigned value 3 at time 7.

Non-blocking assignments: The nonblocking assignment allows assignment scheduling without blocking the procedural flow. The nonblocking assignment statement can be used whenever several variable assignments within the same time step can be made without regard to order or dependence upon each other. Non-blocking assignments are made using the operator <=.
Note: <= is same for less than or equal to operator, so whenever it appears in a expression it is considered to be comparison operator and not as non-blocking assignment.

initial
begin
    a <= 1;
    b <= #5 2;
    c <= #2 3;
end

In the above example, a is assigned value 1 at time 0, and b is assigned value 2 at time 5, and c is assigned value 3 at time 2 (because all the statements execution starts at time 0, as they are non-blocking assignments.

Next type of statements are called as Conditional statements

Conditional statements execute only on a condition.
Types of conditional statements:

1. if and if-else statements
2. case statement

Syntax for if statement

if ( expression )
 statement;
else
 statement;

Example
always @ (a)
begin
if (a==1)
    x = a ;
end

In the above example if a value is equal to 1 then the value of x is updated to the value a i.e. equal to 1.

Case statement syntax

Syntax:  
case ( expression )
case_item ...
endcase

Example
always @ (a,b,c,d,sel)
begin
  case (sel)
3:            y = d;
2:            y = c;
1:             y = b;
  default:  y = a;
  endcase
end


This above example gives the 4x1 multiplexer

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

What is Binary?


Binary describes a numbering scheme in which there are only two possible values for each digit: 0 and 1. The term also refers to any digital encoding/decoding system in which there are exactly two possible states. In digital data memory, storage, processing, and communications, the 0 and 1 value are sometimes called "low" and "high," respectively.
http://favorpcrepair.yolasite.com/resources/binary-code-1024x768.jpg?timestamp=1345296032165
Discrete elements of information are represented in a digital system by physical quantities called signals. Electrical signals such as voltages and currents are the most common. Electronic devices called Transistors predominate in the circuitry that implements these signals. The signals in most present‐day electronic digital systems use just two discrete values and are therefore said to be binary. A binary digit, called a bit, has two values: 0 and 1. Discrete elements of information are represented with groups of bits called binary codes. For example, the decimal digits 0 through 9 are represented in a digital system with a code of four bits (e.g., the number 7 is represented by 0111).


Since binary is a base-2 system, each digit represents an increasing power of 2, with the rightmost digit representing 20, the next representing 21, then 22, and so on. To determine the decimal representation of a binary number simply take the sum of the products of the binary digits and the powers of 2 which they represent. For example, the binary number 100101 is converted to decimal form as follows:
1001012 = [ ( 1 ) × 25 ] + [ ( 0 ) × 24 ] + [ ( 0 ) × 23 ] + [ ( 1 ) × 22 ] + [ ( 0 ) × 21 ] + [ ( 1 ) × 20 ]
1001012 = [ 1 × 32 ] + [ 0 × 16 ] + [ 0 × 8 ] + [ 1 × 4 ] + [ 0 × 2 ] + [ 1 × 1 ]
1001012 = 3710

Octal number


The conversion from binary to octal is easily accomplished by partitioning the binary number into groups of three digits each, starting from the binary point and proceeding to the left and to the right.



Hexadecimal
Conversion from binary to hexadecimal is similar, except that the binary number is divided into groups of four digits:

Let us see the tabular column comparison to decimal number to its binary number, octal, hexadecimal.