DSD Book
DSD Book
DSD Book
Solution :
Circuit diagram of 2-to-4 Decoder is shown in figures 11.1, waveforms
are shown in figure 11.2 and truth table is shown in Table 11.1.
S0 S1
I0 I1
EN
A0 Z(0)
A1 Z(1)
A2 Z(2)
A3 Z(3)
Input’s Output’s
EN S1 S0 Z(0) Z(1) Z(2) Z(3)
0 X X 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1
Table 11.1 Truth table of 2-to-4 Decoder
226
Unit-9 Digital Design
ENTITY decoder_2_to_4 IS
port(s0,s1,en:in bit; z:out bit_vector(0 to 3));
END decoder_2_to_4;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY decoder_2_to_4 IS
port(s0,s1,en:in bit; z:out bit_vector(0 to 3));
END decoder_2_to_4;
227
Unit-9 Digital Design
END decoder_2_to_4_dataflow;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY decoder_2_to_4 IS
port(s0,s1,en:in bit; z:out bit_vector(0 to 3));
END decoder_2_to_4;
--
ARCHITECTURE decoder_2_to_4_structural OF decoder_2_to_4 IS
component and3
port(in1,in2,in3:in bit; out1:out bit);
end component;
component inv
port(in4:in bit; out2:out bit);
end component;
signal s0bar,s1bar:bit;
BEGIN
Example 11.2
For a Full Adder write down
(a) Behavior Model
228
Unit-9 Digital Design
Solution :
Circuit diagram of Full Adder is shown in figures 11.3, waveforms are
shown in figure 11.4 and truth table is shown in Table 11.2.
A
B X0 S
Cin
A0
A1 O0 C
A2
Input’s Output’s
A B Cin S C
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
229
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY full_adder IS
port(a,b,cin:in bit; s,c:out bit);
END full_adder;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY full_adder IS
port(a,b,cin:in bit; s,c:out bit);
END full_adder;
--
ARCHITECTURE full_adder_dataflow OF full_adder IS
BEGIN
s<=a xor b xor cin;
c<=(a and b)or(a and cin)or(b and cin);
END full_adder_dataflow;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
230
Unit-9 Digital Design
USE ieee.std_logic_arith.all;
ENTITY full_adder IS
port(a,b,cin:in bit; s,c:out bit);
END full_adder;
--
ARCHITECTURE full_adder_structure OF full_adder IS
component xor3
port(in1,in2,in3:in bit; out1:out bit);
end component;
component and2
port(in4,in5:in bit; out2:out bit);
end component;
component or3
port(in6,in7,in8:in bit; out3:out bit);
end component;
signal x,y,z:bit;
begin
x0:xor3 port map(a,b,cin,s);
a0:and2 port map(a,b,x);
a1:and2 port map(b,cin,y);
a2:and2 port map(a,cin,z);
o0:or3 port map(x,y,z,c);
END full_adder_structure;
Example 11.3
For a Multiplexer of size 4-to-1 write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Circuit diagram of 4-to-1 Multiplexer is shown in figures 11.5,
waveforms are shown in figure 11.6 and truth table is shown in Table
11.3.
231
Unit-9 Digital Design
S0 S1
I0 I1
S0 BAR S1 BAR
10 U
A0
11 A1 V
O0
12 A2 W
13 X
A3
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY mux_4to1 IS
port(i0,i1,i2,i3,s0,s1:in bit; y:out bit);
END mux_4to1;
232
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY mux_4to1 IS
port(i0,i1,i2,i3,s0,s1:in bit; y:out bit);
END mux_4to1;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY mux IS
port(i0,i1,i2,i3,s0,s1:in bit; y:out bit);
233
Unit-9 Digital Design
END mux;
component or4
port(in4,in5,in6,in7:in bit; out2:out bit);
end component;
signal s0bar,s1bar,u,v,w,x:bit;
BEGIN
Example 11.4
For a BCD-to-Seven Segment Decoder write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Circuit diagram of BCD-to-Seven Segment Decoder is shown in figures
11.7, waveforms are shown in figure 11.8 and truth table is shown in
Table 11.4.
234
Unit-9 Digital Design
a
A
b
B c
a
d
BCD-to-Seven
C Segment Decoder f b
e
f g
D e c
g
d
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
235
Unit-9 Digital Design
ENTITY seven_seg_decoder IS
port(bcd:in bit_vector(0 to 3); led:out bit_vector(0 to 6));
END seven_seg_decoder;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
236
Unit-9 Digital Design
ENTITY seven_seg_decoder IS
port(bcd:in bit_vector(0 to 3); led:out bit_vector(0 to 6));
END seven_seg_decoder;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY seven_seg_decoder IS
port(bcd:in bit_vector(0 to 3); led:out bit_vector(0 to 6));
END seven_seg_decoder;
--
ARCHITECTURE seven_structure OF seven_seg_decoder IS
Component decoder
Port(input:in bit_vector(0 to 3); output:out bit_vector(0 to 6));
End component;
Begin
Dec1:decoder port map(bcd,led);
END seven_structure;
237
Unit-9 Digital Design
Example 11.5
For a 4-bit Parallel in Parallel Out Register write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Block diagram of 4-bit Parallel in Parallel out Register is shown in
figures 11.9 and waveforms are shown in figure 11.10.
Parallel Input's
PR
D Q D Q D Q D Q
CR
Parallel Output's
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY pipo IS
port(d:in bit_vector(0 to 3);clk,pr,cr:in bit; q:out bit_vector(0 to 3));
END pipo;
238
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY pipo IS
port(d:in bit_vector(0 to 3); pr,cr,clk:in bit; q:out bit_vector(0 to 3));
END pipo;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY pipo IS
239
Unit-9 Digital Design
--in1=d,in2=pr,in3=cr,in4=clk,out1=q
BEGIN
d0:dff port map(d(0),pr,cr,clk,q(0));
d1:dff port map(d(1),pr,cr,clk,q(1));
d2:dff port map(d(2),pr,cr,clk,q(2));
d3:dff port map(d(3),pr,cr,clk,q(3));
END pipo_structure;
Example 11.6
For a 4-bit Serial In Serial Out Register write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Block diagram of 4-bit Serial in Serial out Register is shown in figures
11.11 and waveforms are shown in figure 11.12.
PR
CLK
CR
Z(O/P)
240
Unit-9 Digital Design
ENTITY siso IS
port(d,clk,pr,cr:in bit; z:out bit);
END siso;
241
Unit-9 Digital Design
ENTITY siso IS
port(pr,cr,clk,d:in bit; z:out bit);
END siso;
ENTITY siso IS
port(d,clk,pr,cr:in bit; z:out bit);
END siso;
--in1=d,in2=pr,in3=cr,in4=clk,out1=q
signal q:bit_vector(0 to 2);
BEGIN
d0:dff port map(d,pr,cr,clk,q(0));
d1:dff port map(q(0),pr,cr,clk,q(1));
d2:dff port map(q(1),pr,cr,clk,q(2));
d3:dff port map(q(2),pr,cr,clk,z);
END siso_structure;
242
Unit-9 Digital Design
Example11.7
For a 4-bit Serial In Parallel Out Register write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Block diagram of 4-bit Serial in Parallel out Register is shown in figures
11.13 and waveforms are shown in figure 11.14.
PR
D D D D
D
Q Q Q
(serial i/p) Q
CR
Parallel Output's
Figure 11.13 Block Diagram o[f 4-bit Serial In Parallel Out Register
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY sipo IS
port(d,pr,cr,clk:in bit; q:buffer bit_vector(0 to 3));
END sipo;
--
243
Unit-9 Digital Design
END sipo_behavioural;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY sipo IS
port(d,pr,cr,clk:in bit; q:buffer bit_vector(0 to 3));
END sipo;
--
244
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY sipo IS
port(d,clk,pr,cr:in bit; q:buffer bit_vector(0 to 3));
END sipo;
--in1=d,in2=pr,in3=cr,in4=clk,out1=q
BEGIN
END sipo_structure;
Example 11.8
For a 3-bit UP Counter write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
245
Unit-9 Digital Design
Solution :
Block diagram of 3-bit UP Counter is shown in figures 11.15 and
waveforms are shown in figure 11.16.
PR
T Q T Q T Q
CR
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter IS
port(pr,cr,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter;
--
ARCHITECTURE behaviour OF counter IS
function "+"(a,b:bit_vector(0 to 2))return bit_vector is
variable cout:bit;
variable cin:bit:='0';
246
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_up IS
port(pr,cr,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_up;
--
ARCHITECTURE dataflow OF counter_up IS
-- function for addition of two bit arrays
function "+"(a,b:bit_vector(0 to 2))return bit_vector is
variable cout:bit;
variable cin:bit:='0';
variable sum:bit_vector(0 to 2):="000";
begin
for i in 0 to 2 loop
247
Unit-9 Digital Design
BEGIN
end dataflow;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_up IS
port(pr,cr,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_up;
--
ARCHITECTURE counter_up_structure OF counter_up IS
component tff
port(in1,in2,in3,in4:in bit; out1:inout bit);
end component;
BEGIN
ff0:tff port map(t,clk,pr,cr,q(0));
ff1:tff port map(t,q(0),pr,cr,q(1));
ff2:tff port map(t,q(1),pr,cr,q(2));
END counter_up_structure;
Example 11.9
For a 3-bit DOWN Counter write down
(a) Behavior Model
248
Unit-9 Digital Design
Solution :
Block diagram of 3-bit DOWN Counter is shown in figures 11.17 and
waveforms are shown in figure 11.18.
PR
T Q T Q T Q
S1 S2
FF0 FF1 FF2
CLK
Q Q Q
CR
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_down IS
port(pr,cr,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_down;
--
ARCHITECTURE behaviour OF counter_down IS
249
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_down IS
port(pr,cr,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_down;
--
ARCHITECTURE dataflow OF counter_down IS
250
Unit-9 Digital Design
BEGIN
S1<=not q(0);
S2<=not q(1);
q<="111" when(pr='0' and cr='1')else
"000" when(pr='1' and cr='0')else
q - "100"when(pr='1' and cr='1'and clk='0' and clk'event);
end dataflow;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_down IS
port(t,clk,pr,cr:in bit; q:out bit_vector(0 to 2));
END counter_down;
--
ARCHITECTURE counter_down_structure OF counter_down IS
component tff
port(in1,in2,in3,in4:in bit; z,zbar:buffer bit);
end component;
signal s1,s2:bit;
BEGIN
t0:tff port map(t,clk,pr,cr,q(0),s1);
251
Unit-9 Digital Design
Example 11.10
For a 3-bit UP/DOWN Counter write down
(a) Behavior Model
(b) Dataflow Model
(c) Structural Model
Solution :
Block diagram of 3-bit DOWN Counter is shown in figures 11.19 and
waveforms are shown in figure 11.20.
T
UP
PR
A1 S3 A3 S7
T Q T Q T Q
CR
DOWN
LIBRARY ieee;
252
Unit-9 Digital Design
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_updown IS
port(pr,cr,up,dn,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_updown;
--
ARCHITECTURE behaviour OF counter_updown IS
-- function for addition of two bit arrays
function "+"(a,b:bit_vector(0 to 2))return bit_vector is
variable cout:bit;
variable cin:bit:='0';
variable sum:bit_vector(0 to 2):="000";
begin
for i in 0 to 2 loop
cout:=(a(i) and b(i)) or (b(i) and cin) or (a(i) and cin);
sum(i):=a(i) xor b(i) xor cin;
cin:=cout;
end loop;
return sum;
end "+";
BEGIN
process(clk,pr,cr)
variable s1,s2,s3,s4,s5,s6,s7,s8:bit;
begin
s1:=not q(0);
253
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_updown IS
port(pr,cr,up,dn,clk,t:in bit; q:inout bit_vector(0 to 2));
END counter_updown;
--
ARCHITECTURE dataflow OF counter_updown IS
-- function for addition of two bit arrays
function "+"(a,b:bit_vector(0 to 2))return bit_vector is
variable cout:bit;
variable cin:bit:='0';
variable sum:bit_vector(0 to 2):="000";
begin
for i in 0 to 2 loop
254
Unit-9 Digital Design
signal s1,s2,s3,s4,s5,s6,s7,s8:bit;
BEGIN
begin
s1<=not q(0);
s2<=up and q(0);
s3<=s1 and dn;
s4<=s2 or s3;
s5<=not q(1);
s6<=up and q(1);
s7<=s5 and dn;
s8<=s6 or s7;
255
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY counter_up_down IS
port(t,clk,pr,cr,up,dn:in bit; q:buffer bit_vector(0 to 2));
END counter_up_down;
ARCHARCHITECTURE counter_up_down_structure OF
counter_up_down ISITECTURE counter_up_down_structure OF
counter_up_down IS
component tff
port(in1,in2,in3,in4:in bit; z,zbar:buffer bit);
end component;
component and2
port(in5,in6:in bit; out1:out bit);
end component;
component or2
port(in7,in8:in bit; out2:out bit);
end component;
signal s1,s2,s3,s4,s5,s6,s7,s8:bit;
BEGIN
t0:tff port map(t,clk,pr,cr,q(0),s1);
t1:tff port map(t,s4,pr,cr,q(1),s5);
t2:tff port map(t,s8,pr,cr,q(2),open);
a0:and2 port map(s1,dn,s2);
a1:and2 port map(q(0),up,s3);
a2:and2 port map(s5,dn,s6);
a3:and2 port map(q(1),up,s7);
or0:or2 port map(s2,s3,s4);
or1:or2 port map(s6,s7,s8);
END counter_up_down_structure;
256
Unit-9 Digital Design
Example 11.11
For a ALU(74381) write down Behavior Model.
Solution :
Block diagram of a ALU (74381) is shown in figures 11.21, waveforms
are shown in figure 11.22 and Function table is shown in Table 11.5.
P(3)
P(2)
P Input
(4-bit) P(1)
P(0) F(3)
ALU
F(2) F Output
74381
F(1) (4-bit)
Q(3)
F(0)
Q(2)
Q Input
Q(1)
(4-bit)
Q(0)
S2 S1 S0
257
Unit-9 Digital Design
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY alu IS
port(p,q:in bit_vector(0 to 3); s:in bit_vector(0 to 2); f:out bit_vector(0
to 3));
END alu;
--
ARCHITECTURE behavior OF alu IS
-- function for addition of two bit arrays
function "+"(a,b:bit_vector(0 to 3))return bit_vector is
variable cout:bit;
variable cin:bit:='0';
variable sum:bit_vector(0 to 3):="0000";
begin
for i in 0 to 3 loop
cout:=(a(i) and b(i)) or (b(i) and cin) or (a(i) and cin);
sum(i):=a(i) xor b(i) xor cin;
cin:=cout;
end loop;
return sum;
end "+";
begin
258
Unit-9 Digital Design
process(p,q,s)
begin
case s is
when "000"=>
f<="0000";
when "001"=>
f<= q - p ;
when "010"=>
f<= p - q ;
when "011"=>
f<= p + q ;
when "100"=>
f<=p xor q;
when "101"=>
f<=p or q;
when "110"=>
f<=p and q;
when"111"=>
f<="1111";
end case;
end process;
END behavior;
Example 11.12
For a D flip-flop write down Behavior Model.
Solution :
A D flip flop is shown in figures 11.23, waveforms are shown in figure
11.24 and Truth table is shown in Table 11.6.
259
Unit-9 Digital Design
PR
Input D Q Q
FF
Clk
CR
PR CR D(i/p) Output
Q(t + 1)
0 0 X 1
0 1 X 1
1 0 X 0
1 1 0 0
1 1 1 1
Table 11.6 Truth table of D flip-flop
ENTITY dff IS
port(clk,pr,cr,d:in bit; q:out bit);
END dff;
260
Unit-9 Digital Design
Example 11.13
For a T flip-flop write down Behavior Model.
Solution :
A D flip flop is shown in figures 11.25, waveforms are shown in figure
11.26 and Truth table is shown in Table 11.7.
PR
Input
T Q
FF
Clk
Q
CR
261
Unit-9 Digital Design
PR CR T(i/p) Output
Q(t + 1)
0 0 X 1
0 1 X 1
1 0 X 0
1 1 0 Q
1 1 1 `Q
ENTITY tff IS
port(clk,pr,cr,t:in bit; q:inout bit; qbar:out bit);
END tff;
262