DE - Unit 2
DE - Unit 2
10211CS201-DIGITAL ELECTRONICS
Category : Program Core
UNIT-II
Course Handling Faculty :
Dr.P.Rajalakshmi
27-08-2024
Asst. Professor 1
• Logic circuits for digital systems may be combinational or
sequential.
• A combinational circuit consists of input variables, logic
gates, and output variables.
27-08-2024 2
Half Adder
• A combinational circuit that performs the addition of two bits is C: Carry
called a half adder.
• The truth table for the half adder is y y y
S: Sum x 0 1
C: Carry x y C S
0 0
0 0 0 0 x 0 0 1
xy
0 1 0 1 x 1 0
2
1
3
1 0 0 1 S: Sum
y y y
x 1
1 1 1 0 0
0 1
x 0 0 1
xy
S = x’y + xy’
x 1 1
2
0
3
27-08-2024 C = xy
3 xy
Implementation of Half-Adder
x’y + xy’ = s
xy = c
S = x’y + xy’ ➔ x⊕ y
C = xy
27-08-2024 4
Full Adder
• A combinational circuit that performs the addition of three bits is
called a full adder.
• The truth table for the full adder is yz yz
yz yz
C yz
x y S x 01 10
00 11
m0 m1 m3 m2
x 0 0 1 3 2
S: Sum x 1 m4
4
m5
5
m7
7
m6
6
C: Carry 5
yz
x 00 yz 01 y z 11 yz 10 yz
m0 m1 m3 m2
0
x 0 1 3 2
27-08-2024
x 1 m4
4
m5
5
m7
7
m6
6
Full-Adder
• One that performs the addition of three bits(two
significant bits and a previous carry) is a full adder.
27-08-2024 6
Simplified Expressions
27-08-2024 7
Full Adder implementation
• Full-adder can also implemented with two half adders and
one OR gate (Carry Look-Ahead adder).
S = z ⊕ (x ⊕ y)
= z’(xy’ + x’y) + z(xy’ + x’y)’
= xy’z’ + x’yz’ + xyz + x’y’z
C = z(xy’ + x’y) + xy = xy’z + x’yz + xy
27-08-2024 8
Magnitude comparator
• The equality relation of each pair
of bits can be expressed logically
with an exclusive-NOR function as:
A = A3A2A1A0 ; B = B3B2B1B0
xi=AiBi+Ai’Bi’ for i = 0, 1, 2, 3
(A = B) = x3x2x1x0
27-08-2024 9
Magnitude comparator
• We inspect the relative magnitudes
of pairs of MSB. If equal, we
compare the next lower significant
pair of digits until a pair of unequal
digits is reached.
(A>B)=
A3B’3+x3A2B’2+x3x2A1B’1+x3x2x1A0B’0
(A<B)=
A’3B3+x3A’2B2+x3x2A’1B1+x3x2x1A’0B0
27-08-2024 10
Decoders
• The decoder is called n-to-m-line decoder, where m≤2n .
• 3-to-8 line decoder: For each possible input combination, there are
seven outputs that are equal to 0 and only one that is equal to 1.
27-08-2024 11
Implementation and truth table
27-08-2024 12
Decoder with enable input
• Some decoders are constructed with NAND gates, it becomes more
economical to generate the decoder minterms in their
complemented form.
• As indicated by the truth table , only one output can be equal to 0
at any given time, all other outputs are equal to 1.
27-08-2024 13
Demultiplexer
• A decoder with an enable input is referred to as a
decoder/demultiplexer.
• The truth table of demultiplexer is the same with decoder.
A B
D0
Demultiplexer D1
E
D2
D3
27-08-2024 14
Encoders
• An encoder is the inverse operation of a decoder.
• We can derive the Boolean functions by table
z = D 1 + D 3 + D 5 + D7
y = D 2 + D3 + D 6 + D 7
x = D 4 + D5 + D 6 + D 7
27-08-2024 15
Priority encoder
• If two inputs are active simultaneously, the output produces an undefined
combination. We can establish an input priority to ensure that only one input is
encoded.
• Another ambiguity in the octal-to-binary encoder is that an output with all 0’s is
generated when all the inputs are 0; the output is the same as when D0 is equal
to 1.
• The discrepancy tables can resolve aforesaid condition by providing one more
output to indicate that at least one input is equal to 1.
27-08-2024 16
Priority encoder
V=0→no valid inputs
V=1→valid inputs
27-08-2024 17
4-input priority encoder
0
• Implementation of 0
table 0
0
x = D2 + D3
y = D3 + D1D’2
V = D 0 + D 1 + D2 + D 3
27-08-2024 18
Multiplexers
S = 0, Y = I0 Truth Table→ S Y Y = S’I0 + SI1
S = 1, Y = I1 0 I0
1 I1
27-08-2024 19
4-to-1 Line Multiplexer
27-08-2024 20
Boolean function implementation
• A more efficient method for implementing a Boolean function of n
variables with a multiplexer that has n-1 selection inputs.
F(x, y, z) = (1,2,6,7)
27-08-2024 21
4-input function with a multiplexer
F(A, B, C, D) = (1, 3, 4, 11, 12, 13, 14, 15)
27-08-2024 22
Code Conversion
Code-Conversion example, first, we can list the relation of
the BCD and Excess-3 codes in the truth table.
27-08-2024 23
Karnaugh map
For each symbol of the Excess-3 code, we use 1’s to draw
the map for simplifying Boolean function.
27-08-2024 24
Circuit implementation
z = D’; y = CD + C’D’ = CD + (C + D)’
x = B’C + B’D + BC’D’ = B’(C + D) + B(C + D)’
w = A + BC + BD = A + B(C + D)
27-08-2024 25
Describing a Design
In VHDL an entity is used to describe a hardware module. An entity can be
described using,
• Entity declaration
• Architecture
• Configuration
• Package declaration
• Package body
27-08-2024 26
VHDL Introduction
• VHDL stands for very high-speed integrated circuit hardware description
language.
• This language was first introduced in 1981 for the department of Defense
(DoD) under the VHSIC program.
27-08-2024 27
Entity Declaration
Syntax −
entity entity_name is
Port declaration;
end entity_name;
An entity declaration should start with ‘entity’ and end with ‘end’ keywords. The
direction will be input, output or inout.
27-08-2024 28
Architecture
• Architecture − Architecture can be described using structural, dataflow,
behavioral or mixed style.
Syntax −
27-08-2024 29
Data Flow Modeling
• In this modeling style, the flow of data through the entity is expressed using
concurrent (parallel) signal.
Operators
The WHEN statement (WHEN/ELSE or WITH/SELECT/WHEN);
The GENERATE statement;
The BLOCK statement
27-08-2024 30
Behavioral Modeling
• In this modeling style, the behavior of an entity as set of statements is executed
sequentially in the specified order.
27-08-2024 31
Structural Modelling
27-08-2024 32
Logic Operation – AND GATE
• VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity and1 is
port(x,y:in bit ; z:out bit);
end and1;
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity or1 is
port(x,y:in bit ; z:out bit);
end or1;
27-08-2024 34
Logic Operation – NOT Gate
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity not1 is
port(x:in bit ; y:out bit);
end not1;
27-08- 36
2024
• Using Structural Architecture:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_AIS
PORT (A, B: IN STD_LOGIC; S, C: OUT STD_LOGIC);
END H_A;
BEGIN
X1: XOR2 PORT MAP (A,B,S);
X2: AND2 PORT MAP (A,B,C);
END HA_STR;
27-08- 37
2024
• Using Data Flow Architecture:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_A IS
PORT (A, B: IN STD_LOGIC; S, C: OUT
STD_LOGIC); END H_A;
27-08- 38
2024
• Using Behavioural Modeling
ENTITY H_A IS PORT(A, B: IN BIT;
S, C: OUT BIT); END H_A;
ENDIF;
END PROCESS; END BEHAVE_HA;
27-08- 39
2024
• Using Data Flow Architecture with selected signal
assignment:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_AIS
PORT (A, B: IN STD_LOGIC; S, C: OUT STD_LOGIC); END H_A;
27-08- 40
2024
Examples of VHDL Code
• Arithmetic Circuits in VHDL:
– Consider the half subtractorcircuit
27-08- 41
2024
• Using Structural Architecture:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_S IS
PORT (A, B: IN STD_LOGIC; DIFF, BORROW: OUT STD_LOGIC);
END H_S;
27-08- 42
2024
• Using Data Flow Architecture:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_S IS
PORT (A, B: IN STD_LOGIC; DIFF, BORROW: OUT STD_LOGIC); END
H_S;
27-08- 43
2024
• Using Behavioural Modeling
ENDIF;
END PROCESS; END BEHAVE_HS;
27-08- 44
2024
• Using Data Flow Architecture with selected
signal assignment:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_S IS
PORT (A, B: IN STD_LOGIC; DIFF, BORROW: OUT STD_LOGIC); END H_S;
27-08- 46
2024
• Using CASE statement
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY MUX IS
PORT( I3: IN STD_LOGIC_VECTOR(1 DOWNTO 0); I2: IN
STD_LOGIC_VECTOR(1 DOWNTO 0); I1: IN
STD_LOGIC_VECTOR(1 DOWNTO 0); I0: IN
STD_LOGIC_VECTOR(1 DOWNTO 0); S:IN
STD_LOGIC_VECTOR(1 DOWNTO 0); O:OUT
STD_LOGIC_VECTOR(1 DOWNTO 0));
END MUX;
27-08- 47
2024
Examples of VHDL Code
• Decoder in VHDL:
– Consider the 2:4 decodercircuit
27-08- 48
2024
• Using Sequential Architecture model
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DECODER24 IS
PORT( A, B, EN:IN STD_LOGIC;
Z:OUT STD_LOGIC_VECTOR(0 TO 3));
END DECODER24;
ENTITY DECODER24 IS
PORT( A, B, EN:INSTD_LOGIC;
Z:OUT STD_LOGIC_VECTOR(0 to 3));
END DECODER24;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DECODER24 IS
PORT( A, B, EN:INSTD_LOGIC;
Z:OUT STD_LOGIC_VECTOR(0 TO 3)); END
DECODER24;
27-08- 51
2024
Examples of VHDL Code
• Priority Encoder in VHDL:
– Consider the Decimal to BCD Priority Encoder circuit
27-08- 52
2024
• Using Conditional Signal AssignmentStatement
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY PRIORITY_ENCODER IS
PORT( I : IN STD_LOGIC_VECTOR(9 DOWN TO 0);
Y : OUT STD_LOGIC_VECTOR(3 DOWN TO 0) ); END
PRIORITY_ENCODER;
27-08- 53
2024
• Using Sequential Signal Statement
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY PRIORITY_ENCODER IS
PORT( I : IN STD_LOGIC_VECTOR(9 DOWN TO0);
Y : OUT STD_LOGIC_VECTOR(3 DOWN TO 0) );
END PRIORITY_ENCODER;
27-08- 54
2024
Examples of VHDL Code
• Comparator in VHDL:
27-08- 55
2024
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY COMPARATOR IS
PORT( A, B : IN STD_LOGIC_VECTOR(1 DOWN
TO 0); AGTB, AEQB, ALTBY : OUT
STD_LOGIC);
END COMPARATOR;
27-08- 56
2024
Examples of VHDL Code
• BCD to 7-Segment Decoder in VHDL:
27-08- 57
2024
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DEC_7_SEG IS
PORT( BCD : IN STD_LOGIC_VECTOR(3 DOWN TO 0);
LED7 : OUT STD_LOGIC_VECTOR(1 TO 7));
END DEC_7_SEG;
27-08- 58
2024