The cs355sim program reads a circuit definition from an input file and builds the specified digital circuit. It then creates a window and displays the circuit in that window. You can then interact with the circuit by toggling switches in the circuit.
2. Setup your account to use EDiSim
3. Example of Using the Logic Simulator
Begin to familiarize yourself by performing the following experiment
by getting the file "and"
and saving it into your
cs355 project directory.
To save an example from your browser do the following:
Right click on the link -> Save Link As Select a folder to save the file Click OK to save.After you saved a copy into your own directory, you can run the circuit by using cs355sim. If you had called your file "allgates", the command you use to run the circuit is:
cs355sim and
After invoking cs355sim and, a window will pop up and in the window you will see a circuit with 2 switches in the left column and an AND gate in the center column. The rightmost column contains a `probe', which are bascially a light that goes on (filled) if the signal being probed is equal to `1' and off (not filled) if it is equal to `0'.
You can now interact with the circuit by toggling the switches in the circuit.
You build a digital circuit by:
The input line for the logic simulator follows a very simple syntax:
Component Coordinates Inputs Outputs ;where:
A connection is made when the same name is used.
A switch is the only way to obtain input into a circuit. A switch is created with the command ``Switch'', see for an example in the file and.
You will see these lines:
Switch aa sw_0 '0' ZERO; Switch aa sw_1 '1' ONE;Each switch is associated with a key on the keyboard (given in the definition). The first switch you create is associated with the `0' key and the second switch created corresponds to key `1'. You can toggle the switch by hitting the corresponding key on your keyboard, but make sure your mouse cursor is in the circuit window when you do so. Try pressing the `0' and `1' keys and see the effects on the circuit.
Run your saved circuit (in your cs355 project directory) using:
cs355sim andAnd toggle the keys '0' and '1'. Try it !!!
The upper left coordinate is `aa', the one at it's right is `ab',
and the one below it is `ba', and so on:
Each coordinate identifies a ``square'' that you can use to
place (one or more) components.
For example:
Range coordinate
Example:
This will make a Switch component that will occupy the
canvas between the coordinates "aa" and "bb"
(it will occupy the coordinates "aa", "ab", "ba", and "bb") -
so you will have a bigger switch drawn
--- but it will do the same thing !!!).
Some components can have one or more inputs.
Although most components you find in this table have one outputs,
later on you will see components that have multiple outputs.
To make a circuit that cs355sim understand,
each output signal is given an unique name.
Later, when you want to connect a given output signal to the input of
a component, you identify the output signal with its unique name.
A component name in cs355sim is
an identifier that begins with a capital letter,
optionally followed by one or more letter, digit, or `_'
(underscore).
The definition of a component is ended by a semi-colon.
A signal name in cs355sim is
an identifier that begins with a letter
(I recommend always use a lower case to distinguish from component)
optionally followed by one or more letter, digit, or `_'
(underscore).
Again, to connect the output of a component X
to the input of another component Y, do:
Example 2:
Hint:
give signals that you probe in your program with a meaningful name
to help debugging.
The program above is found in `example2' in the demo directory:
You can run it and see the effect with this command:
(Make sure you have setup your account:
click here to run cs355 circuits.)
Toggle the key '3' and see the effect.
Note:
notice the little `3' at the upper left hand corner in the switch.
This indicates that the switch is associated with the key `3'.
Example 3:
(Make sure you have setup your account:
click here to run cs355 circuits.)
You can play with any digital circuit in the demo directory by copying
it over to your directory and run cs355sim filename.
You can build more complex components from basic gates and
use the complex component in further design using the macros
facility in cs355sim.
The syntax of a macros definition is:
Example:
It makes this circut (discussed in class):
NOTES:
The Input-signals of the
Full_Adder
component are: CarryIn, a and b
while the output signals are CarryOut and Sum.
You can use the input signals
(like an input parameter) as inputs to
circuit components.
Notice that the circuit components
in the body of the macros follows
the same structure
as the components you used to construct a circuit.
The macro component will be displayed as a
rectangle and
the coordinate used in the circuit components of a macro
are used to place the component
inside the rectangle that
represents the macro.
Hint:
What you need to look out for when defining a macro:
(because if you do not use some input signal, why would you want
it as input ? You can just as well design the component without
that input if that input was not used at all inside the component...)
If you use an output signal as output of
more than one circuit,
your circuit will definitively not work
(because the outputs are connected together).
Check this fact, because if you have some
unconnected output,
your component
will not work correctly.
One tell-tale sign
of unconnected outputs
are "slashes" in probes.
A slash is an
"unknown" value.
Unconnected outputs will generate
unknown values.
After you define a macro, you can use the component
defined as a macro exactly like an ordinary component...
except:
For example, to use the Full_Adder
component, use the following syntax:
Example of a circuit file that uses the Full_Adder macro:
(The coordinate "ab-cd" is a range coordinate
- it means: occupy the coordinates
between "ab" upto "cd"; i.e.: ab, ac, ad, bb, bc, bd, cb, cc, cd, db, dc,
dd)
(You can cut and paste the above circuit into a file and run it
with cs355sim and see the circuit).
Clearly, a macro definition is similar to a method definition in Java
and you can "invoke" a macro similar to invoking a method in Java.
Macros can help you simply your circuit design
When you want to make many copies of the same component,
you need only define the component once as a macros and
create it as many times as you want.
The demo cs355sim file `4-bit-adder'
( click here)
illustrate the use of macros clearly.
We first define a Full Adder macro at the start of the circuit program,
then later, we define 4 Full Adders to make a 4 bit adder circuit.
Macros will also allow you to simplify the circuit design.
In the later project assignments, I will adopt a "plug-and-play" approach.
I will give you a cs355sim circuit file that contains all the necessary
switches, probes and connections to a component that you need to design.
For these projects, you will need to design a macro that can be used to
"plug" into the circuit file given to you.
The circuit has all the controls you need to test the circuit for correctness.
The EDiSim simulation system
provides a short-hand notation to
specify an
array of signals:
In project 2, where you must
make a 4 bit multiplier circuit; the
circuit has 2 four-bits inputs and
an 8 bits output:
The macro of this
4-bit multiply circuit can be
defined as follows:
EDiSim provises a
short-hand (array) notation to
write the signals:
Summary:
EDiSim reports the error:
6. Coordinate System in cs355sim
EDiSim defines a big canvas divided into
squares and you can put one or more components
in any square.
When you put multiple components in one square,
the componets will displayed vertically stacked.
The coordinate is given as (row,column) and you can either use a
single letter to indicate a row or a column position.
So the coordinate grid consists of 26x26 squares: a, b, c, d, ..., z.
(You can use capital letters or digits as coordinates but I recommend using
lower case letter).
Switch aa sw0 '0' ZERO;
You can put as many components in a square as you wish:
Switch aa sw0 '0' ZERO;
Switch aa sw1 '1' ONE;
coord1-coord2
Switch aa-bb sw0 ZERO;
7. Some Basic Components
The following table shows a partial list of the available components
in the logic simulator (later project handouts will explain
new components when they are needed).
Component Command line syntax
Notes
Switch Switch Coord Output InitValue;
Toggle switch with key, 1 output
Probe Probe Coord Input;
1 input & no output
Not Not Coord Input Output;
1 input & 1 output
And And Coord Inputs Output;
Many inputs & 1 output
Or Or Coord Inputs Output;
Many inputs & 1 output
Nand Nand Coord Inputs Output;
Many inputs & 1 output
Nor Nor Coord Inputs Output;
Many inputs & 1 output
8. Examples
Example 1:
Switch aa sw0 '5' ONE;
defines a switch located at grid coordinate (a,a).
This switch is associated with the key '5'.
The output of this switch is named `sw0' and the switch is
initially on (ONE).
Only switches can have initial values.
As initial values for a switch, you can use ZERO (off) or ONE (on).
Switch aa sw0 '3' ZERO;
Probe ab sw0;
Here, we connect the output of the switch `sw0' to the input
of a probe.
Note: the probe will have the label with the name "sw0" that
is equal to the signal name.
/home/cs355001/demo/circuits/example2
cs355sim /home/cs355001/demo/circuits/example2
Switch aa sw_0 '0' ONE;
Switch ba sw_1 '1' ONE;
Switch ca sw_2 '2' ONE;
And bb sw_0 sw_1 sw_2 out;
Probe bc out;
defines three switches located at grid coordinates
(a,a), (b,a) and (c,a).
The output of switches one, two and three are named
`sw_0', `sw_1' and `sw_2', respectively
and they are all initially on.
At coordinate (b,b), an `AND' gate is placed which has three inputs:
`sw_0', `sw_1' and `sw_2' (the outputs of the switches).
The output of the AND gate is named `out'.
A probe is placed at coordinate (b,c) which use input `out' (the output
of the AND gate).
Thus, the probe will display the output of the AND gate.
This circuit is found in file `example3' in the demo directory;
you can run it with:
cs355sim /home/cs355001/demo/circuits/example3
9. Comments
You can have C-type comments /* ... */ embedded in the file.
For example, the `allgates' circuit file contains the following:
/* This is a comment */
Switch aa sw_0 '0' ZERO;
Switch ca sw_1 '1' ONE;
And bb sw_0 sw_1 out;
Probe bc out;
10. Macros
Later in the course (in project 2), you will need
macros
to help you build more complex circuits.
You may not need it now, just keep these information handy and
read about it when you will need it.
Define ComponentName INPUT_SIGNALS | OUTPUT_SIGNALS ;
Body (consisting of circuit components)
// It can use INPUTS as inputs
// It must produce all OUTPUTS specified
Endef;
Define Full_Adder CarryIn a b | CarryOut Sum;
Xor aa a b x;
Xor ab x CarryIn Sum;
And bb a b y;
And cb CarryIn x z;
Or bc-cc y z CarryOut;
Endef;
Using a macro
Full_Adder Coord Carry-in a b | Carry-out Sum ;
/* Defines a macro */
Define Full_Adder CarryIn a b | CarryOut Sum;
Xor aa a b x;
Xor ab x CarryIn Sum;
And bb a b y;
And cb CarryIn x z;
Or bc-cc y z CarryOut;
Endef;
Switch aa Cin '0' ZERO;
Switch ba a '1' ZERO;
Switch ca b '2' ZERO;
/* Create a component that was defined using a macro */
Full_Adder ab-cd Cin a b | sum Cout;
Probe ae sum;
Probe be Cout;
11. Array notation for signals
Some circuits have/use a input/output signals that
represent a number.
A number consists of
n binary digits --
each digit is one signal
Notation Meaning
-------------------+-----------------------
x[0-3] | x[0] x[1] x[2] x[3]
y[2-0] | y[2] y[1] y[0]
Define Mult4 x3 x2 x1 x0 y3 y2 y1 y0 | z7 z6 z5 z4 z3 z2 z1 z0;
...
Circuit uses signals x3 x2 x1 x0 y3 y2 y1 y0 as input signals
Circuit uses singals z7 z6 z5 z4 z3 z2 z1 z0 as output signals
...
Endef;
Define Mult4 x[3..0] y[3..0] | z[7..0];
...
Circuit uses signals x[3] x[2] x[1] x[0] y[3] y[2] y[1] y[0] as input signals
Circuit uses singals z[7] z[6] z[5] z[4] z[3] z[2] z[1] z[0] as output signals
...
Endef;
This notation for signals: is the same as writing:
var[0..3] var[0] var[1] var[2] var[3]
var[3..1] var[3] var[2] var[1]
12. Common Errors.
cs355sim circuitFile > error
vi error (or use any other editor)
Search for the string: "Error" or "Incorrect" will quickly indentify
the location of the error.
The following is a list of some common errors made by students
from previous courses....
........ "ZZ..variableName" unconnected; UNKNOWN assumed.
Check the spelling of your variable "variableName"
(case sensitive).
If the variable was an array variable, make sure it has [ ].