Skip to main content

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

signalAsignal_asignal_csignal_bsignalBsignalCsignal_a12R11ksignal_b12R22ksignal_c

Module definition

A module is defined using the create module command. This requires the following properties:

NameDescription
widthWidth of the module graphical symbol
portsDescribe the ports that are part of the module symbol. The port names are the internal names within the module.
containsThe 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")

ValuePort typeDescription
"input"InputSignal input into port, default value.
"output"OutputSignal output of pin
"ioInput/OutputSignal input and output of pin
"any"AnyPort has no defined direction