Construct an XOR gate with only an 74LS132 quad NAND gate, and demonstrate it’s behaviour with an Arduino and Processing.
I recently needed an XOR gate, but only had NAND gates on hand.
NAND (and NOR) gates are sometimes known as “universal” logic elements, as it is possible to contruct any other type of logic gate with them.
So while a little wasteful, I’m using the four NAND gates of a single 74LS132 chip to produce one XOR gate.
XOR From NAND Logic
Output State Plot
The XorWithNandGates.ino sketch drives the A/B inputs with a state change every 500ms. Three Arduino analog pins are used to rea dthe actual A, B and Q (output) voltages.
PlotNValues (a simple Processing sketch) reads the data from the serial port and plots the output value over time, with some coloration effects thrown in for good measure.
Here’s a sample trace:
- top trace: Q (output)
- middle trace: B
- bottom trace: A