A module instance is analogous to an invocation of a function in a C
program. It is generally displayed as a box with input and output
wire attached to it. Each instance of a module operates independent
of the other instances. When realized as a circuit, each instance
would take up chip area, and be comprised of its own physical wires
and components. When simulating, TkGate maintains separate state for
the values of wires in each instance and the values of any registers
or memories.
When you create a module instance, that instance will have a unique
instance name, distinct from the name of the module type or function.
The instance name allows you to distinguish between different
instances of a module. For example, if you create two REGS modules,
one might have an instance name of "g1" and one might have an instance
name of "g2". Normally, TkGate automatically assigns the instance
name, but you can change it on the "General" tab of the Gate Properties Box dialog box.
Note that this dialog box displays and modifies properties of the
module instance, not the underlying module implementation.
TkGate's module hierarchy view displays the module hierarchy of your
design. Be sure you have selected to see the hierarchical view. When you are in
edit mode, the hierarchy is shown in terms of module implementations.
That is, at each node in the tree, the children are the names of the
modules which are used as instances at least once in the module.
Consider the example shown to the right. The top-level module "main"
is indicated by the symbol next to it.
In this example, "main" uses one or more module instances of the
"EUNIT", "IUNIT" and "MEMORY" modules. The "REG16" module uses one or
more instances of the "REG4" and "ZREG4" modules, but the symbol next to "REG4" tells us that there is no
definition for that module. The module "ZREG4" shown in red with an underline
indicates that that module is the current module in the editor. The
symbol next to "EUNIT" underneath "ZREG4"
indicates a conflict. ZREG4 includes an instance of "EUNIT", but
"ZREG4" itself is contained in an "EUNIT" (it is in "REG16" which is
in "EUNIT"). Circuits containing conflicts can not be simulated, all
conflicts must be resolved before you can simulate.
Each module in the module list or hierarchy view is preceded by a
symbol showing its type. The possible types are:
HDL and net-list modules may also contain a "lock" on them (for
example ). The lock indicates that
editing of that module has been disabled in the module options dialog
box.
There are also several property flags that you can set for your module:
3.2 Creating Module Instances
1) Select a module from the module list.
2) Drag to the insertion location.
3) Release mouse button to create.
Figure 3.1: Creating a Module Instance
3.3 Module Hierarchy
Your design in TkGate is comprised of a hierarchy of module instances.
There is one module that is designated the top-level module. By
default, this module is called "main", but you can rename it to any
module you wish. You can also designate any module in your design to
be the top-level module. Module instances that are directly included
in the top-level module form the next level in the hierarchy, and
modules instances included in those 2nd layer modules form the next
layer and so on.
3.3.1 Module Hierarchy View
Figure 3.3: Module
Hierarchy View
Symbol Description The top-level module. A normal net-list module. A text HDL module. Collection of module libraries. A module library A module defined in a library. Collection of modules defined but not used in the circuit. Reference to an undefined module in hierarchical list. Conflict/recursive definition in hierarchical list. 3.3.2 Navigating to Modules
Double click on a module in the module hierarchy or module list view
to open that module in the editor. You can also right click on a
module instance in the main editing window and select " Open". When you use " Open" to open modules, TkGate will remember
the modules you have opened on a stack. The modules on the stack will
be displayed in red, with an underline under the module currently
displayed in the editor. To close a module, and return to the parent
module on the stack, right click in a blank area on the canvas and
select " Close".
3.4 Creating and Manipulating Modules
3.4.1 Creating Modules
To create a new module, press the button on the toolbar. This will open the
dialog box shown in Figure 3.4. After you
have opened the dialog box, choose a name for your module and enter it
into the "Name" field. Next, choose a module type. A "netlist"
module is one that is defined graphically by connecting gates and
other modules, and "HDL" module is one that is defined by typing a
text description of the module. You can not change the type once the
module has been created. In order to change the type, you must delete
the module and create a new one of the new type.
3.4.2 Editing Module Properties
You can edit the property flags of a module by right clicking on the
module name in the module list and selecting " Properties...". This will bring up a dialog
box like the one shown in Figure 3.5. The
dialog box will show the name of the module, the name of the file from
which that module was loaded, and the type of the module (netlist or
HDL). These properties can not be modified. The modifiable
attributes of modules are the same as those previously described in
Section 3.4.1 Creating Modules.
3.4.3 Deleting, Copying and Renaming Modules
To delete a module implementation, right click on a module in the module list and
select " Delete". This will
bring up the dialog box shown in Figure 3.6.
Press "OK" to delete the module. You can also change the module to be
deleted by selecting its name from the drop down list. Any instances
of the deleted module used in your design, will not be deleted. If
you attempt to simulate, you will get an undefined module error.
To copy a module implementation, right click on the module to be copied from the module list and select " Copy". This will bring up a dialog box like the one shown in Figure 3.7. Make sure the "From" field shows the name of the module you wish to copy. Enter the name of the new module in the "To" field. This will copy both the module definition and the module interface. The new module will appear in the list, or under the "Unused" tree in the hierarchy view.
To rename a module implementation, right click on the module to be copied from the module list and select " Rename". This will bring up a dialog box like the one shown in Figure 3.8. Make sure the "From" field shows the name of the module you wish to copy. Enter the new name for the module in the "To" field.
Since modules that are defined in your design take precedence over library modules, the next time you load your design, the claimed module will continue to be used in lieu of the library version of that module. If you later decide that you would like to revert to the library version, you can delete the module, and reload the library.
To claim a module, right click on the module to be copied from the module list and select " Claim". This will bring up a dialog box like the one shown in Figure 3.9. Make sure the "Name" field shows the name of the module you wish to claim. The symbol next to the module will change to or to indicate that that module is now part of your design.
Only modules that are part of a library can be claimed. If you
attempt to open the claim dialog box when there are no library modules
in your circuit, you will get an error message.
To set the top-level module, right click on the module and select
" Set As Root". This will bring
up a dialog box like the one shown in Figure
3.10. Make sure the "Name" field shows the name of the correct
module. The module hierarchy view will be recomputed with the new
module as the top-level module.
3.5 Editing Module Definitions
To edit the definition of a netlist module, open the module as
described in section 3.3.2 Navigating to
Modules. Within the module you can use any of the gates you would
use at a higher level including more module instances. Signals as
passed between the inside and outside through special circuit elements
called ports. There are three types of ports: input, output and
inout. These are shown in Figure 3.11a, b and
c, respectively. Internal module ports are created the same way
as other gates. Right click at the position you wish to create it and
select "Module Input", "Module Output" and "Module InOut" from
"Module" under the "Make" menu. When you are creating a port, the net
properties dialog box will appear to allow you to set the name of the
port. Enter a name, and click OK to create it. The wire connected to
the port will have the same net name as the port.
The ports you define as part of the internal definition of a module
must match the ports that you define on the interface, both in the
names used, the type (input, output or inout), and the bit size. If
you have already created the interface, then you can click on the
"Ports" tab on the lower left-hand side of the main window to see what
ports have been created on the interface.
While it is possible to edit the interface of a module directly in
edit mode then choose "Interface → Set" to make that instance the
canonical instance, this is not the recommended way of creating
interfaces. The preferred way is to use the interface editor. To use
the interface editor, select the "Interface" tab in the main edit window.
If you have the top-level module selected, the interface editor will
display a graphical representation for the interfaces of all modules
loaded in your design as shown in Figure 3.12.
You can edit the interfaces directly on this page, or you can double
click on a module, either its graphical form or its name in the module
list, to open the single-module interface editor.
There are two basic types of module interfaces: standard interfaces,
and symbol interfaces. A standard interface is a rectangular box with
ports on the edges of the box. A symbol interface is an arbitrary
user-defined symbol created through a bitmap editor. Most of the
time, you will likely use standard interfaces, but if you wish to
create your own gates, you can create your own symbols for them.
3.6 Editing Module Interfaces
The interface of a module, is its external appearance when it is
included by a higher-level module. It includes the number and names
of the ports, as well as their position. Each module has a canonical
interface which is stored as part of the module definition when you
save your design. Individual instances of a module have an interface
as well which may or may not match the canonical interface. If you
make changes to the interface of a module after you have created one
or more instances of it in your circuit, you may need to go back and
fix those instances.
3.6.1 Standard Module Interfaces
Figure 3.13 shows the single-module
interface editor for a module with a standard interface. At the top
of the "Interface Properties" box, is a selector that lets you choose
between the "Standard" and "Symbol" interface types. While the module
is open, you can switch back and forth between the two types without
losing any work you have done on either interface. Below the
interface type selector, are the module properties. These are the
same properties that can be specified through the module creation and module properties dialog boxes.
To add a new port, you can either double click on the next empty line in the port list, or press the "Add" button. TkGate will attempt to guess an appropriate name for the new port, but you can type in your own name if you prefer. To delete a port, select it and press the "Delete" button.
You can reorder the ports by selecting and dragging them up or down in the port list. Ports that are on the same "Side" will be arranged in the same in both the port list and in the graphical representation of the interface.
To add a new port, right click on the edge of the rectangle at the point you wish to add the port and select "Add Input..", "Add Output.." or "Add InOut..". The Port Parameters dialog box will appear in this instance too allowing you to enter the port name and bit size. To delete a port, use the tool and "cut" the wire off the edge of the interface.
To reposition ports, grab them and slide them back and forth on the
edge to which they are attached. However, to change the edge to which
they are attached, you will need to change the "Side" in the port
list.
The port selection option tells the interface generator which ports should be included on the generated interface. The possible options are:
The port position option tells the interface generator how the ports on the new interface should be positioned. The possible options are:
You must create an "Unselected" and a "Selected" version of your symbol. The "Unselected" version is the appearance when the symbol is not selected, and the "Selected" version is the appearance when you have selected it in the editor. Normally you can just draw the "Unselected" version, copy and paste it into the "Unselected" version, then press the button on the toolbar to automatically boldify your symbol. However, you may want to use the editor to do some final touch-ups.
There are six symbol editor tools that you can use in designing your symbol:
Tool | Description |
---|---|
Bit Tool - Click the left mouse button to set a bit, and the right mouse button to clear a bit. You can also press and hold the mouse button to set/clear multiple bits and you move the mouse. | |
Line Tool - Click and hold the left mouse button to set one end of the line, and drag the mouse to the other end and release to draw a line. The same action with the right mouse button will clear a line. | |
Rectangle Tool - Click and hold the left mouse button to set one corner of the rectangle, and drag the mouse to the other corner and release to draw a rectangle. The same action with the right mouse button will clear the rectangle. | |
Filled Rectangle Tool - Click and hold the left mouse button to set one corner of the filled rectangle, and drag the mouse to the other corner and release to draw a filled rectangle. The same action with the right mouse button will clear the filled rectangle. | |
Port Tool - Use this tool to select and manipulate ports. Click and drag the port to move it. Use the and buttons to rotate the port clockwise or counter-clockwise. | |
Area Select Tool - This tool allows you to select a rectangular area, then use the cut, copy and paste tools. There are two types of paste operations. A normal paste overwrites all bits with the contents of the cut buffer. The overlay paste , pastes only the bits that are set in the cut buffer, combining the cut buffer with the existing image. The selection also limits the scope of the bit shifting and rotating operations to the selection. | |
You can also use the and
buttons to rotate the
image clockwise or counter-clockwise, or the shift buttons such as
to shift the bits left, right,
up or down. You can use the area selection tool to limit the scope of these operations to
the selected area.