In this lab, you'll learn how to use Digital, a digital logic designer and circuit simulator designed for educational purposes. You'll also learn about some basic conventions of circuits, such as power, ground, wires, mechanical switch, and light-emitting diode (LED).
Contents
As we did in COMP 211, we will clone GitHub repositories via SSH. If you have already generated an SSH key on your computer (not inside the COMP 211 container) and connected it to your GitHub account, skip to Clone repo.
To generate a new SSH key, follow these instructions. Do only the steps in the section named "Generating a new SSH key".
On step 2, accept the default file location by pressing Enter. On step 3, when prompted for a passphrase, you may use no passphrase by simply pressing Enter twice.
Then, follow these instructions to add your SSH public key to your GitHub account.
Run git clone <link>
, where <link>
is the SSH link (not HTTPS) to your Lab 0 repository.
Digital allows us to design, simulate, and test circuits.
A Java Runtime Environment (at least JRE 8) is required to run Digital. You should already have this if you're using the same computer you used in COMP 210 or COMP 301. If not, search online for installation instructions for your specific OS and install. You can verify that it works and check its version with java --version
.
To install Digital,
- Go to Digital's GitHub page.
- Click the green Download button at the top of the README (you may need to scroll down slightly).
- Unzip the downloaded
.zip
file. - Move the extracted folder (not the
.zip
file) to an easily accessible location on your computer. You will need to access this frequently.
To start Digital, double-click Digital.exe
.
To start Digital, run java -jar PATH/TO/Digital.jar
, where PATH/TO/Digital.jar
is the path to your Digital.jar
file.
To start Digital without having to type the path to Digital.jar
, alias the command. Run echo "alias digital=\"java -jar ABSOLUTE_PATH_TO_DIGITAL_JAR\"" >> $HOME/.zshrc
, replacing ABSOLUTE_PATH_TO_DIGITAL_JAR
with your absolute path to Digital.jar
. Restart your terminal after running this command.
macOS's default shell is zsh, so this alias command is appended to ~/.zshrc
. If your default shell is not zsh (check with echo $SHELL
), replace .zshrc
with your shell's configuration file (e.g., .bashrc
for bash).
You can now start Digital from any directory by running digital
. You can also open a specific circuit file by running digital PATH/TO/circuit.dig
.
Fix for potential bug where Open menu does not display .dig files
If you encounter an uncommon bug where the Open menu does not display .dig
files, open a .dig
file by passing it as a command-line argument. For example, if you want to open the file ~/circuit.dig
, run java -jar Digital.jar ~/circuit.dig
(or digital ~/circuit.dig
if you did the optional steps above). You can drag a file from Finder to the terminal to automatically paste its absolute path.
The first time you start Digital, you will be greeted with a built-in tutorial. If you do not see it, start it by clicking View > Start Tutorial.
Complete the tutorial, which shows you how to build and simulate a simple circuit.
As shown in the tutorial, you can right-click a component to open a menu and configure settings for that component. The menu also contains a "Help" button that opens documentation for that component. Whenever you don't know what a component does or need to review, please refer to the documentation. You can also hover your mouse over a component to see its functionality or over a specific input (blue dot) or output (red dot) of the component to see information about it.
You may also download a PDF containing all documentation here.
To open settings, click Edit > Settings.
Click View > Component Tree View. This menu may make it easier for you to access components.
To make this menu open by default, click Edit > Settings > Component tree view is visible at startup.
We will soon learn about the Tunnel component, which is very frequently used.
To make working with tunnels more convenient, disable the setting "Show dialog for automatic renaming of tunnels" (which is on by default).
macOS users, if control-click does not work for you, try right clicking with two-finger tap. If this is not already enabled, then do the following:
- Open your computer settings.
- Search for "Trackpad" and press Enter.
- Set secondary click to "Click or Tap with Two Fingers".
In Digital, open example.dig. This is a simple circuit that contains a light-emitting diode (LED) and a mechanical switch.
Simulate the circuit by pressing the triangular Play button at the top. Then, click the switch to toggle it from open to closed, and note how this affects the LED.
To read about how an LED works, right-click the LED component and click "Help". You may also want to read about the other components Supply voltage (logic 1 or) and Ground (logic 0).
Nothing needs to be submitted for this part, but make sure you understand the circuit to be able to complete the next part.
In Digital, open and.dig.
In this file, you'll slightly enhance the previous circuit. Specifically, create a circuit that acts like a "mechanical AND gate", where the LED turns on only if both switches are in the closed position. You need only add wires (i.e., wire the two switches in series). Don't use any logic gates or any additional components.
Don't delete or rename the switches. Our test cases in the green Test Case component require the switches to have the exact names given in the template file.
Click here for instructions if you've already deleted or renamed the switches
If you have already deleted or renamed the switches, then either revert changes in your repo (git restore .
) or add the switches back.
If you decide to add the switches back, the Switch component can be found at Components > Switches > Switch. Additionally, right-click a switch, select "Advanced", check "Switch behaves like an input", and name it switch_0
. Do the same for the other switch, but name it switch_1
.
To manually verify that your circuit works according to the specification above, click the triangular Play button at the top and test your circuit manually.
To automatically test your circuit, click this button at the top to run our tests in the green Test Case component.
You should then see a menu like this:
If you don't see this menu and receive an error, your circuit is invalid (similar to a compilation error when coding). Please read the error message and try to solve the issue.
Common errors
- Test signal x not found in the circuit!
- This error means that the Test Case component expects an input or output component named "x", which doesn't exist in your circuit. Since the template files always label the input/output components with the correct names, this probably means you renamed an input or output component. Note that the names are case-sensitive. To resolve this, if you recognize the name in the error message and know which input or output you renamed, rename it to the proper name given in the error message. If not, look at the template file in your repo's initial commit, and figure out what you changed. Lastly, to view all expected input and output names in a file, right-click the Test Case component, and click Edit (but don't make any changes). The first row contains all expected input and output names.
The menu is essentially a truth table!
In this table, the switch_0
and switch_1
columns are inputs, and LED
is the output that is checked. Each row represents a single test case. For each test case, we provide hardcoded inputs and the expected output. Digital then simulates the circuit with the given inputs and checks whether the output is correct or not. If you click on L2 or any other row, you'll see how this works.
If a test case fails, the menu would look like this:
In L4, the "E: Z / F: 1" means that when the circuit is given the inputs in L4, the expected output is Z, but the actual output is 1. For this circuit or more complicated circuits in the future, if you fail a test case, you could click it (here, L4) to see what happens in the circuit that causes the test failure.
Note: Z is a state that is neither logic 0 nor logic 1. You will learn more about this in a later lecture. All you need to know for now is that if the LED is off, its state is Z.