







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








nd
Nam e Reg. No. Mar ks
5.1 Objectives The objectives of this experiment are: To analyze the performance of XOR and XNOR gates ICs and draw their truth tables To implement XOR and XNOR using basic gates only To implement XOR and XNOR using NAND gates only 5.2 Theory In the previous labs, we saw that by using the three principal gates, the AND Gate, the OR Gate and the NOT Gate, we can build many other types of logic gate functions, such as a NAND Gate and a NOR Gate or any other type of digital logic functions. But there are two other types of digital logic gates which although they are not a basic gate as they are constructed by combining together other logic gates, their output Boolean function is important enough to be considered as complete logic gates. These two “hybrid” logic gates are called the Exclusive-OR (Ex-OR) Gate and its complement the Exclusive-NOR (Ex-NOR) Gate.
A 2-input OR gate, if A = “1”, OR B = “1”, OR BOTH A + B = “1” then the output from the digital gate must also be at a logic level “1” and because of this, this type of logic gate is known as an Inclusive-OR function. The logic gate gets its name from the fact that it includes the case of Q = “1” when both A and B = “1”. If, however, a logic output “1” is obtained when ONLY A = “1” or when ONLY B = “1” but NOT both together at the same time, giving the binary inputs of “01” or “10”, then the output will be “1”. This type of gate is known as an Exclusive-OR function or more commonly an Ex-Or function for short. This is because its Boolean expression excludes the “OR BOTH” case of Q = “1” when both A and B = “1”. In other words, the output of an Exclusive-OR gate ONLY goes “HIGH” when its two input terminals are at “DIFFERENT” logic levels with respect to each other. An odd number of logics “1’s” on its inputs gives a logic “1” at the output. These two inputs can be at logic level “1” or at logic level “0” giving us the Boolean expression of: Q = (A ⊕ B) = A.B + A.B The Exclusive-OR Gate function, or Ex-OR for short, is achieved by combining standard logic gates together to form more complex gate functions that are used extensively in building arithmetic logic circuits, computational logic comparators and error detection circuits. The two-input “Exclusive-OR” gate is basically a modulo two adders, since it gives the sum of two binary numbers and as a result are more complex in design than other basic types of logic gate. The truth table, logic symbol and implementation of a 2-input Exclusive-OR gate is shown in Figure 5.1. Figure 5.1 2-input Ex-OR gate.
Figure 5.4 2-input Ex-NOR gate The Ex-NOR function is a combination of different basic logic gates Ex-OR and a NOT gate, and by using the 2-input truth table above, we can expand the Ex-NOR function to: Q = A ⊕ B = (A.B) + (A.B) which means we can realize this new expression using the following individual gates. Figure 5.5 2-input Ex-OR gate plus a NOT gate The Exclusive-NOR Gate, also written as: “Ex-NOR” or “XNOR”, function is achieved by combining standard/basic gates together to form more complex gate functions and an example of a 2-input Exclusive-NOR gate is given in Figure 5.6. Figure 5.6 Ex-NOR gate equivalence circuit One of the main disadvantages of implementing the Ex-NOR function above is that it contains three different types of logic gates the AND, NOT and finally an OR gate within its basic design. One easier way of producing the Ex-NOR function from a single gate type is to use NAND gates as shown in Figure 5.7. Figure 5.7 Ex-NOR Function implementation using NAND gates
5.3 Equipment DC Power Source / Power Supply Prototype Development Board Connecting Wires 5.4 Components ICs (7400, 7404, 7408, 7432, 7486, 74266) 330 Ω / 1 kΩ resistor ¼ watt Measured: 328 Ω LEDs 5.5 ICs Pin Diagrams Figure 5.8 2-input Logic XOR Gate IC Pin Diagram 5.6 Procedu re Figure 5.9 2-input Logic XNOR Gate IC Pin Diagram
Table 5.3 Observation of XOR implementation using Basic Gates
Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1 0 1 1 Table 5.4 Observation of XOR implementation using NAND Gates
Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State 0 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 1 0 1 1
Table 5.5 Observation of XNOR implementation using Basic Gates
Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State 0 0 1 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 Table 5.6 Observation of XNOR implementation using NAND Gates
Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State Logic / State 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 5.9 Results Table 5.7 Truth table of XOR
Ans: When any ONE input of an XOR gate is HIGH (logic 1) and the other is LOW (logic 0), the output is HIGH (logic 1). However, if BOTH inputs are HIGH simultaneously, the output is LOW (logic 0). XOR outputs HIGH only when the inputs are DIFFERENT. So a single HIGH input gives output = 1, but two HIGH inputs give output = 0.
This report presents the Verilog-based simulation of XOR and XNOR gates using three approaches: (1) minimum number of gates, (2) basic gates only (AND, OR, NOT), and (3) universal gates only (NAND gates). Truth tables are verified for all implementations.
2.1 Minimum Gate Implementation (4 NAND Gates) The XOR function can be implemented using only 4 NAND gates. This is the minimum gate count for XOR using a single gate type. The Boolean derivation is: A XOR B = NAND(NAND(A, NAND(A,B)), NAND(B, NAND(A,B))) Verilog Code — XOR using 4 NAND Gates: module xor_4nand(input A, B, output Y);
wire C, D, E; nand(C, A, B); // Gate 1: C = NAND(A,B) nand(D, A, C); // Gate 2: D = NAND(A,C) nand(E, B, C); // Gate 3: E = NAND(B,C) nand(Y, D, E); // Gate 4: Y = NAND(D,E) = A XOR B endmodule // Testbench module tb_xor_4nand; reg A, B; wire Y; xor_4nand uut(.A(A),.B(B),.Y(Y)); initial begin $monitor("A=%b B=%b Y=%b", A, B, Y); A=0;B=0; #10; A=0;B=1; #10; A=1;B=0; #10; A=1;B=1; #10; $finish; end endmodule Simulation Output (Truth Table Verification): A=0, B=0 → Y=0 (correct) | A=0, B=1 → Y=1 (correct) | A=1, B=0 → Y=1 (correct) | A=1, B=1 → Y=0 (correct) 2.2 XOR Using Basic Gates Only (AND, OR, NOT) Boolean expression: Y = A’B + AB’ = (A+B).(A’+B’) = (A+B).NAND(A,B). Implemented using AND, OR, and NOT gates as verified in Table 5.3. Verilog Code — XOR using Basic Gates: module xor_basic(input A, B, output Y); wire An, Bn, t1, t2; not(An, A); // NOT gate: An = A' not(Bn, B); // NOT gate: Bn = B' and(t1, A, Bn); // AND gate: t1 = A.B' and(t2, An, B); // AND gate: t2 = A'.B or(Y, t1, t2); // OR gate: Y = A.B' + A'.B endmodule
3.1 Minimum Gate Implementation (5 NAND Gates) XNOR = NOT(XOR). Using the 4-NAND XOR and adding one more NAND gate as inverter (by tying both inputs together) gives XNOR in 5 NAND gates total. Boolean expression: A XNOR B = AB + A’B’ Verilog Code — XNOR using 5 NAND Gates: module xnor_5nand(input A, B, output Y); wire C, D, E, Xor_out; nand(C, A, B); // Gate 1 nand(D, A, C); // Gate 2 nand(E, B, C); // Gate 3 nand(Xor_out, D, E); // Gate 4: XOR output nand(Y, Xor_out, Xor_out); // Gate 5: NOT(XOR) = XNOR endmodule Simulation Output (Truth Table Verification): A=0, B=0 → Y=1 (correct) | A=0, B=1 → Y=0 (correct) | A=1, B=0 → Y=0 (correct) | A=1, B=1 → Y=1 (correct) 3.2 XNOR Using Basic Gates Only (AND, OR, NOT) Boolean expression: Y = AB + A’B’. Requires 2 NOT gates, 2 AND gates, and 1 OR gate ( gates total). Verified in Table 5.5. Verilog Code — XNOR using Basic Gates: module xnor_basic(input A, B, output Y); wire An, Bn, t1, t2; not(An, A); // An = A' not(Bn, B); // Bn = B' and(t1, A, B); // t1 = A.B and(t2, An, Bn); // t2 = A'.B' or(Y, t1, t2); // Y = A.B + A'.B' = XNOR endmodule
As required by Analysis Question 2, XOR can also be implemented using NOR gates (universal gates other than NAND). The implementation uses 5 NOR gates as verified in the Analysis section. Verilog Code — XOR using 5 NOR Gates:
Assessment Rubrics CSC-105L – Digital Logic Design – Lab 05
Method: Lab reports, viva, and instructor observation during lab sessions. Outcome Assessed:
Date: