Adding New Gates to Analog

Adding a new gate to analog involves several different tasks: the creation of a set of C functions that describe the behavior of the gate, the creation of a new gate icon, and the rebuilding of an analog executable that includes this gate.

The RESFLOAT gate is the simplest gate in analog that does a useful function: a two-terminal device that implements a linear resistor. An easy introduction to adding gates to analog is adding a new two-terminal gate to the library, using RESFLOAT as a template; in this example, we'll call the new gate FOOFLOAT. By copying and modifying the C source and gate icon for resfloat to create FOOFLOAT, and linking it into a new analog executable, you'll learn the mechanics of adding gates to analog.

Creating the Foofloat Icon

Use Loged to read the file log/lib/ana.gate. The ana.gate file holds all the icons used in analog simulation. Type the command gate resfloat to bring up the RESFLOAT gate. Then, type copy foofloat to create your new gate icon.

At the very least, you'll need to change the "definition" of FOOFLOAT; the definition is a text string used link the C function describing gate behavior with a gate icon. Simple type the command def and answer "y" to the question "Default[FOOFLOAT](y/n)?". This is the only change necessary; however, you may want to use the graphical editor to alter the icon, or use the label editor to alter the attribute screen (however, don't change the number of attributes for this example). See the Loged manual for details on these editors. Be sure to save ana.gate before exiting.

Creating the Foofloat C file

Go to the directory log/src/ana and copy the file resfloat.c to foofloat.c. Edit the file foofloat.c and change all capitalized variants of resfloat (i.e. resfloat, Resfloat, ResFloat, and RESFLOAT) to their foofloat equivalents. Depending on your editor, this may be easiest to do manually.

Also, edit the file log/lib/models.cnf, and clone all the Resfloat lines to make a set of Foofloat parameter calls.

Creating a new executable

Edit the file log/src/Makefile and add foofloat to the ANAOBJ list. Also edit the file log/src/ana/Makefile and add foofloat to the GATESOBJ list. Delete the files log/src/tooldir.c and log/src/simdir.c, then do a make clean install in the log/src directory.

If all goes well, a new analog executable should result. To test the new foofloat gate, type ":make foofloat" to create an instance of foofloat in analog; it should simulate identically to Resfloat.

Behavior of resfloat.c

The previous sections have described the mechanics of adding a new gate to analog, but haven't described the actual functions of the resfloat.c file. These two documents (1, 2)are different annotations of the resfloat.c file, highlighting different aspects of the C functions that describe the behavior of the resfloat gate. Examining these annotated files, as well as examining other gate descriptions in the log/src/ana directory, should help explain the details of gate simulation behavior.

  • To return to Table of Contents.
    Email
    john [dot] lazzaro [at] gmail [dot] com