How to create a simulation
Make a copy of the boilerplate simulation file, mysim.c (see
this figure). Also
make a copy of the Makefile which you will find there. Load
mysim.c into your favorite editor (presumably emacs) and
prepare to enter your simulation.
\begin{figure}
\begin{frepcode}{../src/mysim.c}\end{frepcode}
\caption{mysim.c --- Boilerplate Simulation File}
\end{figure}
You should leave the template file unchanged above and below the lines
Let's begin with the simple circuit pictured in this figure.
First, trace out each run of wire that is electrically connected.
Insert a declaration
Now that all the wires have been declared, they should be connected to the
circuit. Start by looking up function names for the simulations of each of
the circuit elements. If any of them are not in the predefined table, you
will have to break them down into existing elements, or define a new C
procedure to simulate them (see chapter "Building Submodules".)
Then, using the function for each element, create a connection, as follows:
Once you have successfully compiled the simulation (that is, once make runs
through and prints only the compilation commands, and no error messages or
``Stopped'' messages) you can run it. Typing
Simple circuit.
You may also get an error of the form
Complete user code for simulation
Building Submodules
Complex submodules should either be
New functions are straightforward to implement, and fast as well, if you are
familiar with the internal workings of the simulator. This is currently left
to the technical reference manual, but may be detailed here at a later time.
A simulator subunit can be created by making a copy of mysub.c. If
you are only making one subunit, this will suffice. Follow the same
procedure described in Chapter "How to create a
simulation" to construct the simulation,
using MAKEWIRE for the internal wiring. To create a template function
for the main body of the simulator to use, edit the template line at the top
of the file:
The input file format consists of lines which are either assignments or wait statements. An assignment consists of a wire name followed by a space and then a value, which is one of
A wait statement is a line containing the token wait either alone or
followed by a number of time units (nominally nanoseconds) before the next
state change. If the number is left out, it means to allow the simulator to
``settle'' before making the next state change. The simulator currently
ignores these statements, as it propagates any non-delayed changes
immediately.
These files can be read in by the C simulator, the Lisp Simulator, or
the Digital Oscilloscope. The Oscilloscope can also build these input
files.
The D Flip Flop is a bit more complex, and is simulated in the detail
described below.
Sample input waveform.
Sample input wave file
Output simulator waveform
Output of simulator run.
Appendix: Standard Circuit Element Library
The following table lists the standard circuit elements included with
the C Simulator. Other specific elements may be have been added for
specific projects; see your local documentation for more detail.
Table from page 5-22, TI databook, for 7474:
|------------------------------------------------|
| INPUTS | OUTPUTS |
|--------------------------------+---------------|
| preset | clear | clock | D | Q | Q' |
|--------+-------+-------+-------+-------+-------|
| L | H | X | X | H | L |
| H | L | X | X | L | H |
| L | L | X | X | H* | H* |
| H | H | ^ | H | H | L |
| H | H | ^ | L | L | H |
| H | H | L | X | Q0 | Q'0 |
|--------+-------+-------+-------+-------+-------|
| *unstable. |
|------------------------------------------------|