Coa Lab
Coa Lab
a) AND Gate: A Logic circuit whose output is logic ‘1’ if and only if all of its inputs
are logic ‘1’.
Truth table Logic diagram
Inputs Output
A B Y A
Y
0 0 0 B
0 1 0
1 0 0 AND2
1 1 1
Y = A AND B
= A.B
-- File : [Link]
-- Entity : andgate
y
b) OR Gate: A logic gate whose output is logic ‘0’ if and only if all of its inputs are
logic ‘0’.
Truth table Logic diagram
Inputs Output
A 2
A B Y 1 Y
0 0 0 B 3
0 1 1
1 0 1 OR2
1 1 1
Y = A OR B
=A+B
VHDL Code for OR Gate:
-- File : [Link]
-- Entity : orgate
y
c) NOT Gate: A logic gate whose input is complement of its input.
Input Output
A Y
0 1
1 0 INV
Y = NOT A
-- File : [Link]
-- Entity : notgate
y
d) NAND Gate: A logic gate which gives logic ‘0’ output if and only if all of its
inputs are logic ‘1’
Truth table Logic diagram
Inputs Output
A B Y 2
1
0 0 0 3
0 1 1
1 0 1 NAND2
1 1 1
Y= A NAND B
=(A. B)\
-- File : [Link]
-- Entity : nandgate
y
e) NOR Gate: A logic gate whose output logic ‘1’ if and only if all of its inputs are
logic ‘0’
Truth table Logic diagram
Inputs Output
A B Y 2
0 0 0 1
0 1 1 3
1 0 1
NOR2
1 1 1
Y= A NOR B
=(A+ B)\
-- File : [Link]
-- Entity : norgate
y
f) EX-OR (Exclusive OR): A logic gate whose output is logic ‘0’ when all the inputs
are equal and logic ‘1’ when they are un equal.
Truth table Logic diagram
Inputs Output
A B Y 2
0 0 0 1
0 1 1 3
1 0 1
XOR2
1 1 0
Y= A EX-OR B
= A (+)B
= A.B\ + A\.B
-- File : [Link]
-- Entity : xorgate
Entity Declarations
entity xorgate is
Port( A : in std_logic;
B : in std_logic;
Y : out std_logic
);
end xorgate;
200 400 600 800 1000 1200 1400 1600 1800 2000 2200 ns
y
g) EX-NOR (Exclusive -NOR) gate: A logic gate that prodices a logic ‘1’ only when
the two inputs are equal
Truth table Logic diagram
Inputs Output
A B Y 2
0 0 0 1
0 1 1 3
1 0 1
1 1 0 XNOR2
Y= A XNOR B
= (A (+)B)\
= (A.B)\ + A.B
-- File : [Link]
-- Entity : xnorgate
a
b
y
Experiment 2: Write a VHDL program for the following combinational designs.
a) 2 to 4 decoder: A decoder is a digital logic circuit that converts n-bits binary input
code in to M output lines. OR It is a logic circuit that decodes from binary to octal,
decimal, Hexa-decimal or any other code such as 7-segment etc.
EN SEL(1) SEL(0)
INST1 INST2
INV INV
U5
2
3
4
1 D0
NAND3
U6
2
3
4
1 D1
NAND3
U8
2
3
4
1 D3
NAND3
-- Description : 2 to 4 DECODER
end process;
end decoder24_arch;
Simulator Waveforms for 2:4 Decoder:
500 10 0 0 15 0 0 2000 2500 ns
EN
SEL 0 1 2 3 0 1 2 3 0 1 2
D (3 )
D (2 )
D (1 )
D (0 )
b) 8 to 3 (Encoder without & with priority)
Encoder: A logic circuit that produces coded binary outputs from uncoded inputs.
Priority encoder: Whenever two or more inputs are applied at a time, internal
hardware will check this condition and if the priority is set such that higher numbered
input should be taken into account and remaining are considered as don’t care then
output code will be appear will be “higher numbered input”.
E
x 05 0A 0F 14 19 1E 23 28 2D 32
x(7)
x(6)
x(5)
x(4)
x(3)
x(2)
x(1)
x(0)
y 2 3 4 5
y(2)
y(1)
y(0)
A
c) 8 :1 Multiplexer: The multiplexer is a combinational circuit which accepts several data
inputs and allows only one of them AT A TIME to get through to the output.
EN SEL(2) SEL(1) SEL(0)
ENABLE INV1
INV3 INV2
2 U1
3
4 1
5
D0 D0 6
AND5
2 U2
D1 0 EN 3
4 1
5
1 D1 6
D2
AND5
2 U3
2 3
D3 3
4
D2 5
6
4 1
Inputs 5 Y
8:1
4 1 3
D5 67
D3
5
6
AND5
4
5
6
1 Y
D6 4
2 U5
1 9
D4 3
D7 5 7
6
AND5 8
OR8
2 U6
3
54 1
D5 6
AND5
2 U7
3
SEL0 D6
4
5
6
AND5
1
SEL1 5
2 U8
3
4 1
D7
SEL2 6
AND5
Control Inputs
Block Diagram of 8:1 Mux Logic Diagram
-- Description : 8 TO 1 MULTIPLEXOR
end mux8_1_arch;
Simulator Waveforms for 8:1 Multiplexer:
D(7)
D(6)
D(5)
D(4)
D(3)
D(2)
D(1)
D(0)
EN
SEL 0 1 2 3 4 5 6 7
Y
d) Multiplexer, Demultiplexer, comparator.
ENABLE
0 D0 D0
EN 1 D1 Y
2 D2 D1
3 D3
Data Input O/P 1:8
D2
Demux 4 D4
Y
5 D5 D3
6 D6
7 D7 D4
D5
Data Outputs
SEL0
D6
SEL1
SEL2 D7
Control Input
Block Diagram of 1:8 Demux Logic Diagram
Truth Table
EN CONTROL INPUTS OUTPUTS
SEL(3) SEL(3) SEL(3)
0 X X X 0
1 0 0 0 D0=Y
1 0 0 1 D1=Y
1 0 1 0 D2=Y
1 0 1 1 D3=Y
1 1 0 0 D4=Y
1 1 0 1 D5=Y
1 1 1 0 D6=Y
1 1 1 1 D7=Y
-- File : [Link]
-- Entity : demux
end demux8_1_arch;
Simulator Waveforms for 1: Demultiplexer:
EN
SEL 0 1 2 3 4 5 6 7
D 00 02 0A 2A A
D(7)
D(6)
D(5)
D(4)
D(3)
D(2)
D(1)
D(0)
Comparator: A circuit that compares two numbers and produces an output
indicating whether they are equal. It may also indicate which number is greater if they
are unequal. Ex: ‘1’ bit comparator
Truth table:
Comparing Outputs
inputs
A B Y=(A>B) Y=(A<B) Y=(A=B)
0 0 0 0 1
0 1 0 1 0
1 0 1 0 0
1 1 0 0 1
A 2
U1
AB\
3
1 Y(A<B)
INV1
AND2
U3
2
3
1 Y(A=B)
NOR2
U2
2
B 3
1 Y(A>B)
AND2 A\B
INV2
-- File : [Link]
-- Entity : bitcomp
end bitcomp_arch;
Simulator Waveforms for SINGLE BIT MAGNITUDE
COMPARATOR:
500 1000 1500 2000 2500 3000 3500 ns
sel 0 1 2 3 0
Truth table for Full adder Truth table for Half adder
AND2 OR3
U4
2
1 A.B + [Link] + [Link]
3
AND2
-- File : [Link]
-- Entity : HA
-- Architecture : HA_arch
entity HA is
port(
A,B : in STD_LOGIC;
S,CY : out STD_LOGIC
);
end HA;
architecture HA_arch of HA is
begin
S<= A XOR B;
CY<= A AND B;
end HA_arch;
VHDL Code for FULL ADDER
-- File : [Link]
-- Entity : FA
-- Architecture : FA_arch
architecture STRUCTURAL of FA is
signal sum1,cy1,cy2:std_logic;
component HA
port(
A,B : in STD_LOGIC;
S,CY : out STD_LOGIC
);
end component ;
begin
u1: HA port map(A=>A, B=>B, S=>SUM1, CY=>CY1);
u2: HA port map(A=>SUM1, B=>Cin, S=>SUM, CY=>CY2);
end STRUCTURAL;
-- DATAFLOW MODELING-A set of concurrent assignment statements.
architecture DATAFLOW of FA is
begin
SUM<= A XOR B XOR Cin;
CARRY<= (A AND B) OR (Cin AND A)OR (Cin AND B);
end DATAFLOW;
architecture BEHAVIOR of FA is
begin
process(A,B,Cin)
begin
SUM<= A XOR B XOR Cin;
CARRY<= (A AND B) OR (Cin AND A)OR (Cin AND B);
end process;
end BEHAVIOR;
Simulator waveforms of HALF ADDER
1 2 3 4 5 6 7 8 9 us
SUM
CARRY
Cin
SUM
CARRY
Experiment 4: Write a model for 32 bit ALU using the schematic diagram
Shown below example
➢ ALU should use the combinational logic to calculate an output based on the four
bit Opcode input.
➢ ALU should pass the result to the out bit when enable line is high and tri-state
when low enable.
➢ ALU should decode the 4-bit op-code according to the given in example below
Opcode ALU operation
1 A+B
2 A–B
3 A Complement
4 A*B
5 A AND B
6 A OR B
7 A NAND B
8 A XOR B
ALU is logic circuit which is able to perform different arithmetic and logical
function basically ALU is the heart of central processing unit (CPU).
Mode
Note: For A*B, A&B lower 16 bit [15:0] can be taken in to consideration.
VHDL Code for 8_bit ALU:
-- File : [Link]
-- Entity : alu
entity Alu is
port( Clk : in Std_Logic;
MODE,EN: in Std_Logic;
A,B : in Std_Logic_Vector(7 downto 0);
OPCODE : in Std_Logic_Vector(3 downto 0);
Y : out Std_Logic_Vector(7 downto 0));
end Alu;
process
begin
wait until Clk'event and Clk = '1';
y <= Std_Logic_Vector(C_s);
end process ;
end Alu_a;
Clk
MODE
EN
A 08
B 04
OPCODE 0 1 2 3 4 3 6 A D
4 5 7 8 9 B C
Y UU 04 2 00 F7 FB 00 F 0C F3 0C F3 00
0 F