Combinational Logic Design Using VHDL Student
Combinational Logic Design Using VHDL Student
Discussion: BEGIN
Y <= (NOT X1 AND NOT X3) OR (NOT X2
Output: AND NOT X3) OR (X1 AND X2 AND X3);
END PROCESS;
IV. ACTIVITY IV
Write VHDL code to implement the implicit sum of END behavorial;
products (SOP) and product of sum (POS) logic functions
F1(x1,x2,x3,x4) = ∑ (m0,m1,m4,m5,m8,m9,m14,m15) (c) Structural style (using only NAND gates) (for F1)
F2(x1,x2,x3,x4) = ∏ (M0,M1,M5,M8,M9,M13,M15) [sop_and.vhd]
Draw the truth tables for the functions, and use Karnaugh LIBRARY IEEE;
maps to simplify. Provide the following architectural styles: USE IEEE.STD_LOGIC_1164.ALL;
Dataflow style
Behavioral style ENTITY and1 IS PORT (
a, b: IN STD_LOGIC;
Structural style (using only NAND gates)
o: OUT STD_LOGIC
Write a VHDL test bench to verify the operation of the
);
logic circuit. Provide a simulation waveform depicting all
END and1;
possible input cases.
ARCHITECTURE behavorial OF and1 IS
(a) Truth Table
SIGNAL F: STD_LOGIC;
BEGIN
(b) Karnaugh Map Simplification
LIBRARY IEEE;
PROCESS (a,b,F) USE IEEE.STD_LOGIC_1164.ALL;
BEGIN [pos_not.vhd]
LIBRARY IEEE;
PROCESS(X1,X2,X3,X4) USE IEEE.STD_LOGIC_1164.ALL;
BEGIN
Y <= (X3 OR NOT X4) AND (X2 OR X3) ENTITY not1 IS PORT (
AND (NOT X1 OR NOT X2 OR NOT X4); a: IN STD_LOGIC;
END PROCESS; o: OUT STD_LOGIC
);
END behavorial; END not1;
(f) Structural style (using only NAND gates) (for F2) ARCHITECTURE behavorial OF not1 IS
[pos_and.vhd]
LIBRARY IEEE; BEGIN
USE IEEE.STD_LOGIC_1164.ALL;
PROCESS (a)
ENTITY and1 IS PORT ( BEGIN
a, b: IN STD_LOGIC; o <= a NAND a;
o: OUT STD_LOGIC END PROCESS;
);
END and1; END behavorial;
PROCESS (S,X1,X2)
BEGIN
IF ((NOT S AND X1) OR (S AND X2)) =
'1' THEN Y <= '1';
ELSE Y <= '0';
END xor1;
[full_adder.vhd]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
Fig. 4-bit adder/subtracter using 1-bit Full Adder ENTITY full_adder IS PORT (
i1, i2, cin: IN STD_LOGIC;
`TABLE – V sum, cout: OUT STD_LOGIC
TRUTH TABLE FOR 1-BIT FULL ADDER );
Input Bits Output END full_adder;
X Y Carry (Cin) Carry (Cout) Sum (S)
ARCHITECTURE dataflow OF full_adder IS
0 0 0 0 0 BEGIN
0 0 1 0 1 sum <= i1 XOR i2 XOR cin;
0 1 0 0 1 cout <= (i1 AND i2) OR ((i1 XOR i2)
AND cin);
0 1 1 1 0
END dataflow;
1 0 0 0 1
1 0 1 1 0 [add_sub_structural.vhd]
1 1 0 1 0 LIBRARY IEEE;
1 USE IEEE.STD_LOGIC_1164.ALL;
1 1 1 1
ENTITY add_sub IS PORT (
𝑺 = 𝑿 ⊕ 𝒀 ⨁ 𝑪𝒊𝒏 and 𝑪𝒐𝒖𝒕 = 𝑿𝒀 + (𝑿 ⊕ 𝒀) 𝑪𝒊𝒏 X3, X2, X1, X0: IN STD_LOGIC;
Y3, Y2, Y1, Y0, A_S: IN STD_LOGIC;
S4, S3, S2, S1, S0: OUT STD_LOGIC
);
END add_sub;
Fig. Logic Circuit for 1-bit Full Adder COMPONENT xor1 IS PORT (
i1, i2: IN STD_LOGIC;
Use structural architecture style with hierarchical design o1: OUT STD_LOGIC
approach. Use 1-bit adder as the basic building block. );
END COMPONENT;
Implement the 4-bit adder/subtracter using four 1-bit full
adders. Write a VHDL test bench to verify the operation of the
COMPONENT full_adder IS PORT (
4-bit adder/subtracter. Provide a simulation waveform
i1, i2, cin: IN STD_LOGIC;
depicting all possible input cases.
sum, cout: OUT STD_LOGIC
);
VHDL Code:
END COMPONENT;
[xor1.vhd]
LIBRARY IEEE; BEGIN
USE IEEE.STD_LOGIC_1164.ALL; A0: xor1 PORT MAP (i1 => A_S, i2 =>
Y0, o1 => F0);
ENTITY xor1 IS PORT ( A1: full_adder PORT MAP (i1 => X0,
i1, i2: IN STD_LOGIC; i2 => F0, cin => A_S, sum => S0, cout =>
o1: OUT STD_LOGIC C1);
);
A2: xor1 PORT MAP (i1 => A_S, i2 =>
Y1, o1 => F1); S4 => output_vector(4),
A3: full_adder PORT MAP (i1 => X1, S3 => output_vector(3),
i2 => F1, cin => C1, sum => S1, cout => S2 => output_vector(2),
C2); S1 => output_vector(1),
S0 => output_vector(0)
A4: xor1 PORT MAP (i1 => A_S, i2 => );
Y2, o1 => F2);
A5: full_adder PORT MAP (i1 => X2, stim_proc: PROCESS
i2 => F2, cin => C2, sum => S2, cout =>
C3); BEGIN
FOR index1 IN 0 TO 15 LOOP
A6: xor1 PORT MAP (i1 => A_S, i2 => input_vector1 <=
Y3, o1 => F3); std_logic_vector(to_unsigned(index1,4));
A7: full_adder PORT MAP (i1 => X3, FOR index2 IN 0 TO 15 LOOP
i2 => F3, cin => C3, sum => S3, cout => input_vector2 <=
S4); std_logic_vector(to_unsigned(index2,4));
WAIT FOR 50 ns;
END structural; END LOOP;
END LOOP;
Test Bench END PROCESS;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; END behavioral;
USE IEEE.NUMERIC_STD.ALL;
BEGIN
uut: add_sub PORT MAP(
A_S => addsub,
X3 => input_vector1(3),
Use a hierarchical design approach. Create component
X2 => input_vector1(2),
definitions in separate (.vhd) files. Use either Dataflow or
X1 => input_vector1(1),
Behavioral or Structural design styles. Use structural design
X0 => input_vector1(0),
style for the 4:1 MUX architecture. Make use of 2:1 MUX
Y3 => input_vector2(3), component declaration. Make use of 2:1 MUX component
Y2 => input_vector2(2), instantiation. Write a VHDL test bench to verify the operation
Y1 => input_vector2(1), of the 4:1 MUX. Provide a simulation waveform depicting all
Y0 => input_vector2(0), possible input cases.
VHDL Code: ARCHITECTURE behavioral OF mux4to1_tb IS
[mux2to1_dataflow.vhd] COMPONENT mux4to1
LIBRARY IEEE; PORT(
USE IEEE.STD_LOGIC_1164.ALL; X1, X2, X3, X4: IN STD_LOGIC;
ENTITY mux2to1 IS PORT ( S0, S1: IN STD_LOGIC;
SEL, I1, I2: IN STD_LOGIC; Y: OUT STD_LOGIC
O: OUT STD_LOGIC );
); END COMPONENT;
END mux2to1;
SIGNAL select_vec:
ARCHITECTURE dataflow OF mux2to1 IS STD_LOGIC_VECTOR( 1 DOWNTO 0) := "00";
BEGIN SIGNAL input_vec:
WITH (NOT SEL AND I1) OR (SEL AND I2) STD_LOGIC_VECTOR( 3 DOWNTO 0) := "0000";
SELECT SIGNAL output: STD_LOGIC := '0';
O <= '1' WHEN '1',
'0' WHEN '0', BEGIN
'0' WHEN OTHERS; uut: mux4to1 PORT MAP(
END dataflow; S0 => select_vec(0),
S1 => select_vec(1),
[mux4to1_structural.vhd] X1 => input_vec(3),
LIBRARY IEEE; X2 => input_vec(2),
USE IEEE.STD_LOGIC_1164.ALL; X3 => input_vec(1),
X4 => input_vec(0),
ENTITY mux4to1 IS PORT ( Y => output
X1, X2, X3, X4, S0, S1: IN STD_LOGIC; );
Y: OUT STD_LOGIC
); stim_proc: PROCESS
END mux4to1;
BEGIN
ARCHITECTURE structural OF mux4to1 IS FOR selector IN 0 TO 3 LOOP
SIGNAL F1, F2: STD_LOGIC; select_vec <= std_logic_vector
(to_unsigned(selector,2));
COMPONENT mux2to1 IS PORT ( FOR index IN 0 TO 15 LOOP
I1, I2, SEL: IN STD_LOGIC; input_vec <=
O: OUT STD_LOGIC std_logic_vector(to_unsigned(index,4));
); WAIT FOR 50 ns;
END COMPONENT; END LOOP;
END LOOP;
BEGIN END PROCESS;
M0: mux2to1 PORT MAP (I1 => X1, I2 END behavioral;
=>
X2, SEL => S0, O => F1); Discussion:
M1: mux2to1 PORT MAP (I1 => X3, I2 Output:
=>
X4, SEL => S0, O => F2);
M2: mux2to1 PORT MAP (I1 => F1, I2 CONCLUSION
=>
F2, SEL => S1, O => Y);
END structural;
Test bench
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
ENTITY mux4to1_tb IS
END mux4to1_tb;