| JLS does not support the Macintosh right-click hack for one-button mice. Use keyboard accelerators (hot keys) instead. |
This tutorial will guide you through the construction and testing of four circuits:
The first thing you need to do is create a new circuit and editor. Pull down the File menu and select New. A dialog box will appear. Type in any name you like for your circuit and hit return(enter) or click on OK. Give it a few seconds as a lot needs to be done and it takes a while over the network (including loading images).
The circuit we will draw and eventually simulate looks like:
so lets get started.
You will see a large drawing area and a toolbar full of logic elements. Click on the OR gate. A dialog box will appear that will allow you to customize the gate. The gate we want is the default case (2 inputs, one gate, facing right), so simply click on OK.
The symbol for the OR gate should now appear, outlined in pink. It will follow the movement of the mouse, so move it to the center of the drawing area and left click to place it (right clicking will cancel the creation of the gate). Notice that when you are placing the gate there is a message with a yellow background in the upper left of the window that guides you. You can check this at any time if you are unsure what to do next or what "state" the circuit editor is in.
Once you've placed the gate, move the cursor around the window. Note that whenever you move the cursor over the gate its bounding box becomes visible. Move the cursor over the gate, press and hold the left mouse button, and drag the gate around the screen. Releasing the mouse button will place the gate at its current location.
Next select a NOT gate, say OK to the default characteristics, and get ready to place it. You have a couple of options. You can place it near the OR gate and then create a wire to connect it to the OR gate. Alternatively you can move the output of the NOT gate so that it touches one of the inputs of the OR gate - this will automatically connect them. We'll automatically connect them right now and draw wires later.
Drag the NOT gate so that its output touches the lower input of the OR gate. Notice that the output/input become green when they touch. This means that a connection is possible. Many connections are not possible (e.g., connecting the outputs of two gates) and if you try to make one you won't get a green. Once you get a green, left click to place the NOT gate and automatically connect it to the OR gate.
If you'd now like the NOT gate to be a little farther away from the OR gate, just move the cursor over it, press and old the left mouse button, and drag the NOT gate wherever you want it. Notice that there is a wire connecting the two gates that follows the NOT gate as you drag it around.
At this point we have all the gates we need for the boolean expression. The unattached input of the OR gate is A and the input of the NOT gate is B. Lets test it by connecting constant values (0's or 1's) to the inputs.
We'll first place and connect two elements that generate constant values in our circuit. Pick the image from the toolbar that is a small rectangle with the letter N inside and a line sticking out the right end. You'll get a dialog box in which you can set the constant value, and there are two ways to do it. One is to type the value into the box indicated. The other is to click on the black triangle and get a keypad that you can click in the digits of the value. Try both if you like. Click OK when you have picked a value (0 or 1) and place the element a couple of inches to the left of the NOT gate (don't connect it automatically). This time we will connect it by drawing a wire.
Move the cursor into an open area and right click. A menu will pop up - select wire(s). When you do, the menu will disappear and a small circle will appear. This is the beginning of a wire. Move the cursor (and the circle) over the output circle of the constant element you just placed. When it turns green, left click and then move the cursor to draw the other end of the wire. We'll make this a segmented wire (just for demonstration purposes) for now. Drag the new end of the wire someplace and left click. Drag again and left click several times to draw a wire with lots of segments. Don't worry about neatness. Finally drag the new end to the input of the NOT gate and left click again. This will complete the wire connecting the constant generator and the NOT gate.
The wire you just drew probably wanders all over the place. Lets clean it up. Drag the cursor over any part of the wire (avoid corners for now). Notice that that part of the wire turns pink when the cursor is over it - that how you know the editor is selecting it. Select some middle segment of your wire and right click. Pick delete from the menu that appears and watch that segment of the wire disappear. If you move the cursor onto a corner of your wire a little pink circle will appear. If you right click at this time and choose delete you'll remove the corner and both line segments connected at that point. Keep deleting parts of your wire until there is little (but not nothing) left. Then grab a dangling end of your wire and drag it onto another dangling end (or onto a gate input or output). Release the mouse button to re-connect.
Now create another constant element and connect it to the free input of the OR gate. Finally, begin a wire at the output of the OR gate. Draw a single wire segment a couple of inches long to the right, left click to place the corner, and then right click to stop drawing wire segments. Be sure to left click before right clicking.
We now have a complete circuit that we can test with the given input values. To test it, pull down the Simulator menu and pick Run. This will run the simulator on your circuit.
The simulator runs as long as some value could possibly change in the circuit. Once no more changes are possible, the simulator stops. At this point the color of a wire is black if it has zero on it, red if it is a one (or more correctly, non-zero - this applies to wire "bundles", which is a single "line" that represents several wires bundled together).
The values on the wires obviously depend on the values of the constant value elements you chose for your circuit, so verify that the wire values are right. You can also move the cursor over a wire and see the current value in the cyan message bar above the circuit.
All gates have a built-in propagation delay that are used during simulation (wires have no delay). It can be interesting to see the time history of each signal as it propagates through the circuit. An interesting case is when A (the upper input to the OR gate) is 0 and B (the input to the NOT gate) is 1. This will cause the output of the OR gate to temporarily have the wrong value as the 1 propagates through the NOT gate and then the OR gate.
Lets make the inputs have the right values (if they already do, then just follow along anyway). Right click on the constant generating element for the upper OR input. One way to change the value is to either cut or delete the element and create a new one with the value 0. The other way (try this way) is to select the modify menu option. This will pop up a dialog box in which you can change the value. Make the value be 0 and click OK. Now make the input to the NOT gate be 1 by whatever technique you choose.
To see the time history of the value on a wire you must attach a "probe"
to the wire.
Move the cursor onto the output wire, right click, and select the
Attach Probe option.
A dialog box will appear so you can give a name to the probe.
Type in something descriptive, like "output".
When done you'll see the name you typed in blue
above the wire, thereby indicating that a probe is now connected.
Your circuit should now look like this:
Now pull down the Simulator menu and select Show. The bottom of the window will now show simulator controls. Put the cursor on the divider between the simulator controls and the circuit editing window and drag it up to show more of the simulator. Below the buttons will appear an area where signal traces will appear when the simulator is run again. Show about an inch or so of this white trace area, then click on the Restart button. This will re-initialize the circuit and run the simulator again. You should now see a trace of the output wire, and in particular see that it started at 0, became 1 for a short time, and then went back to 0, which is the correct final value for this circuit. Move the mouse over the trace to see the exact timing of each signal change.
It is often handy to be able to run the simulator for a little while, stop, start again for a little while, etc. To do this, click on Step now. The simulator will run for one unit of time (you can assume this unit to be whatever you like - a nanosecond, picosecond). Each click on the button will run the simulator for another time unit. If this is too slow, change the value in the Step box at the top right of the simulator window. Then each click of the button will run the simulator for that length of time.
Lets change the propagation delays of the two gates in the circuit. Move the cursor over one of them and right click. Pick Change Timing, put a new value in the value box, and click OK. Change the other gate's propagation delay similarly.
To run the simulator with these new values, first make sure that the previous simulation was done. If you had stepped it for a while but not to the end, click on the Stop button. Now either Restart the simulator, or Step through it and observe the signal trace.
This concludes the basic tutorial. If you are still interested, lets construct another more complex circuit that will demonstrate some of the more complex logic elements.
Lets build a simple 4-bit counter.
We could build the whole thing from gates and wires, but we'll make it a
lot simpler by using a register, and adder, and a clock.
Here's what it will look like:
If you just finished the previous tutorial, then lets hide the simulator window so we have more room to work. To do so, select Hide from the Simulator menu.
Now lets get rid of the previous circuit. You have several options.
Select the register element from the toolbar (near the middle, looks like a D flip-flop). Pick Neg Trig, give it a name, set the bits to 4 and click on OK. Place it in the middle somewhere. You now have a 4-bit register constructed from four negative-edge triggered D flip-flops.
Next select an adder element from the toolbar (the icon with the plus sign in the middle). Give it 4 bits, then place it to the right of the register.
Draw a wire from the Q output of the register to either the A or B input of the adder. This wire is actually a bundle of four wires - move the cursor over the wire and check the description in the cyan message area below the tool bar.
Create a constant element with value 1 and connect it to the other input of the adder. Create a constant element with value 0 and connect it to the Cin (carry in) input of the adder.
Connect the S output of the adder to the D input of the register with a multi-segment wire.
We now need to cycle the C input of the register to make the circuit count. The cycle time must be long enough get a value into and out of the register and through the adder. Check the propogation delays of the elements (50 for the register, 120 for the adder), so the cycle time must be at least 50+120 = 170. Its not a good idea to have the cycle time be exactly the propagation delay of the circuit (in fact the simulator actions will be undefined if you do), so we'll create a clock element with a cycle time larger than 170.
Select the clock element (just right of the adder on the toolbar), and set the cycle time to 175. You can leave the "One Time" set to 1 or change it to any value less than 175. The "One Time" is the lenght of time the clock output will be a 1. The remaining time the clock will be 0. Connect the clock to the C input of the register, drag the clock to the left a couple of inches, then put a probe on the wire connecting the clock and the register (call it "clock"!).
We could put a probe on hte wire connected to the D output of the register in order to trace the value in the register. However, a register (and a few other elements, like memory) can be watched, which will also produce a trace of the value in the register. Lets make the register watched by right clicking on it and selecting the Watch Element option. Notice that the element turns blue when the cursor is not on it. This indicates that it is being "watched".
We'll step the simulator for now since otherwise it will run for a long, long time (since the clock will keep cycling). Since the cycle time is long, it will be a pain to step one time unit at a time, so set the step time to something like 10 to make things go faster. Now start clicking the Step button. The signal traces will show the clock cycling and the output of the register increasing as you progress.
Click the Stop button when you've seen enough.
Now select the "stop" element from the toolbar (the one looks like a stop sign) and connect any of its four inputs to the Cout (carry out) output of the adder. The stop element will stop the simulator when its input becomes a one. Now click the Restart button to run the simulator. It will simulate until the counter becomes 15 and the carry out becomes 1, then stop automatically.
The signal trace ran off the screen, but it can be compressed to fit. Change the value in the "Scale Factor" box to 5 and click on Apply.
The values in the signal trace are in decimal (base 10). To see them in binary or hex, click on the appropriate button below the scale factor.
To re-arrange the stacking order of the traces, right click on the probe name of any signal and select the desired option.
This concludes the second tutorial. If you are still interested, lets construct a circuit containing subcircuits - a full adder formed from two half adders.
Get rid of the counter circuit by closing it, then create a new circuit with the name "ha" (for half adder).
Now we'll construct the half adder circuit.
This is simply an XOR gate for the sum and an AND gate for the carry,
both connected to the same two inputs, and looks like this:
Since this is a subcircuit, we will eventually need a way to refer to the inputs and outputs of this subcircuit. Thats what the symbols labelled "A", "B", "Sum" and "Carry" are. These are input and output "pins". Find the symbols in the toolbar and create them by filling in the names in the dialog boxes when they appear. Then create the XOR and AND gates and connect the outputs of the gates to the inputs of the "Sum" and "Carry" output pins.
The wiring between the input pins A and B and the gates is slightly more complex this time because we have to connect one output (e.g., A) to two inputs (the XOR gate and the AND gate). Its easy to do. First connect the output of A to the input of the XOR by drawing a wire. Now start a new wire by touching the existing wire (A to XOR) somewhere along its length. The wire start circle and the wire will become green when a connection is possible. Left click to connect, then finish the wire to the input of the AND gate. Use the same process to finish connecting B.
This completes the subcircuit. Now lets create another circuit, a full adder, that includes to half adder subcircuits. Without closing the "ha" circuit create a new circuit called "fa". Note the tabs showing that both circuits are avialable to be editted simply by clicking on the associated tag.
The circuit we will construct looks like this:
The two large squares represent "imported" copies of the half adder circuit we just created. These are not links to the half adder, but two distinct copies. We could even change one of the half adder copies and leave the other alone if we wanted to. Also note that a subsequent change to the original half adder circuit will NOT be reflected in the imported copies.
Lets first import the two half adders, then you can hook things up. Click on the Import pull-down list at the right end of the toolbar. The circuit "ha" will appear. Select it. Type in the name "upper" in the dialog box and place the resulting element somewhere in the drawing area. Now do the same thing again, this time giving it the name "lower". "upper" and "lower" are the local names of the subcircuits in the larger "fa" circuit. Now add the OR gate and hook things up.
Just for fun lets modify one of the imported half adders by replacing the XOR gate with the AND/OR/NOT equivalent. Right click on the "upper" element and select modify. Note that the imported circuit appears, and that there is now a tab with the label "upper in fa". This clearly identifies the circuit you are editting as the one called "upper", which is a subcircuit of "fa". There is no longer any association of the subcircuit with the original "ha" circuit.
Now delete the XOR gate by right clicking on it and selecting delete. Then add the equivalent AND, OR and NOT gates. You'll probably have to move things around to make room. When you are done you must close the subcircuit circuit in order to make any changes to the main circuit that contains it.
Now test your full adder circuit by attaching constant inputs and putting probes on the outputs. It should be interesting to see the resulting output signal traces with all the various gate propagation delays.
If you have time, try creating an N-bit adder circuit using full-adder subcircuits. Subcircuits can be arbitrarily nested!
This concludes the JLS tutorial. You might want to try out two cool features in JLS - state machines and truth tables. Just click on the appropriate icon in the toolbar (just to the right of the pause and stop icons) and then click on the help button that appears in the dialog that appears.