Modules and ports
A common method of organization circuits is to group circuits for a specific function within a module
. This module
can later be used in other larger circuits.
Example
Here is an example:
import lib
# Module is defined here
my_block = create module:
width: 1000
ports:
left: "signal_a", "signal_c"
right: [1], "signal_b"
contains:
# Module ports are defined within this circuit
at port("signal_a", "input") flip:x
wire right 100 down 100
add res(1k)
wire down 100
branch:
wire right 100
add port("signal_b", "output")
wire down 100
add res(2k)
wire down 100 right 100
to port("signal_c", "any")
# Connect signals in the external circuit
at label("signalA")
wire right 500 to my_block pin "signal_a"
at label("signalB", "right")
wire left 500 to my_block pin "signal_b"
at label("signalC")
wire right 500 to my_block pin "signal_c"
# Draw the circuit within the module
at my_block.contains
Module definition
A module is defined using the create module
command. This requires the following properties:
Name | Description |
---|---|
width | Width of the module graphical symbol |
ports | Describe the ports that are part of the module symbol. The port names are the internal names within the module. |
contains | The circuit graph within the module |
Module ports
The port types (input, output, etc.) of the module graphical symbol are automatically derived from the definition of the port within the contains
block.
In the example above, the port symbol for signal_a
in the module graphical symbol is displayed as an input port because within the contains
block, the port is defined as port("signal_a", "input")
Value | Port type | Description |
---|---|---|
"input" | Input | Signal input into port, default value. |
"output" | Output | Signal output of pin |
"io | Input/Output | Signal input and output of pin |
"any" | Any | Port has no defined direction |