CS 240 Lab 1: Transistors to Gates

Peter Mawhorter

Outline

  • Course Structure
  • Basic Electronics (Ohm’s law, transistors, logic gates)
  • Sum-of-Products and Equivalence
  • Integrated Circuits
  • Protoboard (for building physical circuits)
  • LogicWorks (for simulating circuits)

Course Structure

Important Policies

  • No food or drink
    • You may step out for a snack/sip, and we’ll have a break.
  • Masks are required
    • (Due to the prevalence of asymptomatic infections, and the as-yet-unquantified nature of the risks of COVID-19.)

Course Parameters

  • Pre-lab exercises will be in Google docs, or in Gradescope
    • Pre-lab exercises are individual
    • Share docs w/ partner & instructor
  • I will assign different partners each lab
  • Grade is based on pre-lab assignment (30%) and in-lab work (70%), or just in-lab work if there is no assignment

Partner Work

  • Be kind to each other (yes, even when you’re tired)
  • Enhance each others’ learning
  • You’ve had practice at this

Expectations

  • You’re now full-fledged CS majors
    • Capable of independent learning
    • Will ask questions when you need to
    • Will be responsible for meeting deadlines, doing prep work, etc.
  • You will succeed and thrive in this class, and you’ll go on to do great things with this knowledge.

Growth Mindset

  • When you’re having trouble, identify why and what you need to practice to improve.
  • Don’t limit your own potential by buying into the belief that you are either “bad at” or “good at” a subject.
  • This class is hard in order to make you grow strong (but hopefully in a gentle way).

Logging In

  • Use your Wellesley username/password for Windows
  • Use your CS Department username/password for Linux
    • (you set this up in CS 111 or more likely CS 230, if you didn’t just do it this week)
  • Mash F12 when it boots to get to the boot menu for some machines

Setup

  1. Find your partner.
  2. Log in to Windows on at least 1 machine.
  3. Open up a browser an navigate to the class website’s lab section.
    • Scroll down to the bottom to find Lab 1
    • Open up these slides and also the Lab Notebook
  4. Make your own copy of the lab notebook, and share it with your partner and with me (pmawhort@wellesley.edu).

Basic Electronics

What is Electricity?

  • Electricity = the movement of electrons in a material
    • Movement happens because of extra electrons in one place, or extra “holes” in another place, or both.
    • Electrons are so fast. Really, just so fast.

What is Electricity?

  • We measure the surplus or deficit of electrons in relative terms
    • This is voltage (V, measured in Volts), and is always a difference between two points.
    • When unimpeded, the flow of electrons quickly reduces voltage to 0.
  • Rate of flow is called current, (I, measured in Amps)
  • All materials resist the flow of electrons
    • This is called resistance (R, measured in Ohms = Ω)

What is Electricity?

  • Materials that have low resistance are called “conductors”.
    • The resistance of a copper wire is basically 0 (it’s around 1 Ω per 1000 feet of wire, depending a bit on thickness).
  • We use resistors with specific Ohm ratings to create resistance in our circuits, often ~1.8 kΩ.
  • Your body has a resistance value anywhere from 300-100,000 Ω
  • Air has resistance of 1.3-3.3×10¹⁶ Ω (until about 21 kV/cm)

Ohm’s Law

V=I×RV = I \times R

Voltage (V) equals current (I) times resistance (R).

  • More voltage → more current
  • More resistance → less current, since I=VRI = \frac{V}{R}
  • Zero resistance = infinite current (!)

A diagram showing positively and negatively charged materials, with current as the flow of electrons from the negatively-charged material to the positively-charged material. A second diagram showing a 5-volt voltage source with positive and negative terminals. The positive terminal connects to a 250-Ohm resistor, and then back to the negative terminal in a loop. The diagram indicates that 0.2 amps of current are flowing from the positive to the negative terminal. 

Ohm’s Law

  • Conventions are hard to change, current is shown backwards from the flow of electrons (we don’t care).
  • For our purposes, an open switch (meaning electricity has to jump across air) has infinite resistance: no current flows.
  • We also don’t care about the resistance of our wires, they are effectively 0.
  • A “short circuit” means a circuit with negligible resistance. Current becomes very high, until the circuit destroys itself.

Digital vs. Analog

Analog

Analog circuits like antennas or speakers have a complex balance of resistance, current, and voltage, which varies over time.

Digital

We will study digital circuits, which have defined “high” and “low” voltage values; the exact numbers don’t matter so much.

Digital vs. Analog

  • A typical digital circuit uses just 5 volts, and might define “high” as anything above 3 volts, and “low” as anything below that (more detail).
  • Only minimal current may be necessary for the circuit to function, as long as the correct voltage differences can be achieved.
  • Using “high” and “low” we can represent True and False, or 1 and 0.

(Once you give a computer scientist a 1 and a 0, it’s game over.)

Thinking Logically

Gates and Truth Tables

  • A truth table specifies the high/low or 1/0 combinations for different parts of a digital circuit. (You saw these in CS 111 for Booleans)
  • True = 1 and False = 0
  • Here, two inputs A and B (called literals) are shown, along with a function F of A and B.
    What function is this?
A B F
0 0 0
0 1 0
1 0 0
1 1 1

Boolean Algebra

  • Before, you might write “A and B” or “A && B,” now we will write just “ABAB” for AND and “A+BA + B” for OR.
    • Basically, AND is multiplication and OR is addition.
    • 1×11 \times 1 is 1, but anything ×0\times 0 is 0.
    • 0+1=1+0=1+10 + 1 = 1 + 0 = 1 + 1 (if you can’t go above 1).
    • Use ’ for NOT, or write a bar above: A’ or A¯\overbar{A}

Boolean Algebra

  • A minterm is an AND of all of the inputs to a function, possibly with NOTs. The four minterms of two inputs A and B are: AB, A’B, AB’, and A’B’.
  • A maxterm is an OR of all inputs, possibly negated. The four maxterms of two inputs A and B are:
    A + B, A’ + B, A + B’, and A’ + B’.

Basic Functions

Here are truth tables for NOT, AND, and OR, which you are already familiar with:

NOT
F = A’
A F
0 1
1 0
AND
F = AB
A B F
0 0 0
0 1 0
1 0 0
1 1 1
OR
F = A + B
A B F
0 0 0
0 1 1
1 0 1
1 1 1

Basic Functions

Here are truth tables for NAND, NOR, and XOR:

NAND
F = (AB)’
A B F
0 0 1
0 1 1
1 0 1
1 1 0
NOR
F = (A + B)’
A B F
0 0 1
0 1 0
1 0 0
1 1 0
XOR
F = AB’ + A’B
A B F
0 0 0
0 1 1
1 0 1
1 1 0

Basic Functions

  • Why NAND, NOR, and XOR?
    • NAND and NOR are easier to build in a circuit than AND and OR, as we’ll soon see.
    • XOR is quite useful in a number of applications, including cryptography.
    • As the formulas show, NAND, NOR, and XOR can be built out of AND, OR, and NOT.
    • Alternatively, AND and OR can be built from NAND, NOR, and NOT.

Gate Symbols

A diagram showing the circuit symbols for each gate: a flat back and round head for AND, a curved back and pointy-but-curved head for OR, and a triangle with a dot at the tip for NOT. For NAND and NOR, the symbol is the same as AND and OR, but with a dot added to the tip. XOR is the same as OR, but with an extra curved line before the gate, crossing through both input wires and parallel to the curved back of the gate. Except NOT, each gate has 2 inputs and 2 output, NOT has 1 input and 1 output. 

Aside: Mental Juggling

Aside: truth tables present information clearly, but they’re hard to read, and it’s harder to keep them in your head as you then try to apply them to each other or think through a circuit.

This class will repeatedly strain (and also develop) your ability to mentally juggle multiple steps of translation between different representations and parts of a system.

Aside: Mental Juggling

Use tools to improve your juggling skills:

  • Keep references handy, ideally visible without having to even click or turn a page.
  • Practice to internalize key info, like the basic truth tables.
  • Keep scratch paper or a scratch file handy to write things out when your mental stack is out of space.

Sum-of-Products

  • Sum-of-products is a fancy way of saying: read the truth table and make an AND out of each line where the output is 1, then OR those together.
    • Remember that AND = multiply (i.e., product), and OR = add (i.e., sum).
    • Each product is a minterm.
  • For this table, there are three 1s for F, with minterms A’B, AB’, and AB, so the sum-of-products form is F = A’B + AB’ + AB.
A B F
0 0 1
0 1 0
1 0 0
1 1 0

Sum-of-Products

  • Any boolean function can be expressed as a sum-of-products, which only needs NOT, AND, and OR.
  • If we had circuits that could produce these functions, we could put them together to compute anything.

Equivalence

Two functions with the same truth table are equivalent.

F = A’B’ + A’B
A B A’B’ A’B A’B’ + A’B
0 0 1 0 1
0 1 0 1 1
1 0 0 0 0
1 1 0 0 0
Q = A’ + A’B + A’B’
A B A’ A’B A’B’ A’ + A’B + A’B’
0 0 1 0 1 1
0 1 1 1 0 1
1 0 0 0 0 0
1 1 0 0 0 0

Equivalence

  • Use Boolean algebra to find/prove equivalence.
  • Find ways to make the same circuit with fewer or cheaper gates.

Transistors

Transistors

  • To be able to build NOT, AND, and OR gates in a circuit, there has to be a way for voltage or current in one place to manipulate the flow of current or the difference in voltage somewhere else: a switching mechanism.

  • Early switches were big (vacuum tubes) but transistors represent the culmination of decades of research into making them smaller.

  • A modern transistor can be as small as 5 nanometers, with 10s of billions packaged on a singe chip.

Transistors

  • When voltage is present at the trigger side of a transistor, current may flow through, but if no voltage is present, current may not flow.
  • To create a NOT gate, connect input A to the trigger, and output F to the wire leading into the transistor’s channel. (simulation link)
    • When A is high, the current flows across the transistor, draining away voltage above the transistor.
    • When A is low, current cannot pass the transistor, and gets bottled up behind it, creating high voltage at the output.
    • Resistors prevent a short circuit in either state.

An image showing how transistors can be used to create NOT, NAND, and AND gates. TODO 

An image showing how transistors can be used to create NOR and OR gates. TODO 

Integrated Circuits

  • Integrated Circuits (i.e., chips) contain transistors in a specific configuration.
  • The pinout for a chip specifies the internal wiring. Find them online based on the chip number, or in the TTL Data Book.
  • Must be connected to both a voltage source and ground to work.

A picture of an integrated circuit. The main body is black with faint grey writing on it that says the part number and the manufacturer. Sticking out on each side are silver metal spikes or legs (this one has 7 on each side). These point downwards, and can be plugged into the grid of holes in our protoboards. One end of the chip has a small semicircle cut out to help figure out which end is which (we call this end the “top”). 

Integrated Circuits

  • Pins are numbered starting with 1 at the top-left and going around counter-clockwise.
  • Notch determines the “top.”
  • Watch out: the pins are often shown lined up in diagrams, rather than wrapped around the chip.

A pinout diagram for the “7408” chip, with 14 pins, 7 on each side. Internally, it contains AND gates: pins 1 and 2 are inputs to an AND gate with output to pin 3, and similarly for pins 4/5 to 6, pins 9/10 to 8, and pins 12/13 to 11. Pin 14 (at top-right) is labelled Vcc (for Voltage at Common Collector; we just want +5 volts here). Pin 7 (at bottom-left) is labelled GND, for ground. 

Protoboards

A picture of a protoboard, with some transistors, wires, and chips connected. The power switch is on the upper left, and is a red rocker-type switch which is ON when the top part is pushed down and OFF when the bottom part is pushed down. Black and red wires are connected already which connect +5V and ground to 6 sets of vertical rails going up and down the center, which is white. Each rail connects vertically underneath a series of holes which can be used to plug wires into it. In between these sets of rails are three sets of paired rows of holes, where in each row has a left and right half. The two halves are not connected to each other, but every hole on each half is connected to the other holes in the same half of the row. This allows a chip to be inserted spanning between the halves, such that each pin of the chip connects to a single row on either the left or right half. This in turn makes it easy to plug up to 4 wires into holes that will connect to a particular pin of the chip (the half-rows have 5 holes each, and the chip leg takes up one of them). Two chips are plugged into the board in this manner in the upper-right region. On the left, two transistors are plugged in, spanning across several rows. Outside the center region with the holes, there are input and output devices around the edge of the board. A function generator below the power switch on the left, two push-buttons below that, a BNC J1 connector on the bottom-left, a series of eight logic switches to the right of that bottom-left corner, 10K and 1K POT connections in the middle of the bottom, S9 and S10 switches on the right of the bottom, a BNC J2 connector on the bottom-right, an 8Ω speaker above that on the right edge, and a set of 8 logic indicator lights on the upper part of the right edge. At the top-right there are three voltage connections (+5V, +13-15V, and -13-15V) and a ground connection, with two adjustment knobs at the top. Each of these various input/output devices has its own set of holes into which wires can be connected, the push-buttons are already connected to the left-most +5V rail with resistors, and the 8 logic switches have been wired to 8 of the horizontal rows on the bottom-left of the board. 

A protoboard is a prototyping tool: it has places to hold wires and chips so you can put them together easily, with internal horizontal and vertical connections. It also has a power supply and things like switches and LEDs built-in.

Building a Gate

  • A NOT gate can be built with 2 resistors and 1 transistor:
    1. Connect one resistor to the top/input leg of the transistor, and then to the +5V rail of the board.
    2. Connect the same horizontal row that has the resistor and transistor input plugged in to one of the “logic indicator” sockets using a wire. This is the gate output.
    3. Connect the middle/trigger leg of the transistor to one of the push-buttons (they already have resistors connected, so you get one resistor for free).
    4. Connect the bottom/output leg of the resistor to the ground rail on the board.
  • Double-check your connections, then turn on power to the board. The logic indicator should read “high.”
    • Push the button to change the indicator to “low.”

Simulation

Simulation

  • In addition to building circuits, we’ll be simulating them using LogicWorks. It’s available in Windows on the lab machines.
  • For simple circuits, you can also use the Falstad circuit simulator which shows voltage and current flow, but has fewer options for labelling, checking timing, and building more complex circuits.