VLSI Lab Manual
VLSI Lab Manual
VLSI Lab Manual
WEEK
PROGRAM CATEGORY TOPIC
NO
1.1 Design of Logic Gates using Data Flow Model
1.2 Design of Logic Gates using Behavioral Model
1.3 Design of Logic Gates using Structural Model
BASIC LOGIC GATES
1.4 Design of Logic Gates (3-input)using Behavioral
Model
1 1.5 Design of Logic Gates (3-input)using Data
Flow Model
2.1 Design of 2-to-4 Decoder with Behavioral
Model
2.2 Design of 2-to-4 Decoder with If Else
Statements
2.3 Design of 2-to-4 Decoder with Dataflow
Model
DECODER 2.4 Design of 3-to-8 Decoder with Structural
2
Model
2.5 Design of 3-to-8 Decoder with Behavioral
Model
3.1 Design of 8-to-3 Encoder Behavioral model
3.2 Design of 8-to-3 Encoder With Conditional
Statement
ENCODER 3.3 Design of 8-to-3 Encoder using Case statements
3.4 Design of 8-to-3 Encoder using With Parity Bit
Theory:
Digital systems are said to be constructed by using logic gates. These gates are the AND, OR, NOT,
NAND, NOR, EXOR and EXNOR gates. The basic operations are described below with the aid
of truth tables.
AND GATE:
The AND gate is an electronic circuit that gives a high output (1) only if all its inputs are high. A dot
(.) is used to show the AND operation i.e. A.B. Bear in mind that this dot is sometimes omitted i.e. AB
OR GATE:
The OR gate is an electronic circuit that gives a high output (1) if one or more of its inputs are high. A
plus (+) is used to show the OR operation.
NOT GATE:
The NOT gate is an electronic circuit that produces an inverted version of the input at its output. It is
also known as an inverter. If the input variable is A, the inverted output is known as NOT A. This is
also shown as A', or A with a bar over the top, as shown at the outputs. The diagrams below show two
ways that the NAND logic gate can be configured to produce a NOT gate. It can also be done using
NOR logic gates in the same way.
NAND GATE:
This is a NOT-AND gate which is equal to an AND gate followed by a NOT gate. The outputs of all
NAND gates are high if any of the inputs are low. The symbol is an AND gate with a small circle on
the output. The small circle represents inversion
NOR GATE:
This is a NOT-OR gate which is equal to an OR gate followed by a NOT gate. The outputs of all NOR
gates are low if any of the inputs are high.
The symbol is an OR gate with a small circle on the output. The small circle represents inversion.
EXOR GATE:
The 'Exclusive-OR' gate is a circuit which will give a high output if either, but not both, of its two
inputs are high. An encircled plus sign is used to show the EOR operation.
EXNOR GATE:
The 'Exclusive-NOR' gate circuit does the opposite to the EOR gate. It will give a low output ifeither,
but not both, of its two inputs are high. The symbol is an EXOR gate with a small circle on the output.
The small circle represents inversion.
The NAND and NOR gates are called universal functions since with either one the AND and OR
functions and NOT can be generated.
Note:
A function in sum of products form can be implemented using NAND gates by replacing all AND and
OR gates by NAND gates.
A neither function in product of sums form can be implemented using NOR gates by replacing all AND
and OR gates by NOR gates.
Procedural Steps:
The following procedure will guide you to develop a Xilinx ISE project.
8. Say Next for 3 times, then click on Finish. When you find new project result, project summary,
click finish.
9. Click Next to proceed to the Create New Source window in the New Project Wizard. Then
proceed to Section b.
c. Check Syntax:
1. In process window go to sources for window and select behavioral simulaation.
2. Select the desired parameters for simulating your design and click ok.
3. Assign all the signals to test bench wave form and save the file.
e. Simulation Process:
1. In source window from the dropdown menu select behavioral simulation to see the created
test bench file.
2. Select the test bench file from the source process window, click Xilinx ISE simulator. Now
double click simulate behavioral module.
Precautions
MLR Institute of Technology 10
Department Of ECE ECAD and VLSI Lab Manual
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Experiment No: 1
1.1 Logic Gates Data Flow Model
Aim: Write a verilog program to simulate and verify All Logic Gates using Data Flow Model.
Simulation Waveform:
Result: The verilog Program for all logic gates by using Xilinx 9.2i Software is Simulated and verified
successfully
Simulation Waveform:
Result: The verilog Program for all logic gates by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the Nand Gate using Structural Model
Simulation Waveform:
Result: The verilog Program for Nand logic gates by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify the Nor Gate using Structural Model
Program:
module nor1(c,a,b);
output c;
input a,b;
wire d;
or1 u1(d,a,b);
inv u2(c,d);
endmodule
module xor1(c,a,b);
output c;
input a,b;
wire d,e,f,g;
inv u1(d,a);
inv u2(e,b);
and1 u3(f,a,e);
and1 u4(g,b,d);
or1 u5(c,f,g);
endmodule
Simulation Waveform:
Result: The verilog Program for NOR logic gates by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify the XNOR Gate using Structural Model
Program:
module xnor_gate(X, A, B);
output X;
input A;
input B;
xnor(X, A, B);
endmodule
Simulation Waveform:
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
1. What are universal gates?
2. What are special purpose gates?
3. Design XOR gate using NAND gates?
4. How many NOR gates required to design NAND gate?
5. Which gates follows commutative and associative law
Result: The verilog Program for XOR logic gates by using Xilinx 9.2i Software is Simulated and
verified successfully
Experiment No: 2
2.1 Design of 2-to-4 Decoder using Behavioral Model
Aim: Write a verilog program to simulate and verify the 2 to 4 Decoder using Behavioral Model
Software:
Xilinx 9.2i.
Block Diagram:
Truth Table:
Theory:
Decoders :
A decoder is a combinational circuit that converts coded inputs to another coded outputs. The famous
examples of decoders are binary n-to-2n decoders and seven-segment decoders. A binary decoder has
n inputs and a maximum of 2n outputs. As we know, an n-bit binary number provides 2n minterms or
maxterms. This type of decoder produces one of the 2n minterms or maxterms at the outputs based on
the input combinations.
Lets take the 2-to-4 decoder as an example, the block diagram and the truth table of this decoder is
shown in Figure 2.1
MLR Institute of Technology 17
Department Of ECE ECAD and VLSI Lab Manual
From the truth table, you can observe the basic operation of n-to-2n decoders, there is only one active
output ( minterm ) for each input combination. The Boolean expression of the output signals are :
D0 = E x' y',
D1= E x' y,
D2 = E x y' and
D3= E x y
Now, the logic diagram for the 2-to-4 decoder can obtained as shown in Figure 2.2.
In the same way, we can obtained the logic diagram for any n-to-2n type decoder. The commercially
available decoders are normally built using NAND gates instead of using AND gates because they are
easy and less expensive to build. An example of a commercial n-to-2n line decoder is the 74139 chip.
This chip has two 2-to-4 decoders with active low enable for each , They constructed using the NAND
gates (see its pinout diagram and Function Table )
Program
module decoder_2x4(
input [1:0] a,
output reg [3:0] y);
always@(a)
case(a)
2'b00: y= 4'b0001;
2'b01: y= 4'b0010;
2'b10: y= 4'b0100;
2'b11: y= 4'b1000;
endcase
endmodule
Simulation Waveform:
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
1. Which gates are used to implement active high decoder and active low decoders?
2. Design half adder using 2 to 4 Decoder.
3. Design half subtractor using 2 to 4 Decoder.
4. What are the uses of decoder?
5. What are the applications of decoder?
Result: The verilog Program for 2-to-4 decoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 2 to 4 Decoder using If Else Statements
Program
Module decoder2to4(sel,en,y);
Input [1:0] sel;
Input en;
output [3:0]y;
reg [3:0] y;
always @ (sel,en)
begin
if(en==0)
y=4b1111;
else
if (sel == 2b00)
y=4b1110;
else if (sel == 2b01)
y=4b1101;
else if (sel == 2b10)
y=4b1011;
else
y=4b0111;
end
endmoudle
Simulated waveform:
Result: The verilog Program for 2-to-4 decoder by using Xilinx 9.2i Software is Simulated and verified
successfully
MLR Institute of Technology 20
Department Of ECE ECAD and VLSI Lab Manual
Aim: Write a verilog program to simulate and verify the 2 to 4 Decoder using Dataflow Model
Progarm
module decoder2_4 ( a ,b ,w ,x ,y ,z );
output w ;
output x ;
output y ;
output z ;
input a ;
input b ;
assign w = (~a) & (~b);
assign x = (~a) & b;
assign y = a & (~b);
assign z = a & b;
endmodule
Simulated waveform:
Result: The verilog Program for 2-to-4 decoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 3 to 8 Decoder using Structural Model
Program
Simulated waveform:
Result: The verilog Program for 3-to-8 decoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 3 to 8 Decoder using Behavioral Model
Program
module decoder(
input [1:0] a,
output reg [3:0] y
);
always@(a)
case(a)
2'b00: y= 4'b0001;
2'b01: y= 4'b0010;
2'b10: y= 4'b0100;
2'b11: y= 4'b1000;
endcase
endmodule
Simulated waveform:
Result: The verilog Program for 3-to-8 decoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Experiment No: 3
Software:
Xilinx 9.2i.
Block Diagram:
Truth Table:
Theory:
Encoder :
An encoder is a device, circuit, transducer, software program, algorithm or person that converts
information from one format or code to another. The purpose of encoder is standardization, speed,
secrecy, security, or saving space by shrinking size. Encoders are combinational logic circuits and they
are exactly opposite of decoders. They accept one or more inputs and generate a multibit output code.
Encoders perform exactly reverse operation than decoder. An encoder has M input and N output lines.
Out of M input lines only one is activated at a time and produces equivalent code on output N lines. If a
device output code has fewer bits than the input code has, the device is usually called an encoder.
Octal-to-Binary take 8 inputs and provides 3 outputs, thus doing the opposite of what the 3-to-8
decoder does. At any one time, only one input line has a value of 1. The figure below shows the truth
table of an Octal-to-binary encoder.
For an 8-to-3 binary encoder with inputs I0-I7 the logic expressions of the outputs Y0-Y2 are:
Y0 = I1 + I3 + I5 + I7
Y1= I2 + I3 + I6 + I7
Y2 = I4 + I5 + I6 +I7
Program:
module encoder_8x3(
input [7:0] a,
output reg [2:0] y);
always @(a)
begin
if (a==8'b00000001) y=3'b000;
else if (a==8'b00000010) y=3'b001;
else if (a==8'b00000100) y=3'b010;
else if (a==8'b00001000) y=3'b011;
else if (a==8'b00010000) y=3'b100;
else if (a==8'b00100000) y=3'b101;
else if (a==8'b01000000) y=3'b110;
else if (a==8'b10000000) y=3'b111;
else y=3'bX;
end
endmodule
Simulation Waveform:
Result: The verilog Program for 8-to-3 encoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Software:
Xilinx 9.1i.
Block Diagram:
Truth Table:
Theory:
Priority encoder:
A priority encoder is a circuit or algorithm that compresses multiple binary inputs into a smaller
number of outputs. The output of a priority encoder is the binary representation of the ordinal number
starting from zero of the most significant input bit. They are often used to control interrupt requests by
acting on the highest priority request. It includes priority function. If 2 or more inputs are equal to 1 at
the same time, the input having the highest priority will take precedence. Internal hardware will check
this condition and priority is set.
Priority encoders are available in standard IC form and the TTL 74LS148 is an 8-to-3 bit priority
encoder which has eight active LOW (logic "0") inputs and provides a 3-bit code of the highest ranked
MLR Institute of Technology 27
Department Of ECE ECAD and VLSI Lab Manual
input at its output. Priority encoders output the highest order input first for example, if input lines "D2",
"D3" and "D5" are applied simultaneously the output code would be for input "D5" ("101") as this has
the highest order out of the 3 inputs. Once input "D5" had been removed the next highest output code
would be for input "D3" ("011"), and so on.
Program:
Simulation Waveform:
Result: The verilog Program for 8-to-3 encoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Viva Questions:
1. Which gates are used to 8X3 encoder?
2. What are the uses of encoder?
3. What is the difference between encoder with priority and with priority?
4. Which IC is used for encoder?
5. Which Of the following encode used for many code conversions?
(a) Octal to binary (b) Decimal to BCD (C) Hex to binary
Program
module encoder_8_to_3(
input [7:0] i,
output reg [2:0] out
);
always@(*)
begin
case(i)
8'b00000001: out <= 3'b000;
8'b00000010: out <= 3'b001;
8'b00000100: out <= 3'b010;
8'b00001000: out <= 3'b011;
8'b00010000: out <= 3'b100;
8'b00100000: out <= 3'b101;
8'b01000000: out <= 3'b110;
8'b10000000: out <= 3'b111;
default: out<= 3'bxxx;
endcase
end
endmodule
Simulated waveform:
Result: The verilog Program for 8-to-3 encoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Program
Result: The verilog Program for 8-to-3 encoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Program
module encoder8x3(
input [7:0] a,
output reg [2:0] y
);
always @(a)
begin
if (a==8'b00000001) y=3'b000;
else if (a==8'b00000010) y=3'b001;
else if (a==8'b00000100) y=3'b010;
else if (a==8'b00001000) y=3'b011;
else if (a==8'b00010000) y=3'b100;
else if (a==8'b00100000) y=3'b101;
else if (a==8'b01000000) y=3'b110;
else if (a==8'b10000000) y=3'b111;
else y=3'bX;
end
endmodule
Simulated waveform:
Result: The verilog Program for 8-to-3 encoder by using Xilinx 9.2i Software is Simulated and verified
successfully
Experiment No: 4
Aim: Write a verilog program to simulate and verify the 8 to 1 Multiplexer using Behavioral Model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Program:
module multiplier_8x1(
input [7:0] a,
input [2:0] s,
output reg y);
always@(a,s)
case(s)
3'b000: y=a[0];
3'b001: y=a[1];
3'b010: y=a[2];
3'b011: y=a[3];
3'b100: y=a[4];
3'b101: y=a[5];
3'b110: y=a[6];
3'b111: y=a[7];
endcase
endmodule
Theory:
Multiplexer:
In electronics, a multiplexer or mux is a device that selects one of several analog or digital input
signals and forwards the selected input into a single line. A multiplexer of 2n inputs has n select lines,
which are used to select which input line to send to the output. An electronic multiplexer can be
considered as a multiple-input, single-output switch i.e. digitally controlled multi-position switch. The
digital code applied at the select inputs determines which data inputs will be switched to output.
A common example of multiplexing or sharing occurs when several peripheral devices share a
single transmission line or bus to communicate with computer. Each device in succession is allocated a
brief time to send and receive data. At any given time, one and only one device is using the line. This is
an example of time multiplexing since each device is given a specific time interval to use the line.
Simulation Waveform:
Procedure:
1. On the schematic editor of tina pro software connect the circuit as shown in the figure 1.1.
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
Result: The verilog Program for 8x1 mux by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 1 to 8 Multiplexer using Behavioral Model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
DeMultiplexer:
A demultiplexer (or demux) is a device taking a single input signal and selecting one of many data-
output-lines, which is connected to the single input. A multiplexer is often used with a complementary
demultiplexer on the receiving end. A demultiplexer is a single-input, multiple-output switch.
Demultiplexers take one data input and a number of selection inputs, and they have several outputs.
They forward the data input to one of the outputs depending on the values of the selection inputs.
Demultiplexers are sometimes convenient for designing general purpose logic, because if the
demultiplexer's input is always true, the demultiplexer acts as a decoder. This means that any function
of the selection bits can be constructed by logically OR-ing the correct set of outputs. Demultiplexer is
called as a distributro, since it transmits the same data to different destinations.
Program:
module Demux8to1(
input a,
input [2:0] s,
output reg [7:0] z =0 );
always@(a,s)
if (s==0) z[0] = a;
else if (s==1) z[1] = a;
else if (s==2) z[2] = a;
else if (s==3) z[3] = a;
else if (s==4) z[4] = a;
else if (s==5) z[5] = a;
else if (s==6) z[6] = a;
else if (s==7) z[7] = a;
endmodule
Simulation Waveform:
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Result: The verilog Program for 1x8 demux by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 4 to 1 Multiplexer using logical expression
Program
Result: The verilog Program for 4x1 mux by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 4 to 1 Multiplexer using Dataflow Model
Program
endmodule
Simulated waveform:
Result: The verilog Program for 8x1 mux by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify the 4 to 1 Multiplexer using Structural Model
Program
Simulated waveform:
Result: The verilog Program for 8x1 mux by using Xilinx 9.2i Software is Simulated and verified
successfully
Experiment No: 5
Aim: Write a verilog program to simulate and verify the 4 Binary to Gray conversion Using
Behavioral model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Dec Gray Binary
0 000 000
1 001 001
2 011 010
3 010 011
4 110 100
5 111 101
6 101 110
7 100 111
Fig 5.4: Internal circuit diagram for 4 Bit Binary to Gray conversion
Theory:
The reflected binary code, also known as Gray code/Cyclic Code/Unique Distance Code after Frank
Gray, is a binary numeral system where two successive values differ in only one bit. It is a non-
weighted code.
The reflected binary code was originally designed to prevent spurious output from electromechanical
switches. Today, Gray codes are widely used to facilitate error correction in digital communications
such as digital terrestrial television and some cable TV systems.
Many devices indicate position by closing and opening switches. If that device uses natural binary
codes, these two positions would be right next to each other:
...
011
100
...
The problem with natural binary codes is that, with real (mechanical) switches, it is very
unlikely that switches will change states exactly in synchrony. In the transition between the two states
shown above, all three switches change state. In the brief period while all are changing, the switches
will read some spurious position. Even without key bounce, the transition might look like 011 001
101 100. When the switches appear to be in position 001, the observer cannot tell if that is the
"real" position 001, or a transitional state between two other positions. If the output feeds into a
sequential system (possibly via combinational logic) then the sequential system may store a false
value.The reflected binary code solves this problem by changing only one switch at a time, so there is
never any ambiguity of position,
Notice that state 7 can roll over to state 0 with only one switch change. This is called the "cyclic"
property of a Gray code. In the standard Gray coding the least significant bit follows a repetitive pattern
of 2 on, 2 off ( 11001100 ); the next digit a pattern of 4 on, 4 off; and so forth.
More formally, a Gray code is a code assigning to each of a contiguous set of integers, or to
each member of a circular list, a word of symbols such that each two adjacent code words differ by one
symbol. These codes are also known as single-distance codes, reflecting the Hamming distance of 1
between adjacent codes. There can be more than one Gray code for a given word length, but the term
was first applied to a particular binary code for the non-negative integers, the binary-reflected Gray
code, or BRGC, the three-bit version of which is shown above.
Program:
module binary_gray(
input [3:0] b,
output [3:0] g);
assign g[3]=b[3];
assign g[2]=b[3]^b[2];
assign g[1]=b[2]^b[1];
assign g[0]=b[1]^b[0];
endmodule
Simulation Waveform:
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
1. Why gray code is called cyclic code or unique distance code?
2. Give application of gray code.
3. Convert 1010 binary code to gray code.
4. Convert 1110 gray code to binary code.
5. Solve the Boolean expression AB+A bar B bar
Result: The verilog Program for 4 bit binary to gray conversion by using Xilinx 9.2i Software is
Simulated and verified successfully
Aim: Write a verilog program to simulate and verify the 4 Binary to Gray conversion Using Always
statement
Program
module bin_to_gray(
input clk,
input [2:0]gray_input,
output reg [2:0]bin_out
);
always@(posedge clk)
begin
bin_out[2] <= gray_input[2];
bin_out[1] <= bin_out[2] ^ gray_input[1];
bin_out[0] <= bin_out[1] ^ gray_input[0];
end
endmodule
Simulated waveform:
Result: The verilog Program for 4 bit binary to gray conversion by using Xilinx 9.2i Software is
Simulated and verified successfully
Aim: Write a verilog program to simulate and verify the 4 Binary to Gray conversion Using
Structural Model
Program
endmodule
Simulated waveform:
Result: The verilog Program for 4 bit binary to gray conversion by using Xilinx 9.2i Software is
Simulated and verified successfully
Aim: Write a verilog program to simulate and verify the 7 segment code Gray conversion using
behavioral Model
Program
Simulated waveform:
Result: The verilog Program for BCD to 7 segment code conversion by using Xilinx 9.2i Software is
Simulated and verified successfully
Aim: Write a verilog program to simulate and verify the 7 segment code Gray conversion using
conditional operator
Program
endmodule
Simulated waveform:
Result: The verilog Program for BCD to 7 segment code conversion by using Xilinx 9.2i Software is
Simulated and verified successfully
Experiment No: 6
Aim: Write a verilog program to simulate and verify 4 BIT COMPARATOR using Data Flow Model
Software:
Xilinx 9.1i.
Block Diagram:
Truth Table:
Theory:
A digital comparator or magnitude comparator is a hardware electronic device that takes two
numbers as input in binary form and determines whether one number is greater than, less than or equal
to the other number. Comparators are used in a central processing units (CPU) and microcontrollers
Examples of digital comparator include the CMOS 4063 and 4585 and the TTL 7485 and 74682-'89.
The analog equivalent of digital comparator is the voltage comparator. Many microcontrollers have
analog comparators on some of their inputs that can be read or trigger an interrupt.
The purpose of a two-bit binary comparator is quite simple. It determines whether one 2-bit input
number is larger than, equal to, or less than the other. The circuitry accomplishes this through several
logic gates that operate on the principles of Boolean algebra. Since the circuitry is based upon an
algebraic system it can not only be made simpler through mathematical manipulation, but there is also
no absolute solution to the given task
Design
The first step in the creation of the comparator circuit is the generation of a truth table that lists the
input variables, their possible values, and the resulting outputs for each of those values. The truth table
used for this experiment is shown
From the truth table, canonical minterm equations were generated for each output variable. These
equations were then simplified to represent as few logic gates as possible
The final equations were then used to sketch a circuit schematic for each variable. Once each
variable had a schematic, common values were found and the three schematics were combined to create
a single circuit diagram.
The other problem with the circuit design is its inability to interpret signed numbers. For example,
when A is 10 and B is 00, the circuit shows that A is greater than B. If A is interpreted as a signed
number its value is negative two. In this case, the comparator should show L as a high as A would be
less than B.
Program:
module Comparator(
input [3:0] a,
input [3:0] b,
output a_gt_b,
output a_ls_b,
output a_eq_b
);
assign a_gt_b = (a > b);
assign a_ls_b = (a < b);
assign a_eq_b = (a == b);
endmodule
Simulation Waveform:
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
1. Explain what is the differnce between decoder and demultiplexer?
2. Which gates are used to implement Demultiplexier?
3. To Design 1X8 De-Mux. How many number of 1X2 De-Mux required.
4. Write the output expression for 2-bit comparator?
5. What are the applications of comparator?
Result: The verilog Program for 4 bit comparator by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify 1 BIT COMPARATOR using Data Flow Model
Program
module comp4bit(eq,gr,ls,a,b);
input [3:0] a,b;
output eq,gr,ls;
assign eq = (a==b) ? 1 : 0;
assign gr = (a>b) ? 1 : 0;
assign ls = (a<b) ? 1 : 0;
endmodule
Simulated waveform:
Result: The verilog Program for 1 bit comparator by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify 2 BIT COMPARATOR using Data Flow Model
Program
endmodule
Simulated waveform:
Result: The verilog Program for 2 bit comparator by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify 4 BIT COMPARATOR using behavioral model
Program
Result: The verilog Program for 4 bit comparator by using Xilinx 9.2i Software is Simulated and
verified successfully
Aim: Write a verilog program to simulate and verify 4 BIT COMPARATOR using structural
model
Program
input clk ;
wire clk ;
input reset ;
wire reset ;
initial dout = 0;
endmodule
simulated waveform :
Result: The verilog Program for 4 bit comparator by using Xilinx 9.2i Software is Simulated and
verified successfully
Experiment No: 7
7.1 Full Adder Using Dataflow Model
Aim: Write a verilog program to simulate and verify Full Adder using Dataflow Model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
Full Adder:
A full adder adds binary numbers and accounts for values carried in as well as out. A one-bit full adder
adds three one-bit numbers, often written as A, B, and Cin; A and B are the operands, and Cin is a bit
MLR Institute of Technology 63
Department Of ECE ECAD and VLSI Lab Manual
carried in from the next less significant stage. The full-adder is usually a component in a cascade of
adders, which add 8, 16, 32, etc. binary numbers. The circuit produces a two-bit output sum typically
represented by the signals Cout and S.
A full adder can be implemented in many different ways such as with a custom Transistor level
circuit or composed of other gates. One example implementation is with and
.
In this implementation, the final OR Gate before the carry-out output may be replaced by an XOR Gate
without altering the result
ing logic. Using only two types of gates is convenient if the circuit is being implemented using simple
IC chips which contain only one gate type per chip. In this light, Cout can be implemented as
.
A full adder can be constructed from two half adders by connecting A and B to the input of one half
adder, connecting the sum from that to an input to the second adder, connecting Ci to the other input
and OR the two carry outputs. Equivalently, S could be made the three-bit XOR of A, B, and Ci, and
Cout could be made the three-bit majority function of A, B, and Ci.
Program:
module fa_structural(x,y,cin,s,cout);
input x,y,cin;
output s,cout;
wire s1,c1,c2,c3;
xor(s1,x,y);
xor(s,cin,s1);
and(c1,x,y);
and(c2,y,cin);
and(c3,x,cin);
or(cout,c1,c2,c3);
endmodule
Simulation Waveform:
Procedure:
1. On the schematic editor of tina pro software connect the circuit as shown in the figure 1.1.
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Result: The verilog Program for full adder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify Full Adder using Behavioral Model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Program:
module FullAdder_CtAssign(
input A,
input B,
input Ci,
output S,
output Co
);
assign S =A^B^Ci;
assign Co= (A&B) | (Ci&A) | (Ci&B);
endmodule
Simulation Waveform:
Procedure:
1. On the schematic editor of tina pro software connect the circuit as shown in the figure 1.1.
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Result: The verilog Program for full adder by using Xilinx 9.2i Software is Simulated and verified
successfully
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Program:
module FullAdder_Structural(
input A,
input B,
input Ci,
output S,
output Co
);
wire z1,z2,z3,z4;
and And1(z1,A,B);
and And2(z2,A,Ci);
and And3(z3,B,Ci);
or Or1(Co, z1, z2, z3);
xor Xor1(z4, A, B);
xor Xor2(S,z4,Ci);
endmodule
Simulation Waveform:
Result: The verilog Program for full adder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify Full Adder using Procedural Model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Program:
module FullAdder_Procedural(
input A,
input B,
input Ci,
output reg S,
output reg Co
);
always @(Ci, A, B)
begin
case({Ci, A, B})
3'b000: {Co,S}= 'b00;
3'b001: {Co,S}= 'b01;
3'b010: {Co,S}= 'b01;
3'b011: {Co,S}= 'b10;
3'b100: {Co,S}= 'b00;
3'b101: {Co,S}= 'b10;
3'b110: {Co,S}= 'b10;
3'b111: {Co,S}= 'b11;
Endcase
Simulation Waveform:
Result: The verilog Program for full adder by using Xilinx 9.2i Software is Simulated and verified
successfully
Precautions
Use Computer with proper care and shut down it after completion of the work.
DONT INSERT PEN DRIVES.
Viva Questions:
1. How many number of NAND and NOR gates are required to implement Full adder?
2. Write the other expressions for Sum and Carry for full adder and full subtractor?
3. Design Full adder using 3X8 Decoder.
4. What are the difference between combinational circuits and sequential circuits?
5. What is the main difference between Half adder and Full adder?
MLR Institute of Technology 72
Department Of ECE ECAD and VLSI Lab Manual
Aim: Write a verilog program to simulate and verify Full Adder using Two Half Adder
Program
module ha(sumh,carryh,a,b);
input a,b;
output sumh,carryh;
xor x1(sumh,a,b);
and a1(carryh,a,b);
endmodule
//full adder
module fastrc(sum,carry,A,B,Cin);
input A,B,Cin;
output sum,carry;
wire sum1,carry1,carry2;
ha h1(sum1,carry1,A,B);
ha h2(sum,carry2,sum1,Cin);
or o1(carry,carry2,carry1);
endmodule
Simulation Wave Form
Result: The verilog Program for full adder by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify SR flip flop using behavioral model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
In electronics, a flip-flop or latch is a circuit that has two stable states and can be used to store state
information. The circuit can be made to change state by signals applied to one or more control inputs and will
have one or two outputs. It is the basic storage element in sequential logic. Flip-flops and latches are a
fundamental building block of digital electronics systems used in computers, communications, and many other
types of systems.
Flip-flops and latches are used as data storage elements. Such data storage can be used for storage of state,
and such a circuit is described as sequential logic. When used in a finite-state machine, the output and next state
depend not only on its current input, but also on its current state (and hence, previous inputs). It can also be
used for counting of pulses, and for synchronizing variably-timed input signals to some reference timing signal.
Flip-flops can be either simple (transparent or opaque) or clocked (synchronous or edge-triggered); the simple
ones are commonly called latches. The word latch is mainly used for storage elements, while clocked devices
are described as flip-flops.
Flip-flop types
Flip-flops can be divided into common types: the SR ("set-reset"), D ("data" or "delay"[16]), T ("toggle"), and JK types are the common
ones. The behavior of a particular type can be described by what is termed the characteristic equation, which derives the "next" (i.e.,
after the next clock pulse) output, , in terms of the input signal(s) and/or the current output, .
An SR latch, constructed from a pair of cross-coupled NOR gates (an animated picture). Red and black mean logical '1' and '0', respectively.
When using static gates as building blocks, the most fundamental latch is the simple SR latch, where S and R stand
for set and reset. It can be constructed from a pair of cross-coupled NOR logic gates. The stored bit is present on the output marked
Q.
While the S and R inputs are both low, feedback maintains the Q and Q outputs in a constant state, with Q the complement of Q. If S
(Set) is pulsed high while R (Reset) is held low, then the Q output is forced high, and stays high when S returns to low; similarly, if R
is pulsed high while S is held low, then the Q output is forced low, and stays low when R returns to low.
SR latch operation[17]
0 0 Q hold state 0 0 0 x
0 1 0 reset 0 1 1 0
1 0 1 set 1 0 0 1
1 1 X not allowed 1 1 X 0
The R = S = 1 combination is called a restricted combination or a forbidden state because, as both NOR gates then output zeros,
it breaks the logical equation Q = not Q. The combination is also inappropriate in circuits where both inputs may go
low simultaneously (i.e. a transition from restricted to keep). The output would lock at either 1 or 0 depending on the propagation
time relations between the gates (a race condition). In certain implementations, it could also lead to
longer ringings (damped oscillations) before the output settles, and thereby result in undetermined values (errors) in high-frequency
digital circuits. Although this condition is usually avoided, it can be useful in some applications.
To overcome the restricted combination, one can add gates to the inputs that would convert (S,R) = (1,1) to one of the non-
restricted combinations. That can be:
Alternatively, the restricted combination can be made to toggle the output. The result is the JK latch.
SR NAND latch
An SR latch
This is an alternate model of the simple SR latch built with NAND (not AND) logic gates. Set and reset now become active low
signals, denoted S and R respectively. Otherwise, operation is identical to that of the SR latch. Historically, SR-latches have been
predominant despite the notational inconvenience of active-low inputs.
SR latch operation
S R Action
0 0 Restricted combination
0 1 Q=1
Symbol for an SRNAND latch
1 0 Q=0
1 1 No Change
JK latch
The JK latch is much less used than the JK flip-flop. The JK latch follows the following state table:
J K Qnext Comment
0 0 Q No change
0 1 0 Reset
1 0 1 Set
1 1 Q Toggle
Hence, the JK latch is an SR latch that is made to toggle its output when passed the restricted combination of 11. Unlike the JK flip-flop, the 11 input combination
[19]
for the SR latch is not useful because there is no clock that directs toggling.
Gated SR latch
A synchronous SR latch (sometimes clocked SR flip-flop) can be made by adding a second level of NAND gates to the inverted SR latch (or a second level of
AND gates to the direct SR latch). The extra gates further invert the inputs so the simple SR latch becomes a gated SR latch (and a simple SR latch would
transform into a gated SR latch with inverted enable).
With E high (enable true), the signals can pass through the input gates to the encapsulated latch; all signal combinations except for (0,0) = hold then immediately
reproduce on the (Q,Q) output, i.e. the latch is transparent.
With E low (enable false) the latch is closed (opaque) and remains in the state it was left the last time E was high.
The enable input is sometimes a clock signal, but more often a read or write strobe.
E/C Action
Program:
module sr_ff(input S,input R,input Clk,output reg Qa =1'b0,
output reg Qb =1'b1);
reg a,b;
always@(S,R,Clk)
begin
a=Qa;
b=Qb;
if (Clk==1'b1)
case({S,R})
'b00: {Qa,Qb} ={a,b};
'b01: {Qa,Qb} = 'b01;
'b10: {Qa,Qb} = 'b10;
endcase
else if(Clk==1'b0)
{Qa,Qb} ={a,b};
end
endmodule
Simulation Waveform:
Result: The verilog Program for SR flip flop by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: Write a verilog program to simulate and verify D flip flop using behavioral model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
D flip-flop
D flip-flop symbol
The D ip-op is widely used. It is also known as a data or delay flip-flop. The D flip-flop captures the value of the
D-input at a definite portion of the clock cycle (such as the rising edge of the clock). That captured value
becomes the Q output. At other times, the output Q does not change. The D flip-flop can be viewed as a memory
cell, a zero-order hold, or a delay line.
Truth table:
Clock D Qnext
Rising edge 0 0
Rising edge 1 1
Non-Rising X Q
Most D-type flip-flops in ICs have the capability to be forced to the set or reset state (which ignores the D
and clock inputs), much like an SR flip-flop. Usually, the illegal S = R = 1 condition is resolved in D-type flip-
flops. By setting S = R = 0, the flip-flop can be used as described above.
Inputs Outputs
S R D > Q Q'
0 1 X X 0 1
1 0 X X 1 0
1 1 X X 1 1
These flip-flops are very useful, as they form the basis for shift registers, which are an essential part of
many electronic devices. The advantage of the D flip-flop over the D-type "transparent latch" is that the
signal on the D input pin is captured the moment the flip-flop is clocked, and subsequent changes on the
D input will be ignored until the next clock event. An exception is that some flip-flops have a "reset"
signal input, which will reset Q (to zero), and may be either asynchronous or synchronous with the
clock.
The above circuit shifts the contents of the register to the right, one bit position on each active transition
of the clock. The input X is shifted into the leftmost bit position.
D-Flipflop (Delay)
Program:
module ff_d(data,clk,reset,q );
input data, clk, reset ;
output q;
reg q;
always @ ( posedge clk or negedge reset)
if (reset) begin
q <= 1'b0;
end
else begin
q <= data;
end
endmodule
Simulation Waveform:
Result: The verilog Program for SR flip flop by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: To simulate and verify the JK flip flop using Behavioral model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
JK flip-flop
The JK flip-flop augments the behavior of the SR flip-flop (J=Set, K=Reset) by interpreting the S = R = 1 condition as a "flip" or toggle command. Specifically, the
combination J = 1, K = 0 is a command to set the flip-flop; the combination J = 0, K = 1 is a command to reset the flip-flop; and the combination J = K = 1 is a
command to toggle the flip-flop, i.e., change its output to the logical complement of its current value. Setting J = K = 0 does NOT result in a D flip-flop, but rather,
will hold the current state. To synthesize a D flip-flop, simply set K equal to the complement of J. Similarly, to synthesize a T flip-flop, set K equal to J. The JK flip-
flop is therefore a universal flip-flop, because it can be configured to work as an SR flip-flop, a D flip-flop, or a T flip-flop.
0 1 0 reset 0 1 1 X Set
1 0 1 set 1 0 X 1 Reset
1 1 Q toggle 1 1 X 0 No change
Another way to avoid the problem of the RS flip-flop when R=S=1 is to have feedbacks
from Q and Q' to the input AND gates, as shown below. The resulting circuit is called JK
flip-flop with two inputs J=S and K=R.
It is not difficult to obtain the truth table of this JK flip-flop. Note that when J=K=1, the
flip-flop always complements its previous output. In the following the clock CLK is omitted
as the circuit is active only when CLK=1.
Program:
module jk_ff(input wire J,
input wire K,
input wire Clk,
output reg Q=0,
output reg Qbar=1);
reg a,b;
always@(posedge Clk)
begin
a=Q; b=~Q;
case({J,K})
'b00: {Q,Qbar} = {a,b};
'b01:
begin
Q=0; a=Q; b=~Q; Qbar =b;
end
'b10:
begin
Q=1; a=Q; b=~Q; Qbar =b;
end
'b11: {Q,Qbar} = {b,a};
endcase
end
endmodule
Simulation Waveform:
Result: The verilog Program for JK flip flop by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: To simulate and verify the T flip flop using Behavioral model
Software:
Xilinx 9.2i
Block Diagram:
Truth Table:
Theory:
T flip-flop
If the T input is high, the T flip-flop changes state ("toggles") whenever the clock input is strobed. If the T input is
low, the flip-flop holds the previous value. This behavior is described by the characteristic equation:
T flip-flop operation
Comment Comment
1 0 1 toggle 0 1 1 Complement
1 1 0 toggle 1 0 1 Complement
When T is held high, the toggle flip-flop divides the clock frequency by two; that is, if clock frequency is
4 MHz, the output frequency obtained from the flip-flop will be 2 MHz. This "divide by" feature has
application in various types of digital counters. A T flip-flop can also be built using a JK flip-flop (J & K pins
are connected together and act as T) or D flip-flop (T input and Qprevious is connected to the D input through
an XOR gate). A T flip-flop can also be built using an edge-triggered D flip-flop with its D input fed from its
own inverted output.
T-Flipflop (Toggle)
If the J and K inputs are tied together and renamed as T (for toggle), only the first
and last states of JK-FF remain and the FF becomes a toggle FF:
The different types of Flipflops (R,S, J,K, D, T) can also be described by their excitation
table as shown below. The left side shows the desired transition from to ,
the right side gives the triggering signals of various types of FFs needed for the transitions.
Program:
module t_ff(input T,input Clk,output reg Q=0,output reg Qbar,output reg Di);
always@(posedge Clk)
begin
Di=T^Q; Q=Di; Qbar=~Q;
end
endmodule
Simulation Waveform:
Result: The verilog Program for T flip flop by using Xilinx 9.2i Software is Simulated and verified
successfully
Aim: To simulate and verify the Synchronous JK flip flop using case statement
Program
module JKflipflop(
input wire J,
input wire K,
input wire Clk,
output reg Q=0,
output reg Qbar=1);
reg a,b;
always@(posedge Clk)
begin
a=Q; b=~Q;
case({J,K})
'b00: {Q,Qbar} = {a,b};
'b01:
begin
Q=0; a=Q; b=~Q; Qbar =b;
end
'b10:
begin
Q=1; a=Q; b=~Q; Qbar =b;
end
'b11: {Q,Qbar} = {b,a};
Endcase
Result: The verilog Program for JK flip flop by using Xilinx 9.2i Software is Simulated and verified
successfully