Sunday, March 16, 2025

Entry 3: Logical gates

 

Now that pull-up and pull-down resistors are clear, let's get back to the fundamental logic gates:

  • NOT gate
  • AND gate
  • OR gate
  • NAND gate
  • NOR gate
Let's begin with the NOT gate.

NOT gate

NOT Gate Functionality

A NOT gate (inverter) takes one input and produces an output that is the logical inverse:

  • Input HIGH (1) → Output LOW (0).
  • Input LOW (0) → Output HIGH (1).
  • Truth Table:
    Input (A)Output (Q)
    01
    10
This is the NOT gate (inverter) symbol:


I asked Grok "Which chip contains NOT gates":

A widely used and beginner-friendly chip that contains NOT gates is the 74LS04Other options include 74HC04 (CMOS version, 2-6V operation).

I got the 74HC04, which apparently has the same pinout and functions the same as 74LS04. It contains 6 NOT gates. 

I then asked Grok "How can I demonstrate the workings of a NOT gate using this chip, button and and LED?":

Demonstration Setup

Here’s how to build a circuit to demonstrate the 74LS04 NOT gate using a button and an LED:

Materials Needed

  • 74LS04 IC (hex inverter).
  • Breadboard.
  • Power supply: 5V DC (e.g., USB or battery with regulator).
  • Push button (momentary switch).
  • LED (e.g., red).
  • Resistors:
    • 220Ω or 330Ω (for the LED, current-limiting).
    • 10kΩ (pull-down resistor for input, see entry 2).
  • Jumper wires.

Circuit Design

We’ll use one of the six NOT gates (e.g., pins 1 and 2) for this demo.

  1. Power the Chip:
    • Connect Pin 14 (VCC) to +5V.
    • Connect Pin 7 (GND) to ground (0V).
  2. Set Up Input with Button:
    • Input A1 (Pin 1):
      • Connect a 10kΩ resistor from Pin 1 to ground (pull-down, ensures LOW when button is not pressed, see entry 2).
      • Connect a push button from Pin 1 to +5V (when pressed, Pin 1 goes HIGH).
  3. Set Up Output with LED:
    • Connect Pin 2 (output Y1) to the anode (longer leg) of the LED.
    • Connect the cathode (shorter leg) of the LED to ground through a 220Ω resistor (limits current to ~10-15mA at 5V).
  4. Unused Gates:
    • Tie unused inputs (pins 3, 5, 9, 11, 13) to ground or VCC to prevent floating states, which can affect TTL chips. (I will skip this).



How to Demonstrate

  1. Power On: Apply 5V to the circuit. The LED should be ON initially (input LOW → output HIGH).
  2. Test Input States:
    • Button Not Pressed:
      • Input (Pin 1) = LOW (0V, pulled down by 10kΩ resistor).
      • Output (Pin 2) = HIGH (~5V, inverted by NOT gate).
      • LED ON (current flows).
    • Button Pressed:
      • Input (Pin 1) = HIGH (5V from button).
      • Output (Pin 2) = LOW (0V, inverted).
      • LED OFF (no voltage across it).
  3. Release Button: LED turns ON again as input returns to LOW and output to HIGH.

Observation: The LED is ON when the button is not pressed and OFF when pressed, demonstrating the NOT gate’s inversion: input 0 → output 1, input 1 → output 0.



Next, the AND gate.

AND gate

AND Gate Functionality

An AND gate outputs a HIGH (1) signal only when all its inputs are HIGH (1). If any input is LOW (0), the output is LOW (0).

  • Truth Table:
    ABOutput (Q)
    00 0
    01 0
    10 0
    11 1

This is the AND gate symbol:

"A widely used and beginner-friendly chip that contains AND gates is the 74LS08." I will use 74HC08 instead (same pinput). 

Demonstration Setup

Here’s how to build a circuit to demonstrate the 74LS08 AND gate using buttons and an LED:

Materials Needed

  • 74LS08 IC (quad 2-input AND gate).
  • Breadboard.
  • Power supply: 5V DC (e.g., USB power or battery with regulator).
  • Two push buttons (momentary switches).
  • LED (any color, e.g., red).
  • Resistors:
    • 220Ω or 330Ω (for the LED, current-limiting).
    • Two 1kΩ (pull-down resistors for inputs).
  • Jumper wires.

Circuit Design

We’ll use one of the four AND gates (e.g., pins 1, 2, and 3) to keep it simple.

  1. Power the Chip:
    • Connect Pin 14 (VCC) to +5V.
    • Connect Pin 7 (GND) to ground (0V).
  2. Set Up Inputs with Buttons:
    • Input A (Pin 1):
      • Connect a 1kΩ resistor from Pin 1 to ground (pull-down, ensures LOW when button is not pressed).
      • Connect a push button from Pin 1 to +5V (when pressed, Pin 1 goes HIGH).
    • Input B (Pin 2):
      • Connect a 1kΩ resistor from Pin 2 to ground (pull-down).
      • Connect a push button from Pin 2 to +5V (when pressed, Pin 2 goes HIGH).
  3. Set Up Output with LED:
    • Connect Pin 3 (output Y1) to the anode (longer leg) of the LED.
    • Connect the cathode (shorter leg) of the LED to ground through a 220Ω resistor (limits current to ~10-15mA at 5V).
  4. Unused Gates:
    • Tie unused inputs (pins 4, 5, 9, 10, 12, 13) to ground or VCC to prevent floating states, which can cause erratic behavior in TTL chips.





How to Demonstrate

  1. Power On: Apply 5V to the circuit. The LED should be OFF initially (both inputs LOW).
  2. Test Input Combinations:
    • No buttons pressed: A = 0, B = 0 → LED OFF (0 AND 0 = 0).
    • Press Button 1 only: A = 1, B = 0 → LED OFF (1 AND 0 = 0).
    • Press Button 2 only: A = 0, B = 1 → LED OFF (0 AND 1 = 0).
    • Press both Button 1 and Button 2: A = 1, B = 1 → LED ON (1 AND 1 = 1).
  3. Observe: The LED lights up only when both buttons are pressed, demonstrating the AND gate’s logic.


OR gate

Function: Outputs 1 if at least one input is 1; outputs 0 only if all inputs are 0.

Truth Table (2-input):
ABQ
000
011
101
111

This is the OR gate symbol:

The 74LS32 has 4 OR gates:
The demonstration of the OR gate is very similar to the AND gate. The design is identical, except for the AND gate now being an OR gate. 

How to Demonstrate

  1. Power On: Apply 5V to the circuit. The LED should be OFF initially (both inputs LOW).
  2. Test Input Combinations:
    • No buttons pressed:
      • A = 0, B = 0 → LED OFF (0 OR 0 = 0).
    • Press Button 1 only:
      • A = 1, B = 0 → LED ON (1 OR 0 = 1).
    • Press Button 2 only:
      • A = 0, B = 1 → LED ON (0 OR 1 = 1).
    • Press both Button 1 and Button 2:
      • A = 1, B = 1 → LED ON (1 OR 1 = 1).
  3. Release Buttons: LED turns OFF when both buttons are released, returning to 0 OR 0 = 0.

Observation: The LED lights up whenever at least one button is pressed, demonstrating the OR gate’s logic: output is HIGH if any input is HIGH.



Two more, NAND and NOR

NAND gate

Function: Outputs 0 only if all inputs are 1; otherwise, outputs 1. It’s an AND gate followed by a NOT gate.

Truth Table (2-input):
ABQ
001
011
101
110

This is the NAND gate symbol:

It is identical to and AND gate followed by a NOT gate:
The 74LS00 has 4 NAND gates:

How to Demonstrate

  1. Power On: Apply 5V to the circuit. The LED should be ON initially (both inputs LOW → output HIGH).
  2. Test Input Combinations:
    • No buttons pressed:
      • A = 0, B = 0 → LED ON (NOT (0 AND 0) = 1).
    • Press Button 1 only:
      • A = 1, B = 0 → LED ON (NOT (1 AND 0) = 1).
    • Press Button 2 only:
      • A = 0, B = 1 → LED ON (NOT (0 AND 1) = 1).
    • Press both Button 1 and Button 2:
      • A = 1, B = 1 → LED OFF (NOT (1 AND 1) = 0).
  3. Release Buttons: LED turns ON again when both inputs return to LOW (0 NAND 0 = 1).
Observation: The LED is ON unless both buttons are pressed, demonstrating the NAND gate’s logic: output is LOW only when all inputs are HIGH.


Finally, the last stupid gate, the NOR gate

NOR gate

NOR Gate Functionality

A NOR gate (NOT OR) outputs a HIGH (1) signal only when all inputs are LOW (0); otherwise, it outputs LOW (0). It’s an OR gate followed by a NOT gate.

Truth Table (2-input):
ABQ
001
010
100
110

This is the NOR gate symbol:

It is identical to and OR gate followed by a NOT gate:
The 74LS02 has 4 NOR gates:

How to Demonstrate

  1. Power On: Apply 5V to the circuit. The LED should be ON initially (both inputs LOW → output HIGH).
  2. Test Input Combinations:
    • No buttons pressed:
      • A = 0, B = 0 → LED ON (NOT (0 OR 0) = 1).
    • Press Button 1 only:
      • A = 1, B = 0 → LED OFF (NOT (1 OR 0) = 0).
    • Press Button 2 only:
      • A = 0, B = 1 → LED OFF (NOT (0 OR 1) = 0).
    • Press both Button 1 and Button 2:
      • A = 1, B = 1 → LED OFF (NOT (1 OR 1) = 0).
  3. Release Buttons: LED turns ON again when both inputs return to LOW (0 NOR 0 = 1).

Observation: The LED is ON only when neither button is pressed, demonstrating the NOR gate’s logic: output is HIGH only when all inputs are LOW.


Summary

You could certainly dig deeper and investigate how basic gates are designed from transistors, and how transistors work, but this is as "low-level" as I will go.

Here is a summary of AND, OR, NAND and NOR

I am not sure yet why we need these gates and what role they will play in a computer. I was guided here by Grok trying to figure out a major part of a computer, namely a register. The explanation was based on D flip-flops, which in term was explained through an SR latch. So, I am moving on to the SR latch, which will hopefully make more sense now.