CS8382 Digital Lab Manual
CS8382 Digital Lab Manual
LAB MANUAL
1
SYLLABUS
7. Design and implementation of encoder and decoder using logic gates and
study of IC7445 and IC74147
10. Implementation of SISO, SIPO, PISO and PIPO shift registers using Flip-
flops
2
LIST OF EXPERIMENTS
Title
S. No
1. Design of Adders using logic gates and Verilog HDL
2. Design of Subtractor using logic gates and Verilog HDL
3. Design of BCD to excess-3 code converter and vice versa using logic gates
4. Design of Binary to Gray code converter and vice-versa using logic gates
5. Design of 4 bit binary Adder/ Subtractor and BCD adder using IC 7483
Design of 2 bit Magnitude Comparator using logic gates and 8 Bit Magnitude
6.
Comparator using IC 7485
7. Design of Encoder and decoder using logic gates and study of IC7445, IC74147
8. Design of 16-bit odd/even parity checker/ generator using IC74180
9. Design of Mux using logic gates, Verilog HDL and study of IC74150
10. Design of De-Mux using logic gates, Verilog HDL and study of IC 74154
11. Design of 4 bit ripple counter and Mod-10 / Mod-12 Ripple counters
12. Design of 3-bit synchronous up/down counter
13. Design of SISO, SIPO, PISO and PIPO Shift Registers using Flip-flops
14. Design of Counters and Shift Registers using Verilog HDL
3
EXPT NO. : STUDY OF LOGIC GATES
DATE :
AIM:
To study about logic gates and verify their truth tables.
APPARATUS REQUIRED:
SL No. COMPONENT SPECIFICATION QTY
1. AND GATE IC 7408 1
2. OR GATE IC 7432 1
3. NOT GATE IC 7404 1
4. NAND GATE 2 I/P IC 7400 1
5. NOR GATE IC 7402 1
6. X-OR GATE IC 7486 1
7. NAND GATE 3 I/P IC 7410 1
8. IC TRAINER KIT - 1
9. PATCH CORD - 14
THEORY:
Circuit that takes the logical decision and the process are called logic
gates. Each gate has one or more input and only one output.
OR, AND and NOT are basic gates. NAND and NOR are known as
universal gates. Basic gates form these gates.
AND GATE:
The AND gate performs a logical multiplication commonly known as
AND function. The output is high when both the inputs are high. The output
is low level when any one of the inputs is low.
4
OR GATE:
NOT GATE:
The NOT gate is called an inverter. The output is high when the
input is low. The output is low when the input is high.
NAND GATE:
The output is high when any one of the inputs is high. The output is
low when both the inputs are low and both the inputs are high.
PROCEDURE:
(i) Connections are given as per circuit diagram.
(ii) Logical inputs are given as per circuit diagram.
(iii) Observe the output and verify the truth table.
RESULT:
5
AND GATE:
6
OR GATE:
NOT GATE:
7
X-OR GATE :
8
3-INPUT NAND GATE :
9
NOR GATE:
1
EXPT NO. : DESIGN OF ADDER AND SUBTRACTOR
DATE :
AIM:
To design and construct half adder, full adder, half subtractor and full
subtractor circuits and verify the truth table using logic gates.
APPARATUS REQUIRED:
THEORY:
HALF ADDER:
A half adder has two inputs for the two bits to be added and two
outputs one from the sum ‘ S’ and other from the carry ‘ c’ into the higher
adder position. Above circuit is called as a carry signal from the addition of
the less significant bits sum from the X-OR Gate the carry out from the
AND gate.
1
FULL ADDER:
The half subtractor is constructed using X-OR and AND Gate. The
half subtractor has two input and two outputs. The outputs are difference and
borrow. The difference can be applied using X-OR Gate, borrow output can
be implemented using an AND Gate and an inverter.
FULL SUBTRACTOR:
1
RESULT:
HALF ADDER
TRUTH TABLE:
A B CARRY SUM
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
LOGIC DIAGRAM:
1
FULL ADDER
TRUTH TABLE:
A B C CARRY SUM
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
1
CARRY = AB + BC + AC
LOGIC DIAGRAM:
HALF SUBTRACTOR
TRUTH TABLE:
A B BORROW DIFFERENCE
0 0 0 0
0 1 1 1
1 0 0 1
1 1 0 0
1
K-Map for BORROW:
BORROW = A’B
LOGIC DIAGRAM:
FULL SUBTRACTOR
TRUTH TABLE:
A B C BORROW DIFFERENCE
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 1 0
1 0 0 0 1
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
1
K-Map for Borrow:
1
EXPT NO. :
DATE :
APPARATUS REQUIRED:
Sl.No. COMPONENT SPECIFICATION QTY.
1. X-OR GATE IC 7486 1
2. AND GATE IC 7408 1
3. OR GATE IC 7432 1
4. NOT GATE IC 7404 1
5. IC TRAINER KIT - 1
6. PATCH CORDS - 35
THEORY:
The availability of large variety of codes for the same discrete
elements of information results in the use of different codes by different
systems. A conversion circuit must be inserted between the two systems if
each uses different codes for same information. Thus, code converter is a
circuit that makes the two systems compatible even though each uses
different binary code.
The bit combination assigned to binary code to gray code. Since each
code uses four bits to represent a decimal digit. There are four inputs and
four outputs. Gray code is a non-weighted code.
1
The input variable are designated as B3, B2, B1, B0 and the output
variables are designated as C3, C2, C1, Co. from the truth table,
combinational circuit is designed. The Boolean functions are obtained from
K-Map for each output variable.
A code converter is a circuit that makes the two systems compatible
even though each uses a different binary code. To convert from binary code
to Excess-3 code, the input lines must supply the bit combination of
elements as specified by code and the output lines generate the
corresponding bit combination of code. Each one of the four maps represents
one of the four outputs of the circuit as a function of the four input variables.
A two-level logic diagram may be obtained directly from the Boolean
expressions derived by the maps. These are various other possibilities for a
logic diagram that implements this circuit. Now the OR gate whose output is
C+D has been used to implement partially each of three outputs.
PROCEDURE:
(iii) Observe the logical output and verify with the truth tables.
RESULT:
1
BINARY TO GRAY CODE CONVERTOR
TRUTH TABLE:
| Binary input | Gray code output |
B3 B2 B1 B0 G3 G2 G1 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0
G3 = B3
2
K-Map for G2:
2
LOGIC DIAGRAM:
G3 G2 G1 G0 B3 B2 B1 B0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 1 0 0 1 0 0
0 1 1 1 0 1 0 1
0 1 0 1 0 1 1 0
0 1 0 0 0 1 1 1
1 1 0 0 1 0 0 0
1 1 0 1 1 0 0 1
1 1 1 1 1 0 1 0
1 1 1 0 1 0 1 1
1 0 1 0 1 1 0 0
1 0 1 1 1 1 0 1
1 0 0 1 1 1 1 0
1 0 0 0 1 1 1 1
2
K-Map for B3:
B3 = G3
2
K-Map for B1:
2
LOGIC DIAGRAM:
0 0 0 0 0 0 1 1
0 0 0 1 0 1 0 0
0 0 1 0 0 1 0 1
0 0 1 1 0 1 1 0
0 1 0 0 0 1 1 1
0 1 0 1 1 0 0 0
0 1 1 0 1 0 0 1
0 1 1 1 1 0 1 0
1 0 0 0 1 0 1 1
1 0 0 1 1 1 0 0
2
K-Map for E3:
E3 = B3 + B2 (B0 + B1)
K-Map for E2:
E2=B2B1+B2B1B0+B2B1B0
E2=B2B1+B1(B2B0+B2B0) = B2B1+B1(B2 B0)
2
K-Map for E1:
= B1 О B0
K-Map for E0:
2
LOGIC DIAGRAM:
TRUTH TABLE:
x3 x2 X3 X4 A B C D
0 0 1 1 0 0 0 0
0 1 0 0 0 0 0 1
0 1 0 1 0 0 1 0
0 1 1 0 0 0 1 1
0 1 1 1 0 1 0 0
1 0 0 0 0 1 0 1
1 0 0 1 0 1 1 0
1 0 1 0 0 1 1 1
1 0 1 1 1 0 0 0
1 1 0 0 1 0 0 1
2
K-Map for A:
A = X1 X2 + X3 X4 X1
K-Map for B:
2
K-Map for C:
K-Map for D:
3
LOGIC DIAGRAM:
3
EXPT NO. : DESIGN OF 4-BIT ADDER AND SUBTRACTOR
DATE :
AIM:
To design and implement 4-bit adder and subtractor using IC 7483.
APPARATUS REQUIRED:
Sl.No. COMPONENT SPECIFICATION QTY.
1. IC IC 7483 1
2. EX-OR GATE IC 7486 1
3. NOT GATE IC 7404 1
3. IC TRAINER KIT - 1
4. PATCH CORDS - 40
THEORY:
3
4 BIT BINARY ADDER/SUBTRACTOR:
The addition and subtraction operation can be combined into one
circuit with one common binary adder. The mode input M controls the
operation. When M=0, the circuit is adder circuit. When M=1, it becomes
subtractor.
4 BIT BCD ADDER:
Consider the arithmetic addition of two decimal digits in BCD,
together with an input carry from a previous stage. Since each input digit
does not exceed 9, the output sum cannot be greater than 19, the 1 in the sum
being an input carry. The output of two decimal digits must be represented
in BCD and should appear in the form listed in the columns.
ABCD adder that adds 2 BCD digits and produce a sum digit in BCD.
The 2 decimal digits, together with the input carry, are first added in the top
4 bit adder to produce the binary sum.
PROCEDURE:
14. Observe the logical output and verify with the truth tables.
RESULT:
3
PIN DIAGRAM FOR IC 7483:
A A3 A2 A1 B4 B3 B2 B1 C S4 S3 S2 S1 B D4 D3 D2 D1
4
1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 1 0
1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0
0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0
0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 1 0
1 0 1 0 1 0 1 1 1 0 1 0 1 0 1 1 1 1
1 1 1 0 1 1 1 1 1 1 0 1 0 0 1 1 1 1
1 0 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1
3
4-BIT BINARY ADDER/SUBTRACTOR
LOGIC DIAGRAM:
3
BCD ADDER:
TRUTH TABLE:
K MAP
C = S4 (S3 + S2)
3
LOGIC DIAGRAM:
3
EXPT NO. :
DATE :
AIM:
To design and implement
(i) 2 – bit magnitude comparator using basic gates.
(ii) 8 – bit magnitude comparator using IC 7485.
APPARATUS REQUIRED:
THEORY:
3
comparator is specified by three binary variables that indicate whether A>B,
A=B (or) A<B.
A = A3 A2 A1 A0
B = B3 B2 B1 B0
3
PROCEDURE:
RESULT:
4
2 BIT MAGNITUDE COMPARATOR
TRUTH TABLE:
4
K MAP :
4
LOGIC DIAGRAM:
4
PIN DIAGRAM FOR IC 7485:
TRUTH TABLE:
LOGIC DIAGRAM:
4
4
EXPT NO. :
DATE :
AIM:
To design and implement 16 bit odd/even parity checker generator
using IC 74180.
APPARATUS REQUIRED:
THEORY:
4
amount. The parity checker circuit checks for possible errors in the
transmission. If the information is passed in even parity, then the bits
required must have an even number of 1’s. An error occur during
transmission, if the received bits have an odd number of 1’s indicating that
one bit has changed in value during transmission.
PROCEDURE:
RESULT:
4
PIN DIAGRAM FOR IC 74180:
FUNCTION TABLE:
INPUTS OUTPUTS
Number of High Data PE PO E O
Inputs (I0 – I7)
EVEN 1 0 1 0
ODD 1 0 0 1
EVEN 0 1 0 1
ODD 0 1 1 0
X 1 1 0 0
X 0 0 1 1
4
16 BIT ODD/EVEN PARITY CHECKER
TRUTH TABLE:
LOGIC DIAGRAM:
LOGIC DIAGRAM:
4
EXPT NO. :
DATE :
AIM:
To design and implement multiplexer and demultiplexer using logic
gates and study of IC 74150 and IC 74154.
APPARATUS REQUIRED:
Sl.No. COMPONENT SPECIFICATION QTY.
1. 3 I/P AND GATE IC 7411 2
2. OR GATE IC 7432 1
3. NOT GATE IC 7404 1
2. IC TRAINER KIT - 1
3. PATCH CORDS - 32
THEORY:
MULTIPLEXER:
Multiplexer means transmitting a large number of information units
over a smaller number of channels or lines. A digital multiplexer is a
combinational circuit that selects binary information from one of many input
lines and directs it to a single output line. The selection of a particular input
line is controlled by a set of selection lines. Normally there are 2 n input line
and n selection lines whose bit combination determine which input is
selected.
DEMULTIPLEXER:
The function of Demultiplexer is in contrast to multiplexer function. It
takes information from one line and distributes it to a given number of
5
output lines. For this reason, the demultiplexer is also known as a data
distributor. Decoder can also be used as demultiplexer.
In the 1: 4 demultiplexer circuit, the data input line goes to all of the
AND gates. The data select lines enable only one gate at a time and the data
on the data input line will pass through the selected gate to the associated
data output line.
PROCEDURE:
(i) Connections are given as per circuit diagram.
RESULT:
5
BLOCK DIAGRAM FOR 4:1 MULTIPLEXER:
FUNCTION TABLE:
S1 S0 INPUTS Y
0 0 D0 → D0 S1’ S0’
0 1 D1 → D1 S1’ S0
1 0 D2 → D2 S1 S0’
1 1 D3 → D3 S1 S0
5
CIRCUIT DIAGRAM FOR MULTIPLEXER:
TRUTH TABLE:
S1 S0 Y = OUTPUT
0 0 D0
0 1 D1
1 0 D2
1 1 D3
5
5
BLOCK DIAGRAM FOR 1:4 DEMULTIPLEXER:
FUNCTION TABLE:
S1 S0 INPUT
0 0 X → D0 = X S1’ S0’
0 1 X → D1 = X S1’ S0
1 0 X → D2 = X S1 S0’
1 1 X → D3 = X S1 S0
5
LOGIC DIAGRAM FOR DEMULTIPLEXER:
5
TRUTH TABLE:
INPUT OUTPUT
S1 S0 I/P D0 D1 D2 D3
0 0 0 0 0 0 0
0 0 1 1 0 0 0
0 1 0 0 0 0 0
0 1 1 0 1 0 0
1 0 0 0 0 0 0
1 0 1 0 0 1 0
1 1 0 0 0 0 0
1 1 1 0 0 0 1
5
5
PIN DIAGRAM FOR IC 74154:DEMUX
IC74155-DEMUX-8X1,16X1
5
EXPT NO. :
DATE :
AIM:
To design and implement encoder and decoder using logic gates and
study of IC 7445 and IC 74147.
APPARATUS REQUIRED:
THEORY:
ENCODER:
An encoder is a digital circuit that perform inverse operation of a
decoder. An encoder has 2n input lines and n output lines. In encoder the
output lines generates the binary code corresponding to the input value. In
octal to binary encoder it has eight inputs, one for each octal digit and three
output that generate the corresponding binary code. In encoder it is assumed
that only one input has a value of one at any given time otherwise the circuit
6
is meaningless. It has an ambiguila that when all inputs are zero the outputs
are zero. The zero outputs can also be generated when D0 = 1.
DECODER:
A decoder is a multiple input multiple output logic circuit which
converts coded input into coded output where input and output codes are
different. The input code generally has fewer bits than the output code. Each
input code word produces a different output code word i.e there is one to one
mapping can be expressed in truth table. In the block diagram of decoder
circuit the encoded information is present as n input producing 2 n possible
outputs. 2n output values are from 0 through out 2n – 1.
PROCEDURE:
RESULT:
6
BCD TO DECIMAL DECODER:
PIN DIAGRAM FOR IC 74155:2x4 Decoder
6
LOGIC DIAGRAM FOR ENCODER:
TRUTH TABLE:
INPUT OUTPUT
Y1 Y2 Y3 Y4 Y5 Y6 Y7 A B C
1 0 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 0 1 1
0 0 0 1 0 0 0 1 0 0
0 0 0 0 1 0 0 1 0 1
0 0 0 0 0 1 0 1 1 0
0 0 0 0 0 0 1 1 1 1
6
6
LOGIC DIAGRAM FOR DECODER:
TRUTH TABLE:
INPUT OUTPUT
E A B D0 D1 D2 D3
1 0 0 1 1 1 1
0 0 0 0 1 1 1
0 0 1 1 0 1 1
0 1 0 1 1 0 1
0 1 1 1 1 1 0
6
6
EXPT NO. :
DATE :
CONSTRUCTION AND VERIFICATION OF 4 BIT RIPPLE
COUNTER AND MOD 10/MOD 12 RIPPLE COUNTER
AIM:
To design and verify 4 bit ripple counter mod 10/ mod 12 ripple
counter.
APPARATUS REQUIRED:
THEORY:
6
PROCEDURE:
RESULT:
6
PIN DIAGRAM FOR IC 7476:
TRUTH TABLE:
6
CLK QD QC QB QA
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
16 0 0 0 0
7
MOD - 10 RIPPLE COUNTER
TRUTH TABLE:
CLK QD QC QB QA
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 0 0 0 0
LOGIC DIAGRAM:
7
7
MOD - 12 RIPPLE COUNTER
TRUTH TABLE:
CLK QD QC QB QA
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 0 0 0 0
LOGIC DIAGRAM:
7
7
EXPT NO. :
DATE :
DESIGN AND IMPLEMENTATION OF 3 BIT SYNCHRONOUS
UP/DOWN COUNTER
AIM:
To design and implement 3 bit synchronous up/down counter.
APPARATUS REQUIRED:
THEORY:
7
7
PROCEDURE:
(i) Connections are given as per circuit diagram.
RESULT:
7
STATE DIAGRAM:
CHARACTERISTIC TABLE:
Q Qt+1 J K
0 0 0 X
0 1 1 X
1 0 X 1
1 1 X 0
7
TRUTH TABLE:
Input Present State Next State A B C
Up/Down QA QB QC QA+1 Q B+1 QC+1 JA KA JB KB JC KC
0 0 0 0 1 1 1 1 X 1 X 1 X
0 1 1 1 1 1 0 X 0 X 0 X 1
0 1 1 0 1 0 1 X 0 X 1 1 X
0 1 0 1 1 0 0 X 0 0 X X 1
0 1 0 0 0 1 1 X 1 1 X 1 X
0 0 1 1 0 1 0 0 X X 0 X 1
0 0 1 0 0 0 1 0 X X 1 1 X
0 0 0 1 0 0 0 0 X 0 X X 1
1 0 0 0 0 0 1 0 X 0 X 1 X
1 0 0 1 0 1 0 0 X 1 X X 1
1 0 1 0 0 1 1 0 X X 0 1 X
1 0 1 1 1 0 0 1 X X 1 X 1
1 1 0 0 1 0 1 X 0 0 X 1 X
1 1 0 1 1 1 0 X 0 1 X X 1
1 1 1 0 1 1 1 X 0 X 0 1 X
1 1 1 1 0 0 0 X 1 X 1 X 1
K MAP
7
LOGIC DIAGRAM:
8
EXPT NO. :
DATE :
DESIGN AND IMPLEMENTATION OF SHIFT REGISTERS
AIM:
To design and implement
(i) Serial in serial out
(ii) Serial in parallel out
(iii) Parallel in serial out
(iv) Parallel in parallel out
APPARATUS REQUIRED:
THEORY:
8
PROCEDURE:
RESULT:
8
PIN DIAGRAM:
TRUTH TABLE:
Serial in Serial out
CLK
1 1 0
2 0 0
3 0 0
4 1 1
5 X 0
6 X 0
7 X 1
8
SERIAL IN PARALLEL OUT:
LOGIC DIAGRAM:
TRUTH TABLE:
OUTPUT
Q3 Q2 Q1 Q0
CLK DATA
1 1 1 0 0 0
2 0 0 1 0 0
3 0 0 0 1 0
4 1 1 0 0 1
PARALLEL IN SERIAL OUT:
LOGIC DIAGRAM:
8
TRUTH TABLE:
CLK D3 D2 D1 D0 OUTPUT
0 1 0 0 1 1
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 1
TRUTH TABLE:
DATA INPUT OUTPUT
D3 D2 D1 D0 Q3 Q2 Q1 Q0
CLK
1 1 0 0 1 1 0 0 1
2 1 0 1 0 1 0 1 0
8
EXPT NO. :
DATE :
Half-Adder
A combinational circuit that performs the arithmetic addition of two
bits is called a Half Adder. The input variables of a half adder are called
augend and addend bits. The output variables are called the sum and carry.
It is implemented by using AND and XOR gates.
Full-Adder
A combinational circuit that performs the arithmetic addition of three
bits is called a Full Adder. The input variables of a Full adder are called
augend and addend bits. The output variables are called the sum and carry.
It is implemented by using AND, OR and XOR gates.
input a;
input b;
output s;
output c;
xor(s,a,b);
and(c,a,b);
endmodule
module testbench();
reg a,b;
wire s,c;
ha test(a,b,s,c);
initial
begin
8
a=0;b=0;
#5 a=0;b=1;
#5 a=1; b=0;
#5 a=1;b=1;
#5 $finish;
end
endmodule
Output Waveform
Procedure
1. Xilinx ISE software environment is opened and a new project is
created.
8
6. The input binary values for test bench waveform are configured.
8. XILINX ISE simulates the verilog HDL program and displays the
output waveform.
input a;
input b;
input cin;
output sum;
output cout;
wire w1,w2,w3;
xor(w1,a,b);
xor(sum,w1,cin);
and(w2,a,b);
and(w3,w1,cin);
or(cout,w2,w3);
endmodule
8
RTL Schematic
8
Result:
Thus the program for Half adder and Full adder was written using
HDL and simulated successfully using XILINX 9.1i ISE simulator.
EXP NO.
4x1 MUX
Program:
module mux(y,s0,s1,i0,i1,i2,i3,clk);
input s0;
input s1;
input i0;
input i1;
input i2;
input i3;
output y;
begin
assign y=(i0 & ~s0 & ~s1 )|(i1 & ~s0 & s1 )|(i2 & s0 & ~s1 )|(i3 & s0 & s1 );
endmodule
module testbench();
reg s0,s1,i0, i1, i2, i3 ;
wire y;
mux a1(y, s0, s1, i0, i1, i2, i3);
initial
begin
s0=0;s1=0;i0=1;i1=0;i2=0;i3=0;
#10 s0=0;s1=1;i0=0;i1=1;i2=0;i3=0;
#10 s0=1;s1=0;i0=0;i1=0;i2=1;i3=0;
#10 s0=1;s1=1;i0=0;i1=0;i2=0;i3=1;
#10 $finish;
end
endmodule
9
RTL Schematic:
Waveform:
Result:
Thus a 4x1 MUX was implemented using structural simulation in Xilinx ISE.
9
EXP NO.
1X4 DEMUX
Program:
module demux(o1,o2,o3,o4,s0,s1,i,clk);
input i,s0,s1,clk;
output o1,o2,o3,o4;
assign o1=(s0 & s1 & i);
assign o2=(~s0 & s1 & i);
assign o3=(s0 & ~s1 & i);
assign o4=(~s0 & ~s1 & i);
end
assign o1=x1;
assign o2=x2;
assign o3=x3;
assign o4=x4;
endmodule
module testbench();
reg s0,s1,i;
wire o1,o2,o3,o4;
demux a1(o1,o2,o3,o4,s0,s1,i);
initial
begin
s0=0;s1=0;i=1;
#10 s0=0;s1=1;i=1;
#10 s0=1;s1=0;i=1;
#10 s0=1;s1=1;i=1;
end
endmodule
9
RTL Schematic:
Waveform:
Result:
Thus a 1X4 DEMUX was implemented using structural simulation in Xilinx ISE.
9
EXP NO.
Flip-Flops
Aim: To implement the following flip-flops using structural simulation in Xilinx ISE
1. T
2. D
T Flip-flop:
Program:
module tff(t,clk,q);
output q;
input t,clk;
reg q=0;
always@(posedge clk) begin
if (t==0)
q <= q;
else
q <= ~q;
end
endmodule
module testbench();
reg t,clk;
wire q;
tff test(t,clk,q);
initial
begin
$monitor($time,"t=%b,clk=%b,q=%b",t,clk,q);
end
initial
begin
clk=1'
forever #50 clk=~clk;
end
initial
begin
t=1
forever #500 t=~t;
end
endmodule
9
RTL Schematic:
Waveform:
D Flip-flop:
Program:
module DFF1(Q,D, CLK);
output Q;
input D;
input CLK;
reg Q;
always @(posedge CLK)
begin
Q <=D;
end
endmodule
module testbench();
reg D,CLK;
wire Q;
DFF1 one(Q,D,CLK);
initial
begin
$monitor ($time,"Q=%b,D=%b,CLK=%b", Q,D,CLK);
end
initial
begin
D=0;CLK=1;
9
#5 D=0;CLK=0;
#5 D=0;CLK=1;
#5 D=1;CLK=0;
#5 D=1;CLK=1;
#5 D=0;CLK=0;
#5 D=1;CLK=1;
#5 D=1;CLK=0;
#5 D=0;CLK=1;
#5 D=1;CLK=0;
#5 D=1;CLK=1;
$finish;
end
endmodule
RTL Schematic:
Waveform:
Result:
Thus the flip-flops were implemented using structural simulation in Xilinx ISE.
9
EXP NO.
2 bit counters
Aim: To implement the following counters using structural simulation in Xilinx ISE:
Program:
module counter(clk,c0);
input clk;
output [1:0]c0;
reg c0=0;
always @(posedge clk)
c0=c0+1;
endmodule
module testbench();
reg clk;
wire [1:0]c0;
counter c1(clk,c0);
initial
begin
clk=0;
forever #100 clk=~clk;
end
initial
begin
$monitor($time,"c0=%b,clk=%b",c0,clk);
end
endmodule
RTL Schematic:
9
Waveform:
Result:
Thus the counters were implemented using structural simulation in Xilinx ISE
9
Expt No.
Aim:
To Implement a serial in serial out shift register in Xilinx ISE
Program:
module taja(d,clk,q);
input d,clk;
output q;
reg [3:0]q1;
dff t1(d,clk,q1[0]);
dff t2(q[0],clk,q1[1]);
dff t3(q[1],clk,q1[2]);
dff t4(q[2],clk,q);
endmodule
module dff(d,clk,q);
input d,clk;
output q;
reg q=0;
always@(posedge clk)
begin
case(d)
0:q=0;
1:q=1;
endcase
end
endmodule
module testbench();
reg d,clk;
wire [3:0]q;
taja a1(d,clk,q);
initial
begin
clk=1;
forever #10
clk=~clk;
end
initial
begin
d=1;
#20 d=0;
#20 d=1;
9
#20 d=0;
#200 $finish;
end
endmodule
Result:
Thus a serial in serial out shift register was implemented in Xilinx ISE