This tutorial will cover creating an XOR circuit, and using some of the more advanced features of CircuitSim
Part 0: XOR Review
If you already know what an XOR does, you can skip this section.
XOR (Exclusive OR) is a logical operation on two inputs that returns true if both the inputs are different.
Here’s the truth table for XOR
There’s an XOR component in CircuitSim, but for the sake of this tutorial, let’s use AND, OR, and NOT gates to create our own XOR circuit.
Below is a circuit diagram of the XOR gate we will be creating. The symbols for the various logic gates used are labeled.
Part 1: Adding Pins
This will be a 1-bit XOR, so we’ll need two 1-bit inputs
b), and a single 1-bit output.
Go ahead and place the 2 inputs and 1 output now. Make sure that you leave enough room for all the gates you’ll need for your XOR.
Part 2: Changing Component Attributes
Lets add some labels to our inputs and outputs to make this subcircuit a bit more clear.
Click on a pin. The attribute table for the pin should pop up in the bottom left corner of your screen.
Here you can change the bit width of the pin, change its orientation, or add a label. I encourage you to try changing the pin’s orientation and bit width. See what happens. You may find these settings useful when working on larger circuits.
For now, just change the label for the pin. After typing in a label, hit “enter” and the changed label will be saved.
Label the two inputs
b, and the output
This is what your circuit should look like with labels.
Part 3: Adding Gates
Now place the AND, OR, and NOT gates you’ll need to complete the XOR circuit. Make sure to follow the circuit diagram from Part 0.
Part 4: Adding Wires
Connect each of the gates with wires according to the circuit diagram.
Part 5: Adding Text
Click on the Text tool (T in the toolbar), and then click anywhere on the canvas to place a text box.
With text box selected, enter some text. I chose “XOR circuit created with CircuitSim” but you can write anything you want. As long as the text box is selected, you can edit/add/delete text.
Deselect the text box once you are done. You can deselect by clicking anywhere else on the canvas.
Part 6: Labeling Subcircuits
Now that are subcircuit is done, let’s label it. Right click on the subcircuit’s tab (you can find it at the top left corner of the canvas). Click on the “Rename” option. The following dialog box should pop up.
Enter an appropriate name for the subcircuit and hit ok. Your subcircuit should now be renamed. Notice how the tab’s name has changed from “New circuit” to “xor” in the screenshot below.
Part 7: Saving Circuits
Now let’s save our circuit.
Remeber to always save frequently. While working on larger projects, it would be a good idea to use version control software (CircuitSim saves circuits as JSON, so any standard VCS should work fine).
Also make sure to test previous saves to ensure that they work. You can never be too careful.
The save process is self explanatory. Use whatever filename you’d like.
In the example below, I saved this XOR subcircuit as
.sim is the file extension used by CircuitSim to store circuit files.
Part 8: Testing your circuit
Now that we’ve completed our circuit, let’s test it.
After going into “Click Mode’, you can change the inputs. After
checking every possible combination of the
b inputs against
their correct values in the truth table, I’m confident this XOR works.
Extra: Why bother creating an XOR with ANDs and ORs?
Any gate can be created with ANDs, ORs, and NOTs. The XOR gate we just built is a neat application of this idea.
Additionaly, in digital logic design, minimizing the number of transistors to perform a certain function is always top priority.
If you look at the circuit diagram for any logic gate, you will notice that these gates share a lot of the same “building blocks”. By using parts of one gate to build another, you can reduce your overall transistor count and power consumption.
This kind of optimization isn’t possible if you view a logic gate as a monolithic entity that can’t be broken down.
Previous tutorial: Tutorial: 1: My First Circuit
Next tutorial: Tutorial: 3: Creating a circuit with Tunnels and Splitters