Now let's look at how MOSFETs are used in logic computations.

Well, let me back up a step. In order to understand computing, you must have a basic knowledge of boolean algebra. If you are unfamiliar with boolean algebra, stop here and do some research. I'll try and simplify it, but electronics-tutorials.ws has a great set of lessons on it specifically targeted to electronic, or digital, logic. The BBC has a cool interactive site for learning digital logic as well. Digital logic is what we use to design computer logic processors. You may also want to learn more about K-maps, which allow you to see complex truth tables in a different (and often easier) way, and De Morgan's theorems, which are the foundation of boolean algebra. In a broader sense, reference material in discrete mathematics, which covers logic but also set theory, recursion, and relations, may also come in handy. Wikipedia has a list of operators that are commonly used for logic expressions. Also, by way of clarification, in digital logic we use 1's (on) and 0's (off) to indicate the state of the input or output.

NOW let's look at how MOSFETs are used in logic computations, shall we.

First some theory

The first logic gate I want to introduce is the two-input AND gate because it's probably the easiest logic to understand. The image below shows the schematic symbol for an AND gate.

The output of the AND gate will only be high if BOTH of the inputs are also high. If either input is low, the output is also low. The symbol (in digital logic) is "●". See the table below for the AND gate truth table.

A B A • B 0 0 0 0 1 0 1 0 0 1 1 1

When looking at truth tables, the number of possible outcomes in the far right column is related to the number of inputs by raising 2 to a power equal to the number of inputs. In other words, if you have two inputs, you have 22 = 4 outputs. With 3 inputs, you get 23 = 8 outputs, and with 8 inputs your get 28 = 256 possible outputs.

The second gate to consider is the NAND gate, or Not AND. NOT is the way we describe negation, or saying something is the opposite. The negation of true is false, and the NOT of AND is NAND. The symbol for NOT (in digital logic) is the tilde, "~". The NAND truth table is similar, but opposite to the AND truth table. See below.

A B ~(A • B) 0 0 1 0 1 1 1 0 1 1 1 0

The output column is the complete opposite of the AND truth table output, isn't it? Other truth tables (and gates as well) are OR, NOR, XOR, XNOR, and NOT. I'll refer you to this page for a comprehensive list of truth tables used in digital logic and the associated schematic symbols.

Now some application

So how do MOSFETs come in to play with logic gates? Well, since MOSFETs are so easy to saturate (turn fully on) with a low voltage and almost negligible current, we can build the logic gates above with them and in turn build extremely reliable digital logic systems to process data. Let's look at how a NOT gate looks on the inside and see if we can make some sense of this. I'm starting with the NOT because it takes the fewest number of MOSFETs to build and should therefore be less confusing. See the schematic below.



The NOT gate is used, as it's name implies, to negate or invert the input signal. PB1 connects the two MOSFET gates to +6V, but only the ZVN will open with positive voltage. When it opens though, it connects the output to GND, so the + input becomes GND at the output. Conversely, when we apply GND to the input through PB2, only the ZVP opens, which connects the output to +6V, again inverting the signal. (When neither button is pressed, the output can 'float' and be either +V or GND, so it's common to force the input to one state to guarantee that you know what the output is at that moment in time. A simple way to do this is to replace either of the buttons with a 1kΩ resistor, forcing the input to that potential when the remaining button is not pressed. You get to choose which state is your idle state this way.) I encourage you to build this, but I won't detail the instructions.

Now let's see what a NAND gate looks like inside. This time we are using 4 MOSFETs. See the schematic below.

The LED will only turn off (logic 0) when both SWA and SWB are high (logic 1). (Notice how the LED symbol in the schematic is nearly black, indicating off? Remember that.) Compare this result to the NAND truth table. Again I encourage you to build this, but I will not be including build steps.

What do we get when we mix the two? If the NAND is a NOT AND, and we combine it with a second NOT, what do we get? Isn't that just a double negative? So the NOTs cancel, logically, and we're left with an AND gate. In boolean algebra, the equation looks like ~(~(A●B))⇔(A●B). Pretty neat. Below is the truth table for that in case that makes it easier to understand. Also below is the schematic, to which I've added some labels for clarification.

A B (A • B) ~(A • B) ~(~(A • B)) 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1

If you compare the schematics for the AND, NOT and NAND gates, you'll see that even though on the outside the NAND is the negation of AND, on the inside the AND gate is actually made of a NAND gate followed by a NOT gate. So like I said above, the AND gate is actually a NOT NAND. Don't worry, it took me a while to catch on to that one too. Also, notice how the LED in the schematic is bright red, indicating that it is on when the switches are on. Compare that to the NAND gate schematic image above.

Below are schematics for the OR and XOR gates. Notice that both are actually a combination of their respective inverse (NOR and XNOR) with a NOT gate.

In truth it can be proven that any logic gate, and therefore any logic circuit, can be built with some finite number of NAND gates. Also, FPGA chips and the boards designed around them allow you to write code (using VHDL or Verilog) that will connect the gates as needed in order to complete the circuit and are a very easy way to start building and implementing digital logic circuits. Considering how difficult it can be to wire up just one logic gate, can you imagine trying to wire up an entire logic circuit using discrete MOSFETs? It's only been possible in the last few years for students and hobbyists to be able to build circuits like adders, which are simple in theory but complex to build, because of the advancement of technology and the miniaturization of the parts involved. Anyway, I digress. I'm just so grateful for the technology that is at our fingertips, when not that long ago it was only a wish.

So now that it's as clear as mud, let's move on. Now that we have gates, what can we do with them?