INTRODUCTION TO THE SIM SOFTWARE PACKAGE Simulation systems are frequently used to design and evaluate digital circuits. In this course, you will use a software package named "sim" to study combinational and sequential circuits. Input to the simulator is a C++ program which describes each component of the circuit being simulated and the connections betweens the components. Each component is given as: component_type ( row_col_position, inputs, outputs, miscellaneous ); All component names begin with a capital letter. Multiple inputs are grouped as a list inside matching parentheses; not all components use all fields. The position of a component is based on a coordinate system where the rows are often specified using numbers (beginning with 1) and the columns are often specified using letters (beginning with a). Thus, the position in the upper left corner is "1a". Several components may be placed in the same position. Some of the commonly used components are: Not gate -- has a single input and output And gate -- has a variable number of inputs with a single output Or gate -- has a variable number of inputs with a single output Switch -- has no inputs but has a single output and an associated key Probe -- has only a single input but has no outputs Switches are used to generate input values in order to test a function. Each switch is controlled from the keyboard by a specified key. The value produced by a switch (a "0" or a "1") can be toggled by touching the appropriate key. The mouse arrow must be located inside the simulator window for the keys to control the simulator. A switch displays its current value. Probes are used to check the output values produced by a function. The value displayed by each probe is based on the input values supplied by the switches and the circuit to which the probe is connected. Data objects are declared to be type "Signal". The "sim" package uses the X11 graphical user interface and it must be executed on a server running SunOS, such as "north". In order for the shell to locate the executable version of "sim", you must add the following line to your ".personal" file: setenv PATH {$PATH}:/user/csearch/bin If your ".personal" file contains other "setenv PATH" statements, insert this new statement following the existing ones. To use "sim" during your current interactive session, execute the following command: source .personal It will not be necessary to repeat these steps during subsequent sessions. Consider the following example: cat sim.example.c /**************************************************************************** Implement the Boolean function F = AB' + BC'D' ****************************************************************************/ #include // Interface to the "sim" package void simnet() // Function must be named "simnet" { Signal a, b, c, d, F; // Switch and output objects Signal notb, notc, notd; Signal and1, and2; // Intermediate objects // Components and interconnections Switch ( "1a", a, 'a' ); // Switch a controlled by 'a' key Switch ( "2a", b, 'b' ); // Switch b controlled by 'b' key Switch ( "3a", c, 'c' ); // Switch c controlled by 'c' key Switch ( "4a", d, 'd' ); // Switch d controlled by 'd' key Not ( "2b", b, notb ); // NOT gates Not ( "3b", c, notc ); Not ( "4b", d, notd ); And ( "2c", (a, notb), and1 ); // AND gates And ( "3c", (b, notc, notd), and2 ); Or ( "2d", (and1, and2), F ); // OR gate Probe ( "2e", F ); // Probe } The following command could be used to execute "sim": sim sim.example.c While the simulator is running, window overlays sometimes erase part of the "sim" display. This can be redrawn by touching the "5" key on the numeric keypad. The simulation can be restarted with initial input values by touching the "F1" function key. You may exit the simulator by touching the "F10" function key while the mouse is positioned inside the simulator window. You may also exit by "quitting" on the window. Note that the simulator creates a file named "simex" which is equivalent to "a.out". You may rerun or remove it as you wish. Information about a specific component may be obtained with the command: simhelp component_name The command "simhelp" without any arguments will give a list of available components. Additional "sim" Features A circuit consists of a set of components, with signals providing the connection between components. Since "sim" is based on C++, you must declare all signals before they may be used. Some examples: Signal A; // 1-bit signal (default) Signal B (1); // 1-bit signal Signal C (4); // 4-bit signal Signal D (2, "enable"); // 2-bit signal (labeled as "enable") Individual signals within multi-bit signals may be accessed using array-like notation. For example, "C[3]" is a reference to the most significant bit of the 4-bit signal "C", and "C[0]" is a reference to the least significant bit. An optional label may be specified; that label will appear in the X display when the 'F5' function key is toggled. As a convenience, "sim" supports the "Sig" notation. For example: Sig (E,8); // same as "Signal E (8, "E");" -- name and label the same At every instant, each signal has a value from the set listed below. The meaning of each value is given, along with the way in which a probe will display that value. UNINITIALIZED: not initialized ("/") ZERO: de-asserted (background color) ONE: asserted (foreground color) XXX: in transition ("X") HIZ: high impedance state ("-") If a specific value is needed as input to a component, the constant signals "Zero" and "One" should be used, rather than the values listed above. Signals may be grouped together into larger units (busses, essentially) using parentheses and commas (and other overloaded operator symbols). Assuming the declarations of "A", "B", "C" and "D" given above: (A, B, Zero, Zero) // 4-bit signal (A, B, C, D) // 8-bit signal In the second example, the last two bits of the signal are "D[1]" and "D[0]". Components must also be declared; the declaration specifies the position of the component in the display, its inputs and its outputs. The position of a component can be specified in several different ways. The most common: Probe ("3c", MuxOut); Probe ((SD("3c-4c"), "Mux Output"), MuxOut); The row and column are specified as a character string: row 3 and column c of the display, in the first example. In the second example, the declaration specifies the position as a range (rows 3 and 4, column c), and specifies a label for that component in the display. Using the "sim" Package The "sim" package is available only on the CSE server named "north". Thus, you will need to remotely access that server in order to execute "sim". The "sim" package uses the X Window system to display the simulated circuit, so any computer that you wish to use to access "north" must support the X Window system. The computers in the CSE labs all have the necessary software. The Linux machines use "ssh", and the Windows machines use "ssh" and "X-Win32". There is more information available on the CSE website: http://www.cse.msu.edu/facility/howto/ssh/ You can also work from other computers, including your computer at home, if you have access to the X Window system. To run "sim" from a CSE Linux workstation: Open a terminal window Enter "ssh -X north" Enter "sim ...." To run "sim" from a CSE Windows workstation: Select Start, then X-Win32 (click OK if necessary) Select Start, then Secure Shell Client Under "ssh", select Edit, Settings, Tunnelling, TunnelX11 connections, OK Connect to "north" Enter "sim ...." To run "sim" at home, you will need to use a process similar to one of the two above. For a Windows machine, you will need to install an X package (if you have not already done so). There are a number of different X packages available for PCs. Several commercial packages and open source packages are available on the web, including sites that permit downloads of demo versions of the software: http://sourceforge.net/projects/xming (Xming) http://www.starnet.com/products/ (X-Win32) http://tnt.microimages.com/mix/ (MI/X) http://www.labf.com/ (Winaxe) http://xfree86.cygwin.com/ (Cygwin/XFree86) Each package has different installation instructions, so you will need to consult the documentation for the particular website. Similarly, each package has different configuration instructions. A few comments about running "sim" from home: a. Once you have installed and configured a particular X package, you may also need to set one or more parameters whenever you login and wish to use the package. Some of the packages will require you to set your "DISPLAY" environment variable. For example: who | grep mccullen mccullen pts/55 Jan 10 14:47 (pm561-30.dialip.mich.net) setenv DISPLAY pm561-30.dialip.mich.net:0.0 At that point, you should be able to run "sim" on the CSE server "north" and have the circuit displayed on your PC. Please note that this step is probably unnecessary if you are using "ssh" as described earlier in this document. b. Not all of the numeric keypad keys and the function keys seem to work as expected. In particular, the '5' key on the numeric keypad doesn't always redraw the simulated circuit. However, "right click" on the mouse serves the same purpose (in most cases). c. The default X window size is often too big for a PC monitor. You can resize the X window using the mouse, or you can re-execute the same program with a different window size. Since "sim" saves the current program in your directory as "simex", you can re-execute the same simulation multiple times. For example: sim proj01.next.c (translate and execute simulation) Ctrl-c (abort execution) simex -g 600x400 (re-execute simulation) You may need to experiment with the width and height parameters (values for the "-g" option) to get the appropriate size window for your monitor.